Fix crash when host does not support midi-in; Add missing file
[juce-lv2.git] / juce / source / src / text / juce_StringPairArray.cpp
blobd547e81f50f0b75c3a0fec492a322aa8d0117b17
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../core/juce_StandardHeader.h"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_StringPairArray.h"
33 //==============================================================================
34 StringPairArray::StringPairArray (const bool ignoreCase_)
35 : ignoreCase (ignoreCase_)
39 StringPairArray::StringPairArray (const StringPairArray& other)
40 : keys (other.keys),
41 values (other.values),
42 ignoreCase (other.ignoreCase)
46 StringPairArray::~StringPairArray()
50 StringPairArray& StringPairArray::operator= (const StringPairArray& other)
52 keys = other.keys;
53 values = other.values;
54 return *this;
57 bool StringPairArray::operator== (const StringPairArray& other) const
59 for (int i = keys.size(); --i >= 0;)
60 if (other [keys[i]] != values[i])
61 return false;
63 return true;
66 bool StringPairArray::operator!= (const StringPairArray& other) const
68 return ! operator== (other);
71 const String& StringPairArray::operator[] (const String& key) const
73 return values [keys.indexOf (key, ignoreCase)];
76 String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
78 const int i = keys.indexOf (key, ignoreCase);
80 if (i >= 0)
81 return values[i];
83 return defaultReturnValue;
86 void StringPairArray::set (const String& key, const String& value)
88 const int i = keys.indexOf (key, ignoreCase);
90 if (i >= 0)
92 values.set (i, value);
94 else
96 keys.add (key);
97 values.add (value);
101 void StringPairArray::addArray (const StringPairArray& other)
103 for (int i = 0; i < other.size(); ++i)
104 set (other.keys[i], other.values[i]);
107 void StringPairArray::clear()
109 keys.clear();
110 values.clear();
113 void StringPairArray::remove (const String& key)
115 remove (keys.indexOf (key, ignoreCase));
118 void StringPairArray::remove (const int index)
120 keys.remove (index);
121 values.remove (index);
124 void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
126 ignoreCase = shouldIgnoreCase;
129 String StringPairArray::getDescription() const
131 String s;
133 for (int i = 0; i < keys.size(); ++i)
135 s << keys[i] << " = " << values[i];
136 if (i < keys.size())
137 s << ", ";
140 return s;
143 void StringPairArray::minimiseStorageOverheads()
145 keys.minimiseStorageOverheads();
146 values.minimiseStorageOverheads();
149 END_JUCE_NAMESPACE