Open Lighting Architecture
0.9.0
|
Various helper functions related to STL classes.
Files | |
file | STLUtils.h |
Helper functions for STL classes. |
Functions | |
template<typename T > | |
void | ola::STLDeleteElements (T *sequence) |
Delete the elements of a Sequence. | |
template<typename T > | |
void | ola::STLDeleteValues (T *container) |
template<typename T1 , typename T2 > | |
bool | ola::STLContains (const T1 &container, const T2 &value) |
template<typename T1 > | |
void | ola::STLKeys (const T1 &container, std::vector< typename T1::key_type > *keys) |
template<typename T1 , typename T2 > | |
void | ola::STLValues (const T1 &container, std::vector< T2 > *values) |
Extract a vector of values from a pair associative container. | |
template<typename T1 > | |
T1::mapped_type * | ola::STLFind (T1 *container, const typename T1::key_type &key) |
Lookup a value by key in a associative container. | |
template<typename T1 > | |
T1::mapped_type | ola::STLFindOrNull (const T1 &container, const typename T1::key_type &key) |
Lookup a value by key in a associative container. | |
template<typename T1 > | |
bool | ola::STLReplace (T1 *container, const typename T1::key_type &key, const typename T1::mapped_type &value) |
Replace a value in a pair associative container, inserting the key, value if it doesn't already exist. | |
template<typename T1 > | |
T1::mapped_type | ola::STLReplacePtr (T1 *container, const typename T1::key_type &key, const typename T1::mapped_type &value) |
Replace a value in a pair associative container. If the key existed, the old value is returned, otherwise NULL is returned. | |
template<typename T1 > | |
bool | ola::STLReplaceAndDelete (T1 *container, const typename T1::key_type &key, const typename T1::mapped_type &value) |
Similar to STLReplace but this will delete the value if the replacement occurs. | |
template<typename T1 > | |
bool | ola::STLInsertIfNotPresent (T1 *container, const typename T1::value_type &key_value) |
Insert a value into a container only if this value doesn't already exist. | |
template<typename T1 > | |
bool | ola::STLInsertIfNotPresent (T1 *container, const typename T1::key_type &key, const typename T1::mapped_type &value) |
Insert a value into a container only if this value doesn't already exist. | |
template<typename T1 > | |
void | ola::STLInsertOrDie (T1 *container, const typename T1::key_type &key, const typename T1::mapped_type &value) |
Insert an key : value into a pair associative container, or abort the program if the key already exists. | |
template<typename T1 > | |
bool | ola::STLRemove (T1 *container, const typename T1::key_type &key) |
Remove a key / value from a container. | |
template<typename T1 > | |
bool | ola::STLLookupAndRemove (T1 *container, const typename T1::key_type &key, typename T1::mapped_type *value) |
Lookup and remove a key from a pair associative container. | |
template<typename T1 > | |
bool | ola::STLRemoveAndDelete (T1 *container, const typename T1::key_type &key) |
Remove a value from a pair associative container and delete it. | |
template<typename T1 > | |
T1::mapped_type | ola::STLLookupAndRemovePtr (T1 *container, const typename T1::key_type &key) |
Remove a value from a pair associative container and return the value. |
|
inline |
Returns true if the container contains the value.
T1 | A container. |
T2 | The value to search for. |
container | the container to search in. |
value | the value to search for. |
void ola::STLDeleteElements | ( | T * | sequence | ) |
Delete the elements of a Sequence.
sequence | the Sequence to delete the elements from. |
T | A Sequence. |
All elements in the sequence will be deleted. The sequence will be cleared.
class Foo() { public: Foo() { // populate m_objects } ~Foo() { STLDeleteElements(&m_objects); } private: vector<Bar*> m_objects; };
void ola::STLDeleteValues | ( | T * | container | ) |
Delete all values in a pair associative container.
container |
T | A pair associative container. |
All elements in the container will be deleted. The container will be cleared.
class Foo() { public: Foo() { // populate m_objects } ~Foo() { STLDeleteValues(&m_objects); } private: map<int, Bar*> m_objects; };
T1::mapped_type* ola::STLFind | ( | T1 * | container, |
const typename T1::key_type & | key | ||
) |
Lookup a value by key in a associative container.
T1 | A container. |
container | the container to search in. |
key | the key to search for. |
T1::mapped_type ola::STLFindOrNull | ( | const T1 & | container, |
const typename T1::key_type & | key | ||
) |
Lookup a value by key in a associative container.
T1 | A container. |
container | the container to search in. |
key | the key to search for. |
This assumes that NULL can be co-erced to the mapped_type of the container. It's most sutiable for containers with pointers.
bool ola::STLInsertIfNotPresent | ( | T1 * | container, |
const typename T1::value_type & | key_value | ||
) |
Insert a value into a container only if this value doesn't already exist.
T1 | A container. |
container | the container to insert the value in. |
key_value | the pair<key, value> to insert. |
bool ola::STLInsertIfNotPresent | ( | T1 * | container, |
const typename T1::key_type & | key, | ||
const typename T1::mapped_type & | value | ||
) |
Insert a value into a container only if this value doesn't already exist.
T1 | A container. |
container | the container to insert the value in. |
key | the key to insert. |
value | the value to insert. |
void ola::STLInsertOrDie | ( | T1 * | container, |
const typename T1::key_type & | key, | ||
const typename T1::mapped_type & | value | ||
) |
Insert an key : value into a pair associative container, or abort the program if the key already exists.
T1 | A container. |
container | the container to insert the value in. |
key | the key to insert. |
value | the value to insert. |
void ola::STLKeys | ( | const T1 & | container, |
std::vector< typename T1::key_type > * | keys | ||
) |
Extract the list of keys from a pair associative container.
T1 | A container. |
[in] | container | the container to extract the keys for. |
[out] | keys | the vector to populate with the keys. |
bool ola::STLLookupAndRemove | ( | T1 * | container, |
const typename T1::key_type & | key, | ||
typename T1::mapped_type * | value | ||
) |
Lookup and remove a key from a pair associative container.
T1 | A container. |
[in] | container | the container to remove the key from. |
[in] | key | the key to remove. |
[out] | value | A pointer which will be set to the removed value. |
Lookup a value by key in a pair associative container. If the value exists, it's removed from the container, the value placed in value and true is returned.
T1::mapped_type ola::STLLookupAndRemovePtr | ( | T1 * | container, |
const typename T1::key_type & | key | ||
) |
Remove a value from a pair associative container and return the value.
T1 | A container. |
[in] | container | the container to remove the key from. |
[in] | key | the key to remove. |
This assumes that NULL can be co-erced to the mapped_type of the container. It's most sutiable for containers with pointers.
bool ola::STLRemove | ( | T1 * | container, |
const typename T1::key_type & | key | ||
) |
Remove a key / value from a container.
T1 | A container. |
container | the container to remove the key from. |
key | the key to remove. |
bool ola::STLRemoveAndDelete | ( | T1 * | container, |
const typename T1::key_type & | key | ||
) |
Remove a value from a pair associative container and delete it.
T1 | A container. |
[in] | container | the container to remove the key from. |
[in] | key | the key to remove. |
bool ola::STLReplace | ( | T1 * | container, |
const typename T1::key_type & | key, | ||
const typename T1::mapped_type & | value | ||
) |
Replace a value in a pair associative container, inserting the key, value if it doesn't already exist.
T1 | A container. |
container | the container to replace the value in. |
key | the key to insert / replace. |
value | the value to insert / replace. |
bool ola::STLReplaceAndDelete | ( | T1 * | container, |
const typename T1::key_type & | key, | ||
const typename T1::mapped_type & | value | ||
) |
Similar to STLReplace but this will delete the value if the replacement occurs.
T1 | A container. |
container | the container to replace the value in. |
key | the key to insert / replace. |
value | the value to insert / replace. |
T1::mapped_type ola::STLReplacePtr | ( | T1 * | container, |
const typename T1::key_type & | key, | ||
const typename T1::mapped_type & | value | ||
) |
Replace a value in a pair associative container. If the key existed, the old value is returned, otherwise NULL is returned.
T1 | A container. |
container | the container to replace the value in. |
key | the key to insert / replace. |
value | the value to insert / replace. |
void ola::STLValues | ( | const T1 & | container, |
std::vector< T2 > * | values | ||
) |
Extract a vector of values from a pair associative container.
T1 | A container. |
T2 | The type of the values. |
[in] | container | the container to extract the values for. |
[out] | values | the vector to populate with the values. |