All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
C++ STL Utilities

Helper functions/classes for STL. More...

+ Collaboration diagram for C++ STL Utilities:

Files

file  stl.h
 

Classes

class  TfGet< N >
 Function object for retrieving the N'th element of a std::pair or std::tuple. More...
 
class  TfIterator< T, Reverse >
 A simple iterator adapter for STL containers. More...
 
struct  TfDeleter
 Function object for deleting any pointer. More...
 

Functions

template<class Container , class Key , class Result >
bool TfMapLookup (Container const &map, Key const &key, Result *valuePtr)
 Checks if an item exists in a map or a TfHashMap. More...
 
template<class Container , class Key , class Result >
const Result TfMapLookupByValue (Container const &map, Key const &key, const Result &defaultValue)
 Checks if an item exists in a map or a TfHashMap. More...
 
template<class Container , class Key >
Container::mapped_type * TfMapLookupPtr (Container &map, Key const &key)
 Checks if an item exists in a map or TfHashMap, without copying it. More...
 
template<typename T >
std::pair< T, T > TfOrderedPair (T a, T b)
 Return an std::pair in sorted order. More...
 

Detailed Description

Helper functions/classes for STL.

Function Documentation

bool TfMapLookup ( Container const &  map,
Key const &  key,
Result *  valuePtr 
)

Checks if an item exists in a map or a TfHashMap.

If key exists in map, then this function returns true and the value indexed by key is copied into *valuePtr. Otherwise, *valuePtr is not modified, and false is returned.

Example:

* TfHashMap<string, int, TfHash> m = ...;
* int value;
*
*
* if (TfMapLookup(m, "someKey", &value))
* printf("Value found: %d\n", value);
* else
* printf("Value not found\n");
* ...
*

Definition at line 88 of file stl.h.

const Result TfMapLookupByValue ( Container const &  map,
Key const &  key,
const Result &  defaultValue 
)

Checks if an item exists in a map or a TfHashMap.

If key exists in map, then this function returns the value index by key. Otherwise, defaultValue is returned. Note that the result is returned by value, so this is best used for types that are quick to copy.

Example:

* TfHashMap<string, int, TfHash> m;
* m["foo"] = 1;
*
* int value = TfMapLookupByValue(m, "someKey", -1);
* TF_AXIOM(value == -1);
*
* int value = TfMapLookupByValue(m, "foo", -1);
* TF_AXIOM(value == 1);
*
*

Definition at line 114 of file stl.h.

Container::mapped_type* TfMapLookupPtr ( Container &  map,
Key const &  key 
)

Checks if an item exists in a map or TfHashMap, without copying it.

If key exists in the map, then this function returns a pointer to the value indexed by key. Otherwise, NULL is returned.

Example:

* TfHashMap<string, BigData, TfHash> m = ...;
*
* if (BigData* bigPtr = TfMapLookupPtr(m, "someKey"))
* bigPtr->ModifyStuff();
* else
* printf("Value not found\n");
*

Definition at line 143 of file stl.h.

std::pair<T,T> TfOrderedPair ( a,
b 
)
inline

Return an std::pair in sorted order.

This call is a useful helper for maps whose key is an unordered pair of elements. One can either define a new data type such that (a,b) is deemed equivalent to (b,a), or more simply, adopt the convention that a key is always written (a,b) with a < b.

Definition at line 167 of file stl.h.