FBX C++ API Reference
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fbxmap.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2015 Autodesk, Inc.
4  All rights reserved.
5 
6  Use of this software is subject to the terms of the Autodesk license agreement
7  provided at the time of installation or download, or which otherwise accompanies
8  this software in either electronic or hard copy form.
9 
10 ****************************************************************************************/
11 
13 #ifndef _FBXSDK_CORE_BASE_MAP_H_
14 #define _FBXSDK_CORE_BASE_MAP_H_
15 
16 #include <fbxsdk/fbxsdk_def.h>
17 
20 
21 #include <fbxsdk/fbxsdk_nsbegin.h>
22 
23 class FbxObject;
24 
58 template <typename Type> struct FbxLessCompare
59 {
60  inline int operator()(const Type& pLeft, const Type& pRight) const
61  {
62  return (pLeft < pRight) ? -1 : ((pRight < pLeft) ? 1 : 0);
63  }
64 };
65 
68 template <typename Key, typename Type, typename Compare=FbxLessCompare<Key>, typename Allocator=FbxBaseAllocator> class FbxMap
69 {
70 protected:
72  class KeyValuePair : private FbxPair<const Key, Type>
73  {
74  /*****************************************************************************************************************************
75  ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
76  *****************************************************************************************************************************/
77  #ifndef DOXYGEN_SHOULD_SKIP_THIS
78  public:
79  typedef const Key KeyType;
80  typedef const Key ConstKeyType;
81  typedef Type ValueType;
82  typedef const Type ConstValueType;
83 
84  KeyValuePair(const Key& pFirst, const Type& pSecond) : FbxPair<const Key, Type>(pFirst, pSecond){}
85  ConstKeyType& GetKey() const { return this->mFirst; }
86  KeyType& GetKey(){ return this->mFirst; }
87  ConstValueType& GetValue() const { return this->mSecond; }
88  ValueType& GetValue(){ return this->mSecond; }
89  #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
90  };
91 
93  typedef FbxRedBlackTree<KeyValuePair, Compare, Allocator> StorageType;
94 
95 public:
96  typedef Type ValueType;
97  typedef Key KeyType;
98  typedef typename StorageType::RecordType RecordType;
99  typedef typename StorageType::IteratorType Iterator;
100  typedef typename StorageType::ConstIteratorType ConstIterator;
101 
104  inline void Reserve(unsigned int pRecordCount)
105  {
106  mTree.Reserve(pRecordCount);
107  }
108 
110  inline int GetSize() const
111  {
112  return mTree.GetSize();
113  }
114 
119  inline FbxPair<RecordType*, bool> Insert(const KeyType& pKey, const ValueType& pValue)
120  {
121  return mTree.Insert(KeyValuePair(pKey, pValue));
122  }
123 
127  inline bool Remove(const KeyType& pKey)
128  {
129  return mTree.Remove(pKey);
130  }
131 
133  inline void Clear()
134  {
135  mTree.Clear();
136  }
137 
139  inline bool Empty() const
140  {
141  return mTree.Empty();
142  }
143 
145  Iterator Begin()
146  {
147  return Iterator(Minimum());
148  }
149 
151  Iterator End()
152  {
153  return Iterator();
154  }
155 
157  ConstIterator Begin() const
158  {
159  return ConstIterator(Minimum());
160  }
161 
163  ConstIterator End() const
164  {
165  return ConstIterator();
166  }
167 
171  inline const RecordType* Find(const KeyType& pKey) const
172  {
173  return mTree.Find(pKey);
174  }
175 
179  inline RecordType* Find(const KeyType& pKey)
180  {
181  return mTree.Find(pKey);
182  }
183 
187  inline const RecordType* UpperBound(const KeyType& pKey) const
188  {
189  return mTree.UpperBound(pKey);
190  }
191 
195  inline RecordType* UpperBound(const KeyType& pKey)
196  {
197  return mTree.UpperBound(pKey);
198  }
199 
204  inline ValueType& operator[](const KeyType& pKey)
205  {
206  RecordType* lRecord = Find(pKey);
207 
208  if( !lRecord )
209  {
210  lRecord = Insert(pKey, ValueType()).mFirst;
211  }
212 
213  return lRecord->GetValue();
214  }
215 
217  inline const RecordType* Minimum() const
218  {
219  return mTree.Minimum();
220  }
221 
223  inline RecordType* Minimum()
224  {
225  return mTree.Minimum();
226  }
227 
229  inline const RecordType* Maximum() const
230  {
231  return mTree.Maximum();
232  }
233 
235  inline RecordType* Maximum()
236  {
237  return mTree.Maximum();
238  }
239 
240 /*****************************************************************************************************************************
241 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
242 *****************************************************************************************************************************/
243 #ifndef DOXYGEN_SHOULD_SKIP_THIS
244  inline FbxMap(){}
245  inline FbxMap(const FbxMap& pMap) : mTree(pMap.mTree){}
246  inline ~FbxMap(){ Clear(); }
247 
248 private:
249  StorageType mTree;
250 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
251 };
252 
255 template <class Key, class Type, class Compare> class FBXSDK_DLL FbxSimpleMap
256 {
257 public:
259 
263  inline void Add(const Key& pKey, const Type& pValue)
264  {
265  mMap.Insert(pKey, pValue);
266  }
267 
271  inline Iterator Find(const Key& pKey) const
272  {
273  return (Iterator)mMap.Find(pKey);
274  }
275 
279  inline Iterator Find(const Type& pValue) const
280  {
281  Iterator lIterator = GetFirst();
282  while( lIterator )
283  {
284  if( lIterator->GetValue() == pValue )
285  {
286  return lIterator;
287  }
288  lIterator = GetNext(lIterator);
289  }
290  return 0;
291  }
292 
295  inline void Remove(Iterator pIterator)
296  {
297  if( pIterator ) mMap.Remove(pIterator->GetKey());
298  }
299 
302  inline Iterator GetFirst() const
303  {
304  return (Iterator)mMap.Minimum();
305  }
306 
310  inline Iterator GetNext(Iterator pIterator) const
311  {
312  return (Iterator)pIterator ? pIterator->Successor() : 0;
313  }
314 
316  inline void Clear()
317  {
318  mMap.Clear();
319  }
320 
323  inline void Reserve(int pSize)
324  {
325  mMap.Reserve(pSize);
326  }
327 
330  inline int GetCount() const
331  {
332  return mMap.GetSize();
333  }
334 
335 /*****************************************************************************************************************************
336 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
337 *****************************************************************************************************************************/
338 #ifndef DOXYGEN_SHOULD_SKIP_THIS
339  inline FbxSimpleMap(){}
340 
341 private:
343 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
344 };
345 
348 template <class Type, class Compare> class FBXSDK_DLL FbxObjectMap : public FbxSimpleMap<Type, FbxObject*, Compare>
349 {
350 public:
352  inline FbxObjectMap(){}
353 
359  {
360  return pIterator ? pIterator->GetValue() : 0;
361  }
362 };
363 
366 class FBXSDK_DLL FbxObjectStringMap : public FbxObjectMap<FbxString, FbxStringCompare>
367 {
368 public:
371 };
372 
374 template <typename K, typename V, typename C, typename A> inline void FbxMapFree(FbxMap<K, V, C, A>& pMap)
375 {
376  for( typename FbxMap<K, V, C, A>::Iterator i = pMap.Begin(); i != pMap.End(); ++i )
377  {
378  FbxFree(i->GetValue());
379  }
380  pMap.Clear();
381 }
382 
384 template <typename K, typename V, typename C, typename A> inline void FbxMapDelete(FbxMap<K, V, C, A>& pMap)
385 {
386  for( typename FbxMap<K, V, C, A>::Iterator i = pMap.Begin(); i != pMap.End(); ++i )
387  {
388  FbxDelete(i->GetValue());
389  }
390  pMap.Clear();
391 }
392 
394 template <typename K, typename V, typename C, typename A> inline void FbxMapDestroy(FbxMap<K, V, C, A>& pMap)
395 {
396  for( typename FbxMap<K, V, C, A>::Iterator i = pMap.Begin(); i != pMap.End(); ++i )
397  {
398  i->GetValue()->Destroy();
399  }
400  pMap.Clear();
401 }
402 
405 
406 #include <fbxsdk/fbxsdk_nsend.h>
407 
408 #endif /* _FBXSDK_CORE_BASE_MAP_H_ */
void Remove(Iterator pIterator)
Remove an element from the map.
Definition: fbxmap.h:295
Iterator End()
Retrieve the end iterator of the map.
Definition: fbxmap.h:151
FBX SDK environment definition.
FbxObjectStringMap()
Constructor.
Definition: fbxmap.h:370
int operator()(const Type &pLeft, const Type &pRight) const
Definition: fbxmap.h:60
Iterator GetNext(Iterator pIterator) const
Get the next element of a given element.
Definition: fbxmap.h:310
Iterator Begin()
Retrieve the begin iterator of the map.
Definition: fbxmap.h:145
const RecordType * Minimum() const
Retrieve the key-value pair which is the minimum key in map.
Definition: fbxmap.h:217
A simple map class representing a dictionary-like data structure.
Definition: fbxmap.h:255
FbxMap< Key, Type, Compare >::RecordType * Iterator
Definition: fbxmap.h:258
void FbxMapDestroy(FbxMap< K, V, C, A > &pMap)
Call Destroy on each element of the map, and then clear it.
Definition: fbxmap.h:394
Type ValueType
Definition: fbxmap.h:96
FbxPair< RecordType *, bool > Insert(const KeyType &pKey, const ValueType &pValue)
Insert a key-value pair.
Definition: fbxmap.h:119
FbxObject * Get(typename FbxSimpleMap< Type, FbxObject *, Compare >::Iterator pIterator)
Get the object contained in an element.
Definition: fbxmap.h:358
A class that maps strings to objects with a basic string comparator.
Definition: fbxmap.h:366
const RecordType * Maximum() const
Retrieve the key-value pair which is the maximum key in map.
Definition: fbxmap.h:229
void FbxDelete(T *p)
Deletion policy for pointer template classes that uses the FbxDelete() function.
Definition: fbxnew.h:341
StorageType::IteratorType Iterator
Definition: fbxmap.h:99
RecordType * Minimum()
Retrieve the key-value pair which is the minimum key in map.
Definition: fbxmap.h:223
void Add(const Key &pKey, const Type &pValue)
Add a key-value pair as an element.
Definition: fbxmap.h:263
const RecordType * Find(const KeyType &pKey) const
Query a key.
Definition: fbxmap.h:171
Iterator Find(const Key &pKey) const
Find an element with a given key.
Definition: fbxmap.h:271
Key KeyType
Definition: fbxmap.h:97
ValueType & operator[](const KeyType &pKey)
Retrieve the reference of the value in the key-value pairs in map.
Definition: fbxmap.h:204
Iterator Find(const Type &pValue) const
Find an element with a given value.
Definition: fbxmap.h:279
This class implements an efficient map based on key comparison, which stores key-value pairs...
Definition: fbxmap.h:68
Default compare functor for FbxMap and FbxSet, which assumes operator < is defined.
Definition: fbxmap.h:58
The base class of most FBX objects.
Definition: fbxobject.h:157
RecordType * Maximum()
Retrieve the key-value pair which is the maximum key in map.
Definition: fbxmap.h:235
This class template holds a pair of objects.
Definition: fbxpair.h:22
FbxRedBlackTree< KeyValuePair, Compare, Allocator > StorageType
Declaration of the storage type used by the map.
Definition: fbxmap.h:93
void Reserve(unsigned int pRecordCount)
Preallocate memory.
Definition: fbxmap.h:104
bool Remove(const KeyType &pKey)
Delete a key-value pair.
Definition: fbxmap.h:127
ConstIterator Begin() const
Retrieve the begin iterator of the map.
Definition: fbxmap.h:157
void Reserve(int pSize)
Reserve the space for given number elements.
Definition: fbxmap.h:323
StorageType::ConstIteratorType ConstIterator
Definition: fbxmap.h:100
bool Empty() const
Query whether the map is empty.
Definition: fbxmap.h:139
RecordType * UpperBound(const KeyType &pKey)
Find the key-value pair with the smallest key greater than a specified key.
Definition: fbxmap.h:195
const RecordType * UpperBound(const KeyType &pKey) const
Find the key-value pair with the smallest key greater than a specified key.
Definition: fbxmap.h:187
void FbxMapFree(FbxMap< K, V, C, A > &pMap)
Call FbxFree on each element of the map, and then clear it.
Definition: fbxmap.h:374
#define FBXSDK_DLL
Definition: fbxarch.h:173
void Clear()
Clear the map.
Definition: fbxmap.h:133
int GetCount() const
Query the count of elements in the map.
Definition: fbxmap.h:330
int GetSize() const
Retrieve the number of key-value pairs it holds.
Definition: fbxmap.h:110
Iterator GetFirst() const
Get the first element.
Definition: fbxmap.h:302
This class template declare a simple FbxObject map.
Definition: fbxmap.h:348
void Clear()
Remove all of the elements.
Definition: fbxmap.h:316
FbxObjectMap()
Constructor.
Definition: fbxmap.h:352
void FbxMapDelete(FbxMap< K, V, C, A > &pMap)
Call FbxDelete on each element of the map, and then clear it.
Definition: fbxmap.h:384
RecordType * Find(const KeyType &pKey)
Query a key.
Definition: fbxmap.h:179
ConstIterator End() const
Retrieve the end iterator of the map.
Definition: fbxmap.h:163
This class defines the key-value pairs used by the map.
Definition: fbxmap.h:72
StorageType::RecordType RecordType
Definition: fbxmap.h:98