24 #ifndef PXR_BASE_TF_STL_H 25 #define PXR_BASE_TF_STL_H 32 #include "pxr/base/tf/api.h" 34 #include "pxr/base/tf/hashmap.h" 35 #include "pxr/base/tf/hashset.h" 38 #include <boost/call_traits.hpp> 46 PXR_NAMESPACE_OPEN_SCOPE
50 struct Tf_MapLookupHelper {
53 template <
class Key,
class Result>
54 static bool Lookup(Container
const& map, Key
const &key, Result* valuePtr)
56 typename Container::const_iterator i = map.find(key);
61 *valuePtr = i->second;
87 template <
class Container,
class Key,
class Result>
88 bool TfMapLookup(Container
const &map, Key
const &key, Result* valuePtr)
90 return Tf_MapLookupHelper<Container>::Lookup(map, key, valuePtr);
113 template <
class Container,
class Key,
class Result>
115 Key
const &key,
const Result &defaultValue)
117 typename Container::const_iterator i = map.find(key);
118 if (i == map.end()) {
141 template <
class Container,
class Key>
142 typename Container::mapped_type *
145 typename Container::iterator i = map.find(key);
146 return (i != map.end()) ? &(i->second) : NULL;
149 template <
class Container,
class Key>
150 typename Container::mapped_type
const *
153 typename Container::const_iterator i = map.find(key);
154 return (i != map.end()) ? &(i->second) : NULL;
165 template <
typename T>
166 inline std::pair<T,T>
168 return (a < b) ? std::pair<T,T>(a,b) : std::pair<T,T>(b,a);
193 TF_API
size_t Tf_GetEmptyHashMapBucketCount();
196 template <
class Key,
class Value,
class Hash,
class Equal,
class Alloc>
197 inline void TfReset(TfHashMap<Key, Value, Hash, Equal, Alloc> &hash){
204 static size_t emptyCount = Tf_GetEmptyHashMapBucketCount();
206 if (hash.bucket_count() > emptyCount)
207 TfHashMap<Key, Value, Hash, Equal, Alloc>(0).swap(hash);
208 else if (!hash.empty())
212 TF_API
size_t Tf_GetEmptyHashSetBucketCount();
215 template <
class Value,
class Hash,
class Equal,
class Alloc>
216 inline void TfReset(TfHashSet<Value, Hash, Equal, Alloc> &hash) {
217 static size_t emptyCount = Tf_GetEmptyHashSetBucketCount();
220 if (hash.bucket_count() > emptyCount)
221 TfHashSet<Value, Hash, Equal, Alloc>(0).swap(hash);
222 else if (!hash.empty())
232 inline typename boost::call_traits<T>::param_type
248 template <
class InputIterator1,
class InputIterator2,
class OutputIterator>
251 InputIterator2 first2, InputIterator2 last2,
252 OutputIterator result)
254 typedef std::multiset<typename InputIterator2::value_type> SetType;
255 SetType set2(first2, last2);
259 for (InputIterator1 i = first1; i != last1; ++i) {
260 typename SetType::iterator j = set2.find(*i);
279 template <
class BackInsertionSequence,
280 class InputIterator1,
class InputIterator2>
281 BackInsertionSequence
283 InputIterator2 first2, InputIterator2 last2)
285 BackInsertionSequence result;
287 std::back_inserter(result));
302 template <
class InputIterator1,
class InputIterator2,
class OutputIterator>
305 InputIterator2 first2, InputIterator2 last2,
306 OutputIterator result)
308 typedef std::set<typename InputIterator1::value_type> Set1Type;
309 typedef std::set<typename InputIterator2::value_type> Set2Type;
312 Set2Type set2(first2, last2);
316 for (InputIterator1 i = first1; i != last1; ++i)
317 if (set1.insert(*i).second && !set2.count(*i))
332 template <
class BackInsertionSequence,
333 class InputIterator1,
class InputIterator2>
334 BackInsertionSequence
336 InputIterator1 last1,
337 InputIterator2 first2,
338 InputIterator2 last2)
340 BackInsertionSequence result;
342 std::back_inserter(result));
354 template <
class ForwardIterator,
class Predicate>
355 static inline ForwardIterator
356 TfFindBoundary(ForwardIterator first, ForwardIterator last,
357 Predicate
const &pred)
359 size_t len = std::distance(first, last);
361 ForwardIterator middle;
366 std::advance(middle, half);
370 len = len - half - 1;
394 template <
class PairOrTuple>
395 using return_type =
typename std::tuple_element<N, PairOrTuple>::type;
397 template <
class PairOrTuple>
398 constexpr return_type<PairOrTuple>& operator()(PairOrTuple& p)
const 400 return std::get<N>(p);
403 template <
class PairOrTuple>
404 constexpr
const return_type<PairOrTuple>& operator()(
405 const PairOrTuple& p)
const 407 return std::get<N>(p);
410 template <
class PairOrTuple>
411 constexpr return_type<PairOrTuple>&& operator()(PairOrTuple&& p)
const 413 return std::get<N>(std::move(p));
417 PXR_NAMESPACE_CLOSE_SCOPE
419 #endif // PXR_BASE_TF_STL_H void TfReset(T &obj)
Reset obj to be an empty, space-optimized object.
A simple iterator adapter for STL containers.
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,...
std::pair< T, T > TfOrderedPair(T a, T b)
Return an std::pair in sorted order.
BackInsertionSequence TfOrderedSetDifferenceToContainer(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
Produce a sequence consisting of the set difference of [first1, last1) and [first2,...
BackInsertionSequence TfOrderedUniquingSetDifferenceToContainer(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
Produce a sequence consisting of the set difference of the unique elements in [first1,...
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,...
const Result TfMapLookupByValue(Container const &map, Key const &key, const Result &defaultValue)
Checks if an item exists in a map or a TfHashMap.
bool TfMapLookup(Container const &map, Key const &key, Result *valuePtr)
Checks if an item exists in a map or a TfHashMap.
Function object for retrieving the N'th element of a std::pair or std::tuple.
boost::call_traits< T >::param_type TfIdentity(typename boost::call_traits< T >::param_type arg)
An unary function that represents the identity function; it takes a single argument arg,...
Container::mapped_type * TfMapLookupPtr(Container &map, Key const &key)
Checks if an item exists in a map or TfHashMap, without copying it.
A file containing basic constants and definitions.