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.

151 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2016 ROLI Ltd.
  5. Copyright (C) 2018 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. #include "StringPairArray.h"
  21. namespace water {
  22. StringPairArray::StringPairArray (const bool ignoreCase_)
  23. : ignoreCase (ignoreCase_)
  24. {
  25. }
  26. StringPairArray::StringPairArray (const StringPairArray& other)
  27. : keys (other.keys),
  28. values (other.values),
  29. ignoreCase (other.ignoreCase)
  30. {
  31. }
  32. StringPairArray::~StringPairArray()
  33. {
  34. }
  35. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  36. {
  37. keys = other.keys;
  38. values = other.values;
  39. return *this;
  40. }
  41. bool StringPairArray::operator== (const StringPairArray& other) const
  42. {
  43. for (int i = keys.size(); --i >= 0;)
  44. if (other [keys[i]] != values[i])
  45. return false;
  46. return true;
  47. }
  48. bool StringPairArray::operator!= (const StringPairArray& other) const
  49. {
  50. return ! operator== (other);
  51. }
  52. const String& StringPairArray::operator[] (StringRef key) const
  53. {
  54. return values [keys.indexOf (key, ignoreCase)];
  55. }
  56. String StringPairArray::getValue (StringRef key, const String& defaultReturnValue) const
  57. {
  58. const int i = keys.indexOf (key, ignoreCase);
  59. if (i >= 0)
  60. return values[i];
  61. return defaultReturnValue;
  62. }
  63. bool StringPairArray::containsKey (StringRef key) const noexcept
  64. {
  65. return keys.contains (key);
  66. }
  67. void StringPairArray::set (const String& key, const String& value)
  68. {
  69. const int i = keys.indexOf (key, ignoreCase);
  70. if (i >= 0)
  71. {
  72. values.set (i, value);
  73. }
  74. else
  75. {
  76. keys.add (key);
  77. values.add (value);
  78. }
  79. }
  80. void StringPairArray::addArray (const StringPairArray& other)
  81. {
  82. for (int i = 0; i < other.size(); ++i)
  83. set (other.keys[i], other.values[i]);
  84. }
  85. void StringPairArray::clear()
  86. {
  87. keys.clear();
  88. values.clear();
  89. }
  90. void StringPairArray::remove (StringRef key)
  91. {
  92. remove (keys.indexOf (key, ignoreCase));
  93. }
  94. void StringPairArray::remove (const int index)
  95. {
  96. keys.remove (index);
  97. values.remove (index);
  98. }
  99. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  100. {
  101. ignoreCase = shouldIgnoreCase;
  102. }
  103. String StringPairArray::getDescription() const
  104. {
  105. String s;
  106. for (int i = 0; i < keys.size(); ++i)
  107. {
  108. s << keys[i] << " = " << values[i];
  109. if (i < keys.size())
  110. s << ", ";
  111. }
  112. return s;
  113. }
  114. void StringPairArray::minimiseStorageOverheads()
  115. {
  116. keys.minimiseStorageOverheads();
  117. values.minimiseStorageOverheads();
  118. }
  119. }