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.

160 lines
6.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_STRINGPAIRARRAY_H_INCLUDED
  24. #define JUCE_STRINGPAIRARRAY_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. A container for holding a set of strings which are keyed by another string.
  28. @see StringArray
  29. */
  30. class JUCE_API StringPairArray
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates an empty array */
  35. StringPairArray (bool ignoreCaseWhenComparingKeys = true);
  36. /** Creates a copy of another array */
  37. StringPairArray (const StringPairArray& other);
  38. /** Destructor. */
  39. ~StringPairArray();
  40. /** Copies the contents of another string array into this one */
  41. StringPairArray& operator= (const StringPairArray& other);
  42. //==============================================================================
  43. /** Compares two arrays.
  44. Comparisons are case-sensitive.
  45. @returns true only if the other array contains exactly the same strings with the same keys
  46. */
  47. bool operator== (const StringPairArray& other) const;
  48. /** Compares two arrays.
  49. Comparisons are case-sensitive.
  50. @returns false if the other array contains exactly the same strings with the same keys
  51. */
  52. bool operator!= (const StringPairArray& other) const;
  53. //==============================================================================
  54. /** Finds the value corresponding to a key string.
  55. If no such key is found, this will just return an empty string. To check whether
  56. a given key actually exists (because it might actually be paired with an empty string), use
  57. the getAllKeys() method to obtain a list.
  58. Obviously the reference returned shouldn't be stored for later use, as the
  59. string it refers to may disappear when the array changes.
  60. @see getValue
  61. */
  62. const String& operator[] (StringRef key) const;
  63. /** Finds the value corresponding to a key string.
  64. If no such key is found, this will just return the value provided as a default.
  65. @see operator[]
  66. */
  67. String getValue (StringRef, const String& defaultReturnValue) const;
  68. /** Returns true if the given key exists. */
  69. bool containsKey (StringRef key) const noexcept;
  70. /** Returns a list of all keys in the array. */
  71. const StringArray& getAllKeys() const noexcept { return keys; }
  72. /** Returns a list of all values in the array. */
  73. const StringArray& getAllValues() const noexcept { return values; }
  74. /** Returns the number of strings in the array */
  75. inline int size() const noexcept { return keys.size(); };
  76. //==============================================================================
  77. /** Adds or amends a key/value pair.
  78. If a value already exists with this key, its value will be overwritten,
  79. otherwise the key/value pair will be added to the array.
  80. */
  81. void set (const String& key, const String& value);
  82. /** Adds the items from another array to this one.
  83. This is equivalent to using set() to add each of the pairs from the other array.
  84. */
  85. void addArray (const StringPairArray& other);
  86. //==============================================================================
  87. /** Removes all elements from the array. */
  88. void clear();
  89. /** Removes a string from the array based on its key.
  90. If the key isn't found, nothing will happen.
  91. */
  92. void remove (StringRef key);
  93. /** Removes a string from the array based on its index.
  94. If the index is out-of-range, no action will be taken.
  95. */
  96. void remove (int index);
  97. //==============================================================================
  98. /** Indicates whether to use a case-insensitive search when looking up a key string.
  99. */
  100. void setIgnoresCase (bool shouldIgnoreCase);
  101. //==============================================================================
  102. /** Returns a descriptive string containing the items.
  103. This is handy for dumping the contents of an array.
  104. */
  105. String getDescription() const;
  106. //==============================================================================
  107. /** Reduces the amount of storage being used by the array.
  108. Arrays typically allocate slightly more storage than they need, and after
  109. removing elements, they may have quite a lot of unused space allocated.
  110. This method will reduce the amount of allocated storage to a minimum.
  111. */
  112. void minimiseStorageOverheads();
  113. private:
  114. //==============================================================================
  115. StringArray keys, values;
  116. bool ignoreCase;
  117. JUCE_LEAK_DETECTOR (StringPairArray)
  118. };
  119. #endif // JUCE_STRINGPAIRARRAY_H_INCLUDED