JUCE  v5.1.1-3-g1a0b28c73
JUCE API
StringPairArray Class Reference

A container for holding a set of strings which are keyed by another string. More...

#include <juce_StringPairArray.h>

Collaboration diagram for StringPairArray:

Public Member Functions

 StringPairArray (bool ignoreCaseWhenComparingKeys=true)
 Creates an empty array. More...
 
 StringPairArray (const StringPairArray &other)
 Creates a copy of another array. More...
 
 ~StringPairArray ()
 Destructor. More...
 
void addArray (const StringPairArray &other)
 Adds the items from another array to this one. More...
 
void clear ()
 Removes all elements from the array. More...
 
bool containsKey (StringRef key) const noexcept
 Returns true if the given key exists. More...
 
const StringArraygetAllKeys () const noexcept
 Returns a list of all keys in the array. More...
 
const StringArraygetAllValues () const noexcept
 Returns a list of all values in the array. More...
 
String getDescription () const
 Returns a descriptive string containing the items. More...
 
String getValue (StringRef, const String &defaultReturnValue) const
 Finds the value corresponding to a key string. More...
 
void minimiseStorageOverheads ()
 Reduces the amount of storage being used by the array. More...
 
bool operator!= (const StringPairArray &other) const
 Compares two arrays. More...
 
StringPairArrayoperator= (const StringPairArray &other)
 Copies the contents of another string array into this one. More...
 
bool operator== (const StringPairArray &other) const
 Compares two arrays. More...
 
const Stringoperator[] (StringRef key) const
 Finds the value corresponding to a key string. More...
 
void remove (StringRef key)
 Removes a string from the array based on its key. More...
 
void remove (int index)
 Removes a string from the array based on its index. More...
 
void set (const String &key, const String &value)
 Adds or amends a key/value pair. More...
 
void setIgnoresCase (bool shouldIgnoreCase)
 Indicates whether to use a case-insensitive search when looking up a key string. More...
 
int size () const noexcept
 Returns the number of strings in the array. More...
 

Private Attributes

bool ignoreCase
 
StringArray keys
 
StringArray values
 

Detailed Description

A container for holding a set of strings which are keyed by another string.

See also
StringArray

Constructor & Destructor Documentation

◆ StringPairArray() [1/2]

StringPairArray::StringPairArray ( bool  ignoreCaseWhenComparingKeys = true)

Creates an empty array.

◆ StringPairArray() [2/2]

StringPairArray::StringPairArray ( const StringPairArray other)

Creates a copy of another array.

◆ ~StringPairArray()

StringPairArray::~StringPairArray ( )

Destructor.

Member Function Documentation

◆ addArray()

void StringPairArray::addArray ( const StringPairArray other)

Adds the items from another array to this one.

This is equivalent to using set() to add each of the pairs from the other array.

◆ clear()

void StringPairArray::clear ( )

Removes all elements from the array.

◆ containsKey()

bool StringPairArray::containsKey ( StringRef  key) const
noexcept

Returns true if the given key exists.

◆ getAllKeys()

const StringArray& StringPairArray::getAllKeys ( ) const
inlinenoexcept

Returns a list of all keys in the array.

◆ getAllValues()

const StringArray& StringPairArray::getAllValues ( ) const
inlinenoexcept

Returns a list of all values in the array.

◆ getDescription()

String StringPairArray::getDescription ( ) const

Returns a descriptive string containing the items.

This is handy for dumping the contents of an array.

◆ getValue()

String StringPairArray::getValue ( StringRef  ,
const String defaultReturnValue 
) const

Finds the value corresponding to a key string.

If no such key is found, this will just return the value provided as a default.

See also
operator[]

◆ minimiseStorageOverheads()

void StringPairArray::minimiseStorageOverheads ( )

Reduces the amount of storage being used by the array.

Arrays typically allocate slightly more storage than they need, and after removing elements, they may have quite a lot of unused space allocated. This method will reduce the amount of allocated storage to a minimum.

◆ operator!=()

bool StringPairArray::operator!= ( const StringPairArray other) const

Compares two arrays.

Comparisons are case-sensitive.

Returns
false if the other array contains exactly the same strings with the same keys

◆ operator=()

StringPairArray& StringPairArray::operator= ( const StringPairArray other)

Copies the contents of another string array into this one.

◆ operator==()

bool StringPairArray::operator== ( const StringPairArray other) const

Compares two arrays.

Comparisons are case-sensitive.

Returns
true only if the other array contains exactly the same strings with the same keys

◆ operator[]()

const String& StringPairArray::operator[] ( StringRef  key) const

Finds the value corresponding to a key string.

If no such key is found, this will just return an empty string. To check whether a given key actually exists (because it might actually be paired with an empty string), use the getAllKeys() method to obtain a list.

Obviously the reference returned shouldn't be stored for later use, as the string it refers to may disappear when the array changes.

See also
getValue

◆ remove() [1/2]

void StringPairArray::remove ( StringRef  key)

Removes a string from the array based on its key.

If the key isn't found, nothing will happen.

◆ remove() [2/2]

void StringPairArray::remove ( int  index)

Removes a string from the array based on its index.

If the index is out-of-range, no action will be taken.

◆ set()

void StringPairArray::set ( const String key,
const String value 
)

Adds or amends a key/value pair.

If a value already exists with this key, its value will be overwritten, otherwise the key/value pair will be added to the array.

◆ setIgnoresCase()

void StringPairArray::setIgnoresCase ( bool  shouldIgnoreCase)

Indicates whether to use a case-insensitive search when looking up a key string.

◆ size()

int StringPairArray::size ( ) const
inlinenoexcept

Returns the number of strings in the array.

Member Data Documentation

◆ ignoreCase

bool StringPairArray::ignoreCase
private

◆ keys

StringArray StringPairArray::keys
private

◆ values

StringArray StringPairArray::values
private

The documentation for this class was generated from the following file: