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.

100 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_IDENTIFIER_JUCEHEADER__
  19. #define __JUCE_IDENTIFIER_JUCEHEADER__
  20. class StringPool;
  21. //==============================================================================
  22. /**
  23. Represents a string identifier, designed for accessing properties by name.
  24. Identifier objects are very light and fast to copy, but slower to initialise
  25. from a string, so it's much faster to keep a static identifier object to refer
  26. to frequently-used names, rather than constructing them each time you need it.
  27. @see NamedPropertySet, ValueTree
  28. */
  29. class JUCE_API Identifier
  30. {
  31. public:
  32. /** Creates a null identifier. */
  33. Identifier() noexcept;
  34. /** Creates an identifier with a specified name.
  35. Because this name may need to be used in contexts such as script variables or XML
  36. tags, it must only contain ascii letters and digits, or the underscore character.
  37. */
  38. Identifier (const char* name);
  39. /** Creates an identifier with a specified name.
  40. Because this name may need to be used in contexts such as script variables or XML
  41. tags, it must only contain ascii letters and digits, or the underscore character.
  42. */
  43. Identifier (const String& name);
  44. /** Creates a copy of another identifier. */
  45. Identifier (const Identifier& other) noexcept;
  46. /** Creates a copy of another identifier. */
  47. Identifier& operator= (const Identifier& other) noexcept;
  48. /** Destructor */
  49. ~Identifier();
  50. /** Compares two identifiers. This is a very fast operation. */
  51. inline bool operator== (const Identifier& other) const noexcept { return name == other.name; }
  52. /** Compares two identifiers. This is a very fast operation. */
  53. inline bool operator!= (const Identifier& other) const noexcept { return name != other.name; }
  54. /** Returns this identifier as a string. */
  55. String toString() const { return name; }
  56. /** Returns this identifier's raw string pointer. */
  57. operator const String::CharPointerType() const noexcept { return name; }
  58. /** Returns this identifier's raw string pointer. */
  59. const String::CharPointerType getCharPointer() const noexcept { return name; }
  60. /** Checks a given string for characters that might not be valid in an Identifier.
  61. Since Identifiers are used as a script variables and XML attributes, they should only contain
  62. alphanumeric characters, underscores, or the '-' and ':' characters.
  63. */
  64. static bool isValidIdentifier (const String& possibleIdentifier) noexcept;
  65. private:
  66. //==============================================================================
  67. String::CharPointerType name;
  68. static StringPool& getPool();
  69. };
  70. #endif // __JUCE_IDENTIFIER_JUCEHEADER__