Class HashArray
#include <HashArray.h >
This class manages key/value pairs, implementing an associated array.
The data structure can be serialized using toString() and loaded from text using fromString().
The HashArray data type is a key-value container.
It is typeless, but a specific type can be asserted (e.g. setBool()) or retrieved (e.g. getBool(), getInt(), etc). It is up the the application to store/retrieve by type consistently.
This data type is very convenient for messaging. Calling the toString() method converts the HashArray into a string. Using the fromString() method or constructor converts it back.
Return the number of key-value pairs.
Return value: # keys in hash array
Determine if there are no key-value pairs in the hash array.
Return value: True if there are no key-value pairs, false if there's at least one
const string& text |
some text to chck if in valid format |
Determine if a string is a serialized HashArray structure or not.
Return value: True if it's a serialized HashArray
Constructor for an empty HashArray
const HashArray& array |
the HashArray to copy |
Copy constructor for a HashArray
const string& text |
serialized string created by HashArray::toString() |
char separator |
the key-value separator string Default value: '\n' |
Constructor for a HashArray from a string (serialized HashArray value).
const string& text |
serialized string created by HashArray::toString() |
const string& separator |
the key-value separator string |
Constructor for a HashArray from a string (serialized HashArray value).
const string& key |
the key to use to find the value |
Get a hash array value from its key
Return value: the value for the key
int key |
the key to use to find the value (it is converted to a string) |
Get a hash array value from its key
Return value: the value for the key
const string& key |
the key to use for the value |
const string& value |
the value to assign to the key |
Set a hash array value for a key, overwriting any previous value
const string& key |
the key to use for the value |
long value |
the value to assign to the key (it is converted to a string) |
Set a string value for a key, overwriting any previous value
const string& key |
the key to use for the value |
int value |
the value to assign to the key (it is converted to a string) |
Set a long value for a key, overwriting any previous value
const string& key |
the key to use for the value |
unsigned long value |
the value to assign to the key (it is converted to a string) |
Set a unsingned long value for a key, overwriting any previous value
const string& key |
the key to use for the value |
unsigned int value |
the value to assign to the key (it is converted to a string) |
Set a unsigned int value for a key, overwriting any previous value
const string& key |
the key to use for the value |
bool value |
the value to assign to the key (it is converted to a T or F) |
Set a boolean value for a key, overwriting any previous value
const string& key |
the key to use for the value |
float value |
the value to assign to the key (it is converted to a string) |
Set a float value for a key, overwriting any previous value
const string& key |
the key to use for the value |
double value |
the value to assign to the key (it is converted to a string) |
Set a double value for a key, overwriting any previous value
int key |
the key to use for the value (it is converted to a string) |
const string& value |
the value to assign to the key |
Set a string value for an intgeger key, overwriting any previous value
int key |
the key to use for the value (it is converted to a string) |
long value |
the value to assign to the key (it is converted to a string) |
Set a long value for an intgeger key, overwriting any previous value
int key |
the key to use for the value (it is converted to a string) |
bool value |
the value to assign to the key (it is converted to a string) |
Set a boolean value for an integer key, overwriting any previous value
int key |
the key to use for the value (it is converted to a string) |
float value |
the value to assign to the key (it is converted to a string) |
Set a float value for an integer key, overwriting any previous value
const string& key |
the key to use for the value |
Clear/Unset a hash array value for a key
int key |
the key to use for the value (it is converted to a string) |
Clear/Unset a hash array value for a key
const string& value |
the value to append |
Add a new string value into the HashArray, using a key as its index (the new 5th pair will have a key value of 5).
Regardless of its key, return the last value in the HashArray
Return value: value of last key-value pair in this HashArray
Remove all key-value pairs, creating an empty HashArray.
const string& key |
the key for the value lookup |
Given a string key, return the matching value as string.
If the key does not exit, the default is null string.
Return value: the value (as string), null string if key not found
const string& key |
the key for the value lookup |
Given a string key, return the matching value as integer.
If the key does not exit, the default is 0.
Return value: the value (as long), 0 if key not found
const string& key |
the key for the value lookup |
Given a string key, return the matching value as float.
If the key does not exit, the default is 0.
Return value: the value (as float)
const string& key |
the key for the value lookup |
Given a string key, return the matching value as double.
If the key does not exit, the default is 0.
Return value: the value (as double)
const string& key |
the key for the value lookup |
Given a string key, return the matching value as boolean.
Note that T, Y, and 1 as the first character make the value true.
If the key does not exit, the default is False.
Return value: the value (as bool)
const string& key |
the key for the value lookup |
Given a string key, return the matching value as a HashArray.
Presumably the value is a serialized HashArray.
If the key does not exit, the default is en empty HashArray.
Return value: the value (as HashArray)
const string& key |
the key for the value lookup |
Given a string key, return the matching value as a HashArray.
Presumably the value is a serialized HashArray.
If the key does not exit, the default is en empty HashArray.
Return value: the value (as HashArray)
int key |
the key for the value lookup (it is converted to a string) |
Given an integer key, return the matching value as string.
If the key does not exit, the default is null string.
Return value: the value (as string)
int key |
the key for the value lookup (it is converted to a string) |
Given an integer key, return the matching value as integer.
If the key does not exit, the default is 0.
Return value: the value (as long)
int key |
the key for the value lookup (it is converted to a string) |
Given an integer key, return the matching value as boolean.
Note that T, Y, and 1 as the first character make the value true.
If the key does not exit, the default is false.
Return value: the value (as bool)
int index |
the index/offset into the HashArray |
Given an index/offset into the HashArray, return the value there.
If the index it out of range, the default is null string.
Return value: the value (as string)
const HashArray& other |
the other HashArray for comparison |
Compare to HashArrays for equality. Both must have the same number of keys with appropriately matching values.
Note that the HashArrays do not need to have their keys at the same index.
@retuen True if the two arrays are identifical
const HashArray& other |
the other HashArray for comparison |
Compare to HashArrays for equality. Both must have the same number of keys with appropriately matching values.
Note that the HashArrays do not need to have their keys at the same index.
@retuen True if the two arrays are identifical
const HashArray& other |
the HashArray subset candidate |
Check if a provided HashArray is a subset of this HashArray.
Return value: True if other is a subset of this HashArray
const string& key |
the key to find |
Return the index of a key in the HashArray
Return value: the index (0+) or -1 if key not found
const string& key |
the key to find |
Determine if the provided key is inside the HashArray.
Return value: True if the key was found
const string& value |
the value to find |
Return the index of the first key-value pair found in the HashArray with the value provided.
Return value: the index (0+) or -1 if value not found
const string& value |
the value to find |
Determine if the value provided is contained in one of the key-value pairs.
Return value: True if value found
long value |
the value to find (converted to string) |
Return the index of the first key-value pair found in the HashArray with the value provided.
Return value: the index (0+) or -1 if value not found
long value |
the value to find (converted to string) |
Determine if the value provided is contained in one of the key-value pairs.
Return value: True if value found
const string& value |
the value to find |
Given a value, return the first matching key
Return value: key as string for that value, or null string if not found
long value |
the value to find (converted to string) |
Given a value, return the first matching key
Return value: key as string for that value, or null string if not found
Convert all the keys to lower case.
Convert all the keys to upper case.
int index |
the key to find |
Return the key for the provided index.
Note that this index is not guaranteed to be correct after a call to set().
Return value: the offset into the HashArray where the key was found
int index |
the key to find |
Return the value for the provided index.
Note that this index is not guaranteed to be correct after a call to set().
Return value: the offset into the HashArray where the key was found
Get the list of keys in the HashArray
Return value: a vector of strings of the keys
Get the list of values in the HashArray.
If more than one key has a same value, then the value is repeated.
Return value: a vector of strings of the keys
const string& separator |
Specify a key-pair separator other than newline. Default value: "\n" |
Serialize the HashArray into a string.
Return value: a string representing the HashArray
string text |
input string which is a serialized HashArray |
char separator |
specify an alternate key-pair separator than newline Default value: '\n' |
Deserialize a HashArray - take a string and convert it to a HashArray.
Any previous key-pair values in the HashArray are cleared.
string text |
input string which is a serialized HashArray |
string separator |
specify the key-pair separator |
Deserialize a HashArray - take a string and convert it to a HashArray.
Any previous key-pair values in the HashArray are cleared.
bool numeric |
if true, a numeric sort is used instead of alphanumeric Default value: false |
Sort the key-value pairs by the keys. This effects the getKeys() output.
bool numeric |
if true, a numeric sort is used instead of alphanumeric Default value: false |
Sort the key-value pairs by the values. This effects the getValues() output.
const HashArray& array2 |
the other HashArray to combine into this HashArray |
Add the provided HashArray to the existing HashArray. For any duplicate keys, the value from array2 will override.
Return value: this HashArray
const HashArray& array1 |
the first array |
const HashArray& array2 |
the second array |
Combine two HashArray structures. For any duplicate keys, the value from array2 will override.
Return value: a new HashArray
const HashArray& array2 |
the second array |
Combine two HashArray structures. For any duplicate keys, the value from array2 will override.
Return value: a new HashArray
const HashArray& array2 |
the other HashArray to combine into this HashArray |
Add the provided HashArray to the existing HashArray. For any duplicate keys, the value from array2 will override.
Return value: this HashArray
unsigned int ha_size |
|
vector <string > keys |
|
vector <string > values |
string key |
|
const string& value |
int key |
|
const string& value |