#include "map.h"
Public Member Functions | |
| Map (int sizeHint=101) | |
| ~Map () | |
| int | size () |
| bool | isEmpty () |
| void | add (string key, ValueType value) |
| void | remove (string key) |
| bool | containsKey (string key) |
| ValueType | getValue (string key) |
| ValueType & | operator[] (string key) |
| void | clear () |
| void | mapAll (void(fn)(string key, ValueType val)) |
| template<typename ClientDataType> | |
| void | mapAll (void(fn)(string key, ValueType val, ClientDataType &data), ClientDataType &data) |
| Iterator | iterator () |
| const Map & | operator= (const Map &rhs) |
| Map (const Map &rhs) | |
| template<typename ClientData> | |
| void | mapAll (void(*fn)(string key, ValueType value, ClientData &cd), ClientData &data) |
| template<typename ValueType> | |
| void | mapAll (void(*fn)(string key, ValueType value)) |
Friends | |
| class | Iterator |
Classes | |
| struct | cell |
| class | Iterator |
The constructor initializes a new empty map. The optional argument is a hint about the expected number of entries that this map will hold, which allows the map to configure itself for efficiency at that size. If not specified, a reasonable default is used and the map will adapt as entries are added. The explicit keyword is used to prevent accidental construction of a Map from an integer. Raises an error if sizeHint is negative.
The destructor deallocates storage associated with this map.
| int Map< ValueType >::size | ( | ) |
This member function returns the number of entries in this map.
| bool Map< ValueType >::isEmpty | ( | ) |
This member function returns true if this map contains no entries, false otherwise.
| void Map< ValueType >::add | ( | string | key, | |
| ValueType | value | |||
| ) |
This member function associates key with value in this map. Any previous value associated with key is replaced by this new entry. If there was already an entry for this key, the map's size is unchanged; otherwise, it increments by one.
| void Map< ValueType >::remove | ( | string | key | ) |
This member function removes any entry for key from this map. If there is no entry for the key, the map is unchanged. Otherwise, the key and its associated value are removed and the map's size decreases by one.
| bool Map< ValueType >::containsKey | ( | string | key | ) |
Returns true if there is an entry for key in this map, false otherwise.
| ValueType Map< ValueType >::getValue | ( | string | key | ) |
If key is found in this map, this member function returns the associated value. If key is not found, raises an error. The containsKey member function can be used to verify the presence of a key in the map before attempting to get its value.
| ValueType & Map< ValueType >::operator[] | ( | string | key | ) |
This member function overloads [] to access values from this map by key. The argument inside the brackets is the key (a string). This allows the client to use notation of an "associative-array" to get/set the value associated with a key. If the key is already present in the map, this function returns a reference to its associated value, and the size of the map is unchanged. If key is not present in the map, a new entry for the key is added, and the size of the map increases by one. The value for the newly entered key is set to the default for value type, and a reference to that value is returned. Because this function returns the value by reference, it allows in-place modification of the value.
| void Map< ValueType >::clear | ( | ) |
This member function removes all entries from this map. The map is made empty and will have size() = 0 after being cleared.
| void Map< ValueType >::mapAll | ( | void(fn)(string key, ValueType val) | ) |
This member function goes through every entry in this map and calls the function fn, passing it two arguments: the key and its associated value.
| void Map< ValueType >::mapAll | ( | void(fn)(string key, ValueType val, ClientDataType &data) | , | |
| ClientDataType & | data | |||
| ) |
This member function goes through every entry in this map and calls the function fn, passing it three arguments: the key, its associated value, and the client's data. That data can be of whatever type is needed for the client's callback.
This member function creates an iterator that allows the client to iterate through the keys in this map. Note that the iterator returns the _keys_ one by one. If needed, you can retrieve the associated value from the map using getValue or operator[].
| const Map< ValueType > & Map< ValueType >::operator= | ( | const Map< ValueType > & | rhs | ) |
This copy constructor and operator= are defined to make a deep copy, making it possible to pass/return maps by value and assign from one map to another. The entire contents of the map, including all entries, are copied. Each map entry is copied from the original map to the copy using assignment (operator=). Making copies is generally avoided because of the expense and thus, maps are typically passed by reference, however, when a copy is needed, these operations are supported.
| void Map< ValueType >::mapAll | ( | void(*)(string key, ValueType value, ClientData &cd) | fn, | |
| ClientData & | data | |||
| ) |
| void Map< ValueType >::mapAll | ( | void(*)(string key, ValueType value) | fn | ) |
friend class Iterator [friend] |
1.5.1