fbxset.h

Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2013 Autodesk, Inc.
00004    All rights reserved.
00005  
00006    Use of this software is subject to the terms of the Autodesk license agreement
00007    provided at the time of installation or download, or which otherwise accompanies
00008    this software in either electronic or hard copy form.
00009  
00010 ****************************************************************************************/
00011 
00013 #ifndef _FBXSDK_CORE_BASE_SET_H_
00014 #define _FBXSDK_CORE_BASE_SET_H_
00015 
00016 #include <fbxsdk/fbxsdk_def.h>
00017 
00018 #include <fbxsdk/core/base/fbxredblacktree.h>
00019 #include <fbxsdk/core/base/fbxmap.h>
00020 
00021 #include <fbxsdk/fbxsdk_nsbegin.h>
00022 
00026 class FBXSDK_DLL FbxSet
00027 {
00028 public:
00036         FbxSet(int pItemPerBlock=20);
00037 
00041         FbxSet(const FbxSet& other);
00042 
00044         ~FbxSet();
00046 
00047     // Add and remove
00054     bool Add(FbxHandle pReference, FbxHandle pItem);
00055     
00060     bool Remove(FbxHandle pReference);
00061     
00066     bool RemoveItem(FbxHandle pItem);
00067 
00073     bool SetItem(FbxHandle pReference, FbxHandle pItem);
00074 
00081     FbxHandle Get(FbxHandle pReference, int* pIndex=NULL) const;
00082 
00084     void Clear();
00085 
00086     // Index manipulation
00092     FbxHandle GetFromIndex(int pIndex, FbxHandle* pReference=NULL) const;
00093 
00098     bool RemoveFromIndex(int pIndex);
00099 
00100     // Get The Count
00104     int GetCount() const { return mSetCount; }
00105 
00106     // Sorting
00111     bool Swap()const;
00112 
00113     //The array can be sorted only if the private member:mIsChanged be true.
00117     bool Sort()const;
00118 
00120     const FbxSet& operator=(const FbxSet&);
00121 
00122 /*****************************************************************************************************************************
00123 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
00124 *****************************************************************************************************************************/
00125 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00126     struct SSet;
00127 
00128 private:
00129     // internal functions for Sets manipulation
00130     SSet* FindEqual(FbxHandle pReference) const;
00131 
00132 private:
00133     SSet*           mSetArray;
00134     int             mSetCount;
00135     int             mBlockCount;
00136     int             mItemPerBlock;
00137     mutable bool    mIsChanged;
00138 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
00139 };
00140 
00143 template <typename Type, typename Compare=FbxLessCompare<Type>, typename Allocator=FbxBaseAllocator> class FbxSet2
00144 {
00145 protected:
00147     class Value
00148     {
00149     /*****************************************************************************************************************************
00150     ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
00151     *****************************************************************************************************************************/
00152     #ifndef DOXYGEN_SHOULD_SKIP_THIS
00153     public:
00154         typedef const Type KeyType;
00155         typedef const Type ConstKeyType;
00156         typedef const Type ValueType;
00157         typedef const Type ConstValueType;
00158 
00159         inline Value(const Type& pValue) : mValue(pValue){}
00160         inline KeyType& GetKey() const { return mValue; }
00161         inline ConstKeyType& GetKey(){ return mValue; }
00162         inline ValueType& GetValue() const { return mValue; }
00163         inline ConstValueType& GetValue(){ return mValue; }
00164 
00165     protected:
00166         ValueType mValue;
00167 
00168     private:
00169         Value& operator=(const Value&);
00170     #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
00171     };
00172 
00174     typedef FbxRedBlackTree<Value, Compare, Allocator> StorageType;
00175 
00176 public:
00177     typedef Type ValueType;
00178     typedef typename StorageType::RecordType        RecordType;
00179     typedef typename StorageType::IteratorType      Iterator;
00180     typedef typename StorageType::ConstIteratorType ConstIterator;
00181 
00185     inline void Reserve(unsigned int pRecordCount)
00186     {
00187         mTree.Reserve(pRecordCount);
00188     }
00189 
00191     inline int GetSize() const
00192     {
00193         return mTree.GetSize();
00194     }
00195 
00199     inline FbxPair<RecordType*, bool> Insert(const ValueType& pValue)
00200     {
00201         return mTree.Insert(Value(pValue));
00202     }
00203 
00207     inline int Remove(const ValueType& pValue)
00208     {
00209         return mTree.Remove(pValue);
00210     }
00211 
00213     inline void Clear()
00214     {
00215         mTree.Clear();
00216     }
00217 
00219     inline bool Empty() const
00220     {
00221         return mTree.Empty();
00222     }
00223 
00225     Iterator Begin()
00226     {
00227         return Iterator(Minimum());
00228     }
00229 
00231     Iterator End()
00232     {
00233         return Iterator();
00234     }
00235 
00237     ConstIterator Begin() const
00238     {
00239         return ConstIterator(Minimum());
00240     }
00241 
00243     ConstIterator End() const
00244     {
00245         return ConstIterator();
00246     }
00247 
00251     inline const RecordType* Find(const ValueType& pValue) const
00252     {
00253         return mTree.Find(pValue);
00254     }
00255 
00259     inline RecordType* Find(const ValueType& pValue)
00260     {
00261         return mTree.Find(pValue);
00262     }
00263 
00265     inline const RecordType* Minimum() const
00266     {
00267         return mTree.Minimum();
00268     }
00269 
00271     inline RecordType* Minimum()
00272     {
00273         return mTree.Minimum();
00274     }
00275 
00277     inline const RecordType* Maximum() const
00278     {
00279         return mTree.Maximum();
00280     }
00281 
00283     inline RecordType* Maximum()
00284     {
00285         return mTree.Maximum();
00286     }
00287 
00289     inline bool operator==(const FbxSet2<Type, Compare, Allocator>& pOther) const
00290     {
00291         return (this == &pOther) || (mTree == pOther.mTree);
00292     }
00293 
00295     inline bool operator != (const FbxSet2<Type, Compare, Allocator>& pOther) const
00296     {
00297         return !(*this == pOther);
00298     }
00299 
00303     inline FbxSet2 Intersect(const FbxSet2& pOther) const
00304     {
00305         FbxSet2 lReturn;
00306         ConstIterator lBegin = Begin();
00307         for (; lBegin != End(); ++lBegin)
00308         {
00309             if (pOther.Find(lBegin->GetValue()) != NULL)
00310                 lReturn.Insert(lBegin->GetValue());
00311         }
00312         return lReturn;
00313     }
00314 
00318     inline FbxSet2 Union(const FbxSet2& pOther) const
00319     {
00320         FbxSet2 lReturn(*this);
00321         ConstIterator lBegin = pOther.Begin();
00322         for (; lBegin != End(); ++lBegin)
00323         {
00324             if (Find(lBegin->GetValue()) == NULL)
00325                 lReturn.Insert(lBegin->GetValue());
00326         }
00327         return lReturn;
00328     }
00329 
00330 /*****************************************************************************************************************************
00331 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
00332 *****************************************************************************************************************************/
00333 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00334     inline FbxSet2(){}
00335     inline FbxSet2(const FbxSet2& pSet) : mTree(pSet.mTree){}
00336     inline ~FbxSet2(){ Clear(); }
00337 
00338 private:
00339     StorageType mTree;
00340 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
00341 };
00342 
00343 #include <fbxsdk/fbxsdk_nsend.h>
00344 
00345 #endif /* _FBXSDK_CORE_BASE_SET_H_ */