Public Member Functions

StringPairArray Class Reference

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

List of all members.

Public Member Functions

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

Detailed Description

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

See also:
StringArray

Constructor & Destructor Documentation

StringPairArray::StringPairArray ( bool  ignoreCaseWhenComparingKeys = true )

Creates an empty array.

StringPairArray::StringPairArray ( const StringPairArray other )

Creates a copy of another array.

StringPairArray::~StringPairArray (  )

Destructor.


Member Function Documentation

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

Copies the contents of another string array into this one.

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
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
const String& StringPairArray::operator[] ( const String 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
String StringPairArray::getValue ( const String key,
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[]
const StringArray& StringPairArray::getAllKeys (  ) const

Returns a list of all keys in the array.

const StringArray& StringPairArray::getAllValues (  ) const

Returns a list of all values in the array.

int StringPairArray::size (  ) const

Returns the number of strings in the array.

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.

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.

void StringPairArray::clear (  )

Removes all elements from the array.

void StringPairArray::remove ( const String key )

Removes a string from the array based on its key.

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

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.

void StringPairArray::setIgnoresCase ( bool  shouldIgnoreCase )

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

String StringPairArray::getDescription (  ) const

Returns a descriptive string containing the items.

This is handy for dumping the contents of an array.

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.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines