The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef __JUCE_IDENTIFIER_JUCEHEADER__
  22. #define __JUCE_IDENTIFIER_JUCEHEADER__
  23. class StringPool;
  24. //==============================================================================
  25. /**
  26. Represents a string identifier, designed for accessing properties by name.
  27. Identifier objects are very light and fast to copy, but slower to initialise
  28. from a string, so it's much faster to keep a static identifier object to refer
  29. to frequently-used names, rather than constructing them each time you need it.
  30. @see NamedPropertySet, ValueTree
  31. */
  32. class JUCE_API Identifier
  33. {
  34. public:
  35. /** Creates a null identifier. */
  36. Identifier() noexcept;
  37. /** Creates an identifier with a specified name.
  38. Because this name may need to be used in contexts such as script variables or XML
  39. tags, it must only contain ascii letters and digits, or the underscore character.
  40. */
  41. Identifier (const char* name);
  42. /** Creates an identifier with a specified name.
  43. Because this name may need to be used in contexts such as script variables or XML
  44. tags, it must only contain ascii letters and digits, or the underscore character.
  45. */
  46. Identifier (const String& name);
  47. /** Creates a copy of another identifier. */
  48. Identifier (const Identifier& other) noexcept;
  49. /** Creates a copy of another identifier. */
  50. Identifier& operator= (const Identifier other) noexcept;
  51. /** Destructor */
  52. ~Identifier();
  53. /** Compares two identifiers. This is a very fast operation. */
  54. inline bool operator== (const Identifier other) const noexcept { return name == other.name; }
  55. /** Compares two identifiers. This is a very fast operation. */
  56. inline bool operator!= (const Identifier other) const noexcept { return name != other.name; }
  57. /** Returns this identifier as a string. */
  58. String toString() const { return name; }
  59. /** Returns this identifier's raw string pointer. */
  60. operator const String::CharPointerType() const noexcept { return name; }
  61. /** Returns this identifier's raw string pointer. */
  62. const String::CharPointerType getCharPointer() const noexcept { return name; }
  63. /** Returns true if this Identifier is not null */
  64. bool isValid() const noexcept { return name.getAddress() != nullptr; }
  65. /** Returns true if this Identifier is null */
  66. bool isNull() const noexcept { return name.getAddress() == nullptr; }
  67. /** A null identifier. */
  68. static Identifier null;
  69. /** Checks a given string for characters that might not be valid in an Identifier.
  70. Since Identifiers are used as a script variables and XML attributes, they should only contain
  71. alphanumeric characters, underscores, or the '-' and ':' characters.
  72. */
  73. static bool isValidIdentifier (const String& possibleIdentifier) noexcept;
  74. private:
  75. //==============================================================================
  76. String::CharPointerType name;
  77. static StringPool& getPool();
  78. };
  79. #endif // __JUCE_IDENTIFIER_JUCEHEADER__