HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stl.h File Reference
#include "pxr/pxr.h"
#include "pxr/base/tf/api.h"
#include "pxr/base/tf/tf.h"
#include "pxr/base/tf/hashmap.h"
#include "pxr/base/tf/hashset.h"
#include "pxr/base/tf/iterator.h"
#include <algorithm>
#include <iterator>
#include <map>
#include <set>
#include <utility>
+ Include dependency graph for stl.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Tf_MapLookupHelper< T >
 
class  TfGet< N >
 

Functions

template<class Container , class Key , class Result >
bool TfMapLookup (Container const &map, Key const &key, Result *valuePtr)
 
template<class Container , class Key , class Result >
const Result TfMapLookupByValue (Container const &map, Key const &key, const Result &defaultValue)
 
template<class Container , class Key >
Container::mapped_type * TfMapLookupPtr (Container &map, Key const &key)
 
template<class Container , class Key >
Container::mapped_type const * TfMapLookupPtr (Container const &map, Key const &key)
 
template<typename T >
std::pair< T, T > TfOrderedPair (T a, T b)
 
template<class T >
void TfReset (T &obj)
 
TF_API size_t Tf_GetEmptyHashMapBucketCount ()
 
template<class Key , class Value , class Hash , class Equal , class Alloc >
void TfReset (TfHashMap< Key, Value, Hash, Equal, Alloc > &hash)
 Specialize for TfHashMap to make minimally sized hashes. More...
 
TF_API size_t Tf_GetEmptyHashSetBucketCount ()
 
template<class Value , class Hash , class Equal , class Alloc >
void TfReset (TfHashSet< Value, Hash, Equal, Alloc > &hash)
 Specialize for TfHashSet to make minimally sized hashes. More...
 
template<class InputIterator1 , class InputIterator2 , class OutputIterator >
void TfOrderedSetDifference (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
 
template<class BackInsertionSequence , class InputIterator1 , class InputIterator2 >
BackInsertionSequence TfOrderedSetDifferenceToContainer (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
 
template<class InputIterator1 , class InputIterator2 , class OutputIterator >
void TfOrderedUniquingSetDifference (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
 
template<class BackInsertionSequence , class InputIterator1 , class InputIterator2 >
BackInsertionSequence TfOrderedUniquingSetDifferenceToContainer (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
 

Function Documentation

TF_API size_t Tf_GetEmptyHashMapBucketCount ( )
TF_API size_t Tf_GetEmptyHashSetBucketCount ( )
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.

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:

int value;
if (TfMapLookup(m, "someKey", &value))
printf("Value found: %d\n", value);
else
printf("Value not found\n");
...

Definition at line 86 of file stl.h.

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.

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:

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 112 of file stl.h.

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.

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

Example:

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

Definition at line 141 of file stl.h.

template<class Container , class Key >
Container::mapped_type const* TfMapLookupPtr ( Container const &  map,
Key const &  key 
)

Definition at line 149 of file stl.h.

template<typename T >
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 165 of file stl.h.

template<class InputIterator1 , class InputIterator2 , class OutputIterator >
void TfOrderedSetDifference ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
InputIterator2  last2,
OutputIterator  result 
)

Produce a sequence consisting of the set difference of [first1, last1) and [first2, last2), while maintaining the relative order of the first sequence. No particular order is required for either range, but elements must have a strict weak order provided by operator<.

If an element appears multiple times in either the first or second sequence, the number of occurrences in the output is the difference between the first sequence and the second (or zero if there are more occurrences in the second sequence). For example, if the first sequence is (1, 3, 3, 1) and the second sequence is (2, 3, 2), the result will be (1, 3, 1).

Definition at line 237 of file stl.h.

template<class BackInsertionSequence , class InputIterator1 , class InputIterator2 >
BackInsertionSequence TfOrderedSetDifferenceToContainer ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
InputIterator2  last2 
)

Produce a sequence consisting of the set difference of [first1, last1) and [first2, last2), while maintaining the relative order of the first sequence. No particular order is required for either range, but elements must have a strict weak order provided by operator<.

If an element appears multiple times in either the first or second sequence, the number of occurrences in the output is the difference between the first sequence and the second (or zero if there are more occurrences in the second sequence). For example, if the first sequence is (1, 3, 3, 1) and the second sequence is (2, 3, 2), the result will be (1, 3, 1).

Definition at line 269 of file stl.h.

template<class InputIterator1 , class InputIterator2 , class OutputIterator >
void TfOrderedUniquingSetDifference ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
InputIterator2  last2,
OutputIterator  result 
)

Produce a sequence consisting of the set difference of the unique elements in [first1, last1) and [first2, last2), while maintaining the relative order of the first sequence. No particular order is required for either range, but elements must have a strict weak order provided by operator<.

If an element appears multiple times in the first sequence, it appears either zero or one times in the output. It appears zero times if it appears in the second sequence, and one time if it does not. For example, if the first sequence is (1, 3, 3, 1) and the second sequence is (2, 3, 2), the result will be (1).

Definition at line 291 of file stl.h.

template<class BackInsertionSequence , class InputIterator1 , class InputIterator2 >
BackInsertionSequence TfOrderedUniquingSetDifferenceToContainer ( InputIterator1  first1,
InputIterator1  last1,
InputIterator2  first2,
InputIterator2  last2 
)

Produce a sequence consisting of the set difference of the unique elements in [first1, last1) and [first2, last2), while maintaining the relative order of the first sequence. No particular order is required for either range, but elements must have a strict weak order provided by operator<.

If an element appears multiple times in the first sequence, it appears either zero or one times in the output. It appears zero times if it appears in the second sequence, and one time if it does not. For example, if the first sequence is (1, 3, 3, 1) and the second sequence is (2, 3, 2), the result will be (1).

Definition at line 322 of file stl.h.

template<class T >
void TfReset ( T &  obj)
inline

Reset obj to be an empty, space-optimized object.

This can be used to clear c++ containers and reclaim their memory. For instance, std::vector::clear() will not reclaim any memory, even if the vector previously had a large number of elements. Often, this is what you want because the vector is later filled again. But sometimes you want to reclaim the memory, and this function will do that.

As another example, gcc's hash_map and hash_set do not clear their bucket lists when they themselves are cleared. This can lead to poor performance due to ever-growing bucket lists for hashes that are repeatedly filled, cleared, and filled again. TfReset will avoid this by effectively clearing the bucket list.

This function requires that the expression T().swap(obj) where obj is of type T& be valid. This is true for many classes, including the standard containers.

Definition at line 187 of file stl.h.

template<class Key , class Value , class Hash , class Equal , class Alloc >
void TfReset ( TfHashMap< Key, Value, Hash, Equal, Alloc > &  hash)
inline

Specialize for TfHashMap to make minimally sized hashes.

Definition at line 195 of file stl.h.

template<class Value , class Hash , class Equal , class Alloc >
void TfReset ( TfHashSet< Value, Hash, Equal, Alloc > &  hash)
inline

Specialize for TfHashSet to make minimally sized hashes.

Definition at line 214 of file stl.h.