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.

161 lines
6.0KB

  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_STRINGPAIRARRAY_JUCEHEADER__
  19. #define __JUCE_STRINGPAIRARRAY_JUCEHEADER__
  20. #include "juce_StringArray.h"
  21. //==============================================================================
  22. /**
  23. A container for holding a set of strings which are keyed by another string.
  24. @see StringArray
  25. */
  26. class JUCE_API StringPairArray
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates an empty array */
  31. StringPairArray (bool ignoreCaseWhenComparingKeys = true);
  32. /** Creates a copy of another array */
  33. StringPairArray (const StringPairArray& other);
  34. /** Destructor. */
  35. ~StringPairArray();
  36. /** Copies the contents of another string array into this one */
  37. StringPairArray& operator= (const StringPairArray& other);
  38. //==============================================================================
  39. /** Compares two arrays.
  40. Comparisons are case-sensitive.
  41. @returns true only if the other array contains exactly the same strings with the same keys
  42. */
  43. bool operator== (const StringPairArray& other) const;
  44. /** Compares two arrays.
  45. Comparisons are case-sensitive.
  46. @returns false if the other array contains exactly the same strings with the same keys
  47. */
  48. bool operator!= (const StringPairArray& other) const;
  49. //==============================================================================
  50. /** Finds the value corresponding to a key string.
  51. If no such key is found, this will just return an empty string. To check whether
  52. a given key actually exists (because it might actually be paired with an empty string), use
  53. the getAllKeys() method to obtain a list.
  54. Obviously the reference returned shouldn't be stored for later use, as the
  55. string it refers to may disappear when the array changes.
  56. @see getValue
  57. */
  58. const String& operator[] (const String& key) const;
  59. /** Finds the value corresponding to a key string.
  60. If no such key is found, this will just return the value provided as a default.
  61. @see operator[]
  62. */
  63. String getValue (const String& key, const String& defaultReturnValue) const;
  64. /** Returns a list of all keys in the array. */
  65. const StringArray& getAllKeys() const noexcept { return keys; }
  66. /** Returns a list of all values in the array. */
  67. const StringArray& getAllValues() const noexcept { return values; }
  68. /** Returns the number of strings in the array */
  69. inline int size() const noexcept { return keys.size(); };
  70. //==============================================================================
  71. /** Adds or amends a key/value pair.
  72. If a value already exists with this key, its value will be overwritten,
  73. otherwise the key/value pair will be added to the array.
  74. */
  75. void set (const String& key, const String& value);
  76. /** Adds the items from another array to this one.
  77. This is equivalent to using set() to add each of the pairs from the other array.
  78. */
  79. void addArray (const StringPairArray& other);
  80. //==============================================================================
  81. /** Removes all elements from the array. */
  82. void clear();
  83. /** Removes a string from the array based on its key.
  84. If the key isn't found, nothing will happen.
  85. */
  86. void remove (const String& key);
  87. /** Removes a string from the array based on its index.
  88. If the index is out-of-range, no action will be taken.
  89. */
  90. void remove (int index);
  91. //==============================================================================
  92. /** Indicates whether to use a case-insensitive search when looking up a key string.
  93. */
  94. void setIgnoresCase (bool shouldIgnoreCase);
  95. //==============================================================================
  96. /** Returns a descriptive string containing the items.
  97. This is handy for dumping the contents of an array.
  98. */
  99. String getDescription() const;
  100. //==============================================================================
  101. /** Reduces the amount of storage being used by the array.
  102. Arrays typically allocate slightly more storage than they need, and after
  103. removing elements, they may have quite a lot of unused space allocated.
  104. This method will reduce the amount of allocated storage to a minimum.
  105. */
  106. void minimiseStorageOverheads();
  107. private:
  108. //==============================================================================
  109. StringArray keys, values;
  110. bool ignoreCase;
  111. JUCE_LEAK_DETECTOR (StringPairArray);
  112. };
  113. #endif // __JUCE_STRINGPAIRARRAY_JUCEHEADER__