Audio plugin host https://kx.studio/carla
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.

119 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2016 ROLI Ltd.
  5. Copyright (C) 2017-2022 Filipe Coelho <falktx@falktx.com>
  6. Permission is granted to use this software under the terms of the ISC license
  7. http://www.isc.org/downloads/software-support-policy/isc-license/
  8. Permission to use, copy, modify, and/or distribute this software for any
  9. purpose with or without fee is hereby granted, provided that the above
  10. copyright notice and this permission notice appear in all copies.
  11. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  12. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  13. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  14. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  15. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  17. OF THIS SOFTWARE.
  18. ==============================================================================
  19. */
  20. #ifndef WATER_IDENTIFIER_H_INCLUDED
  21. #define WATER_IDENTIFIER_H_INCLUDED
  22. #include "String.h"
  23. namespace water {
  24. //==============================================================================
  25. /**
  26. Represents a string identifier, designed for accessing properties by name.
  27. Comparing two Identifier objects is very fast (an O(1) operation), but creating
  28. them can be slower than just using a String directly, so the optimal way to use them
  29. is to keep some static Identifier objects for the things you use often.
  30. @see NamedValueSet, ValueTree
  31. */
  32. class 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 std::string& name);
  47. /** Creates an identifier with a specified name.
  48. Because this name may need to be used in contexts such as script variables or XML
  49. tags, it must only contain ascii letters and digits, or the underscore character.
  50. */
  51. Identifier (const char* nameStart, const char* nameEnd);
  52. /** Creates a copy of another identifier. */
  53. Identifier (const Identifier& other) noexcept;
  54. /** Creates a copy of another identifier. */
  55. Identifier& operator= (const Identifier& other) noexcept;
  56. /** Destructor */
  57. ~Identifier() noexcept;
  58. /** Compares two identifiers. This is a very fast operation. */
  59. inline bool operator== (const Identifier& other) const noexcept { return name == other.name; }
  60. /** Compares two identifiers. This is a very fast operation. */
  61. inline bool operator!= (const Identifier& other) const noexcept { return name != other.name; }
  62. /** Compares the identifier with a string. */
  63. inline bool operator== (const char* other) const noexcept { return name == other; }
  64. /** Compares the identifier with a string. */
  65. inline bool operator!= (const char* other) const noexcept { return name != other; }
  66. /** Compares the identifier with a string. */
  67. inline bool operator< (const char* other) const noexcept { return name < other; }
  68. /** Compares the identifier with a string. */
  69. inline bool operator<= (const char* other) const noexcept { return name <= other; }
  70. /** Compares the identifier with a string. */
  71. inline bool operator> (const char* other) const noexcept { return name > other; }
  72. /** Compares the identifier with a string. */
  73. inline bool operator>= (const char* other) const noexcept { return name >= other; }
  74. /** Returns this identifier as a string. */
  75. const std::string& toString() const noexcept { return name; }
  76. /** Returns this identifier as a StringRef. */
  77. operator StringRef() const noexcept { return StringRef(name.c_str()); }
  78. /** Returns true if this Identifier is not null */
  79. bool isValid() const noexcept { return !name.empty(); }
  80. /** Returns true if this Identifier is null */
  81. bool isNull() const noexcept { return name.empty(); }
  82. private:
  83. std::string name;
  84. };
  85. }
  86. #endif // WATER_IDENTIFIER_H_INCLUDED