OpenShot Library | OpenShotAudio 0.2.2
juce_StringPairArray.h
1
2/** @weakgroup juce_core-text
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/**
32 A container for holding a set of strings which are keyed by another string.
33
34 @see StringArray
35
36 @tags{Core}
37*/
39{
40public:
41 //==============================================================================
42 /** Creates an empty array */
43 StringPairArray (bool ignoreCaseWhenComparingKeys = true);
44
45 /** Creates a copy of another array */
46 StringPairArray (const StringPairArray& other);
47
48 /** Destructor. */
50
51 /** Copies the contents of another string array into this one */
52 StringPairArray& operator= (const StringPairArray& other);
53
54 //==============================================================================
55 /** Compares two arrays.
56 Comparisons are case-sensitive.
57 @returns true only if the other array contains exactly the same strings with the same keys
58 */
59 bool operator== (const StringPairArray& other) const;
60
61 /** Compares two arrays.
62 Comparisons are case-sensitive.
63 @returns false if the other array contains exactly the same strings with the same keys
64 */
65 bool operator!= (const StringPairArray& other) const;
66
67 //==============================================================================
68 /** Finds the value corresponding to a key string.
69
70 If no such key is found, this will just return an empty string. To check whether
71 a given key actually exists (because it might actually be paired with an empty string), use
72 the getAllKeys() method to obtain a list.
73
74 Obviously the reference returned shouldn't be stored for later use, as the
75 string it refers to may disappear when the array changes.
76
77 @see getValue
78 */
79 const String& operator[] (StringRef key) const;
80
81 /** Finds the value corresponding to a key string.
82 If no such key is found, this will just return the value provided as a default.
83 @see operator[]
84 */
85 String getValue (StringRef, const String& defaultReturnValue) const;
86
87 /** Returns true if the given key exists. */
88 bool containsKey (StringRef key) const noexcept;
89
90 /** Returns a list of all keys in the array. */
91 const StringArray& getAllKeys() const noexcept { return keys; }
92
93 /** Returns a list of all values in the array. */
94 const StringArray& getAllValues() const noexcept { return values; }
95
96 /** Returns the number of strings in the array */
97 inline int size() const noexcept { return keys.size(); }
98
99
100 //==============================================================================
101 /** Adds or amends a key/value pair.
102 If a value already exists with this key, its value will be overwritten,
103 otherwise the key/value pair will be added to the array.
104 */
105 void set (const String& key, const String& value);
106
107 /** Adds the items from another array to this one.
108 This is equivalent to using set() to add each of the pairs from the other array.
109 */
110 void addArray (const StringPairArray& other);
111
112 //==============================================================================
113 /** Removes all elements from the array. */
114 void clear();
115
116 /** Removes a string from the array based on its key.
117 If the key isn't found, nothing will happen.
118 */
119 void remove (StringRef key);
120
121 /** Removes a string from the array based on its index.
122 If the index is out-of-range, no action will be taken.
123 */
124 void remove (int index);
125
126 //==============================================================================
127 /** Indicates whether to use a case-insensitive search when looking up a key string.
128 */
129 void setIgnoresCase (bool shouldIgnoreCase);
130
131 //==============================================================================
132 /** Returns a descriptive string containing the items.
133 This is handy for dumping the contents of an array.
134 */
135 String getDescription() const;
136
137 //==============================================================================
138 /** Reduces the amount of storage being used by the array.
139
140 Arrays typically allocate slightly more storage than they need, and after
141 removing elements, they may have quite a lot of unused space allocated.
142 This method will reduce the amount of allocated storage to a minimum.
143 */
144 void minimiseStorageOverheads();
145
146
147private:
148 //==============================================================================
149 StringArray keys, values;
150 bool ignoreCase;
151
152 JUCE_LEAK_DETECTOR (StringPairArray)
153};
154
155} // namespace juce
156
157/** @}*/
A special array for holding a list of strings.
A container for holding a set of strings which are keyed by another string.
const StringArray & getAllValues() const noexcept
Returns a list of all values in the array.
int size() const noexcept
Returns the number of strings in the array.
const StringArray & getAllKeys() const noexcept
Returns a list of all keys in the array.
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition: juce_String.h:43
#define JUCE_API
This macro is added to all JUCE public class declarations.