33 #ifndef INCLUDE_OLA_STL_STLUTILS_H_ 34 #define INCLUDE_OLA_STL_STLUTILS_H_ 57 while (!stack->empty()) {
69 while (!stack->empty()) {
100 typename T::iterator iter = sequence->begin();
101 for (; iter != sequence->end(); ++iter) {
135 typename T::iterator iter = container->begin();
136 for (; iter != container->end(); ++iter) {
151 template<
typename T1,
typename T2>
153 return container.find(value) != container.end();
162 template<
typename T1>
163 void STLKeys(
const T1 &container, std::vector<typename T1::key_type> *keys) {
164 keys->reserve(keys->size() + container.size());
165 typename T1::const_iterator iter = container.begin();
166 for (; iter != container.end(); ++iter)
167 keys->push_back(iter->first);
177 template<
typename T1,
typename T2>
178 void STLValues(
const T1 &container, std::vector<T2> *values) {
179 values->reserve(values->size() + container.size());
180 typename T1::const_iterator iter = container.begin();
181 for (; iter != container.end(); ++iter)
182 values->push_back(iter->second);
192 template<
typename T1>
193 typename T1::mapped_type*
STLFind(T1 *container,
194 const typename T1::key_type &key) {
195 typename T1::iterator iter = container->find(key);
196 if (iter == container->end()) {
199 return &iter->second;
210 template<
typename T1>
211 typename T1::mapped_type
const*
STLFind(
const T1 *container,
212 const typename T1::key_type &key) {
213 typename T1::const_iterator iter = container->find(key);
214 if (iter == container->end()) {
217 return &iter->second;
231 template<
typename T1>
233 const typename T1::key_type &key) {
234 typename T1::const_iterator iter = container.find(key);
235 if (iter == container.end()) {
257 template<
typename T1>
258 bool STLReplace(T1 *container,
const typename T1::key_type &key,
259 const typename T1::mapped_type &value) {
260 std::pair<typename T1::iterator, bool> p = container->insert(
261 typename T1::value_type(key, value));
263 p.first->second = value;
282 template<
typename T1>
284 const typename T1::key_type &key,
285 const typename T1::mapped_type &value) {
286 std::pair<typename T1::iterator, bool> p = container->insert(
287 typename T1::value_type(key, value));
289 typename T1::mapped_type old_value = p.first->second;
290 p.first->second = value;
306 template<
typename T1>
308 const typename T1::mapped_type &value) {
309 std::pair<typename T1::iterator, bool> p = container->insert(
310 typename T1::value_type(key, value));
312 delete p.first->second;
313 p.first->second = value;
328 template<
typename T1>
330 const typename T1::value_type &key_value) {
331 return container->insert(key_value).second;
345 template<
typename T1>
347 const typename T1::mapped_type &value) {
348 return container->insert(
typename T1::value_type(key, value)).second;
361 template<
typename T1>
363 const typename T1::mapped_type &value) {
364 assert(container->insert(
typename T1::value_type(key, value)).second);
375 template<
typename T1>
376 bool STLRemove(T1 *container,
const typename T1::key_type &key) {
377 return container->erase(key);
392 template<
typename T1>
394 const typename T1::key_type &key,
395 typename T1::mapped_type *value) {
396 typename T1::iterator iter = container->find(key);
397 if (iter == container->end()) {
400 *value = iter->second;
401 container->erase(iter);
416 template<
typename T1>
418 const typename T1::key_type &key) {
419 std::pair<typename T1::iterator, bool> p = container->insert(
420 typename T1::value_type(key, NULL));
424 template<
typename T1>
425 void PairAssociativeAssignNew(T1 **location) {
426 *location =
new T1();
436 template<
typename T1>
438 const typename T1::key_type &key) {
439 std::pair<typename T1::iterator, bool> p = container->insert(
440 typename T1::value_type(key, NULL));
442 PairAssociativeAssignNew(&p.first->second);
455 template<
typename T1>
457 typename T1::iterator iter = container->find(key);
458 if (iter == container->end()) {
462 container->erase(iter);
477 template<
typename T1>
480 const typename T1::key_type &key) {
481 typename T1::iterator iter = container->find(key);
482 if (iter == container->end()) {
485 typename T1::mapped_type value = iter->second;
486 container->erase(iter);
502 template<
typename T1,
typename T2>
504 typename T1::mapped_type value) {
505 typename T2::const_iterator iter = input.begin();
506 for (; iter != input.end(); ++iter) {
507 std::pair<typename T1::iterator, bool> p = output->insert(
508 typename T1::value_type(*iter, value));
510 p.first->second = value;
515 #endif // INCLUDE_OLA_STL_STLUTILS_H_ T1::mapped_type STLFindOrNull(const T1 &container, const typename T1::key_type &key)
Lookup a value by key in a associative container.
Definition: STLUtils.h:232
void STLMapFromKeys(T1 *output, const T2 input, typename T1::mapped_type value)
Definition: STLUtils.h:503
bool STLRemoveAndDelete(T1 *container, const typename T1::key_type &key)
Remove a value from a pair associative container and delete it.
Definition: STLUtils.h:456
bool 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.
Definition: STLUtils.h:307
void STLEmptyStack(T *stack)
Clear a stack.
Definition: STLUtils.h:56
T1::iterator STLLookupOrInsertNull(T1 *container, const typename T1::key_type &key)
Lookup or insert a NULL value into a pair associative container.
Definition: STLUtils.h:417
bool STLLookupAndRemove(T1 *container, const typename T1::key_type &key, typename T1::mapped_type *value)
Lookup and remove a key from a pair associative container.
Definition: STLUtils.h:393
void STLEmptyStackAndDelete(T *stack)
Clear a stack and delete all pointers..
Definition: STLUtils.h:68
bool STLRemove(T1 *container, const typename T1::key_type &key)
Remove a key / value from a container.
Definition: STLUtils.h:376
void STLDeleteElements(T *sequence)
Delete the elements of a Sequence.
Definition: STLUtils.h:99
void STLValues(const T1 &container, std::vector< T2 > *values)
Extract a vector of values from a pair associative container.
Definition: STLUtils.h:178
T1::iterator STLLookupOrInsertNew(T1 *container, const typename T1::key_type &key)
Lookup or insert a new object into a pair associative container.
Definition: STLUtils.h:437
bool STLContains(const T1 &container, const T2 &value)
Definition: STLUtils.h:152
void STLKeys(const T1 &container, std::vector< typename T1::key_type > *keys)
Definition: STLUtils.h:163
void 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 exis...
Definition: STLUtils.h:362
void STLDeleteValues(T *container)
Definition: STLUtils.h:134
bool 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...
Definition: STLUtils.h:258
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
T1::mapped_type * STLFind(T1 *container, const typename T1::key_type &key)
Lookup a value by key in a associative container.
Definition: STLUtils.h:193
T1::mapped_type STLLookupAndRemovePtr(T1 *container, const typename T1::key_type &key)
Remove a value from a pair associative container and return the value.
Definition: STLUtils.h:478
bool STLInsertIfNotPresent(T1 *container, const typename T1::value_type &key_value)
Insert a value into a container only if this value doesn't already exist.
Definition: STLUtils.h:329
T1::mapped_type 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...
Definition: STLUtils.h:283