- Main Page
- Classes
- Files
- Directories

- File List
- File Members

# fbxstringlist.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_STRING_LIST_H_
    00014 #define _FBXSDK_CORE_BASE_STRING_LIST_H_
    00015
    00016 #include <fbxsdk/fbxsdk_def.h>
    00017
    00018 #include <fbxsdk/core/base/fbxarray.h>
    00019 #include <fbxsdk/core/base/fbxstring.h>
    00020
    00021 #include <fbxsdk/fbxsdk_nsbegin.h>
    00022
    00024 class FbxStringListItem
    00025 {
    00026 public:
    00027     FbxStringListItem(){ mReference = 0; }
    00028     FbxStringListItem(const char* pString, FbxHandle pRef=0){ mString = pString; mReference = pRef; }
    00029
    00030     FbxString   mString;
    00031     FbxHandle       mReference;
    00032 };
    00033
    00034 inline int FbxCompareStringListSort(const void* E1, const void* E2)
    00035 {
    00036     return FBXSDK_stricmp((*(FbxStringListItem**)E1)->mString.Buffer(), (*(FbxStringListItem**)E2)->mString.Buffer());
    00037 }
    00038
    00039 inline int FbxCompareStringListFindEqual(const void* E1, const void* E2)
    00040 {
    00041     return FBXSDK_stricmp((*(FbxStringListItem*)E1).mString.Buffer(), (*(FbxStringListItem**)E2)->mString.Buffer());
    00042 }
    00043
    00044 inline int FbxCompareCaseSensitiveStringList(const void *E1,const void *E2)
    00045 {
    00046     return strcmp((*(FbxStringListItem*)E1).mString.Buffer(), (*(FbxStringListItem**)E2)->mString.Buffer());
    00047 }
    00048
    00050 template <class Type> class FbxStringListT
    00051 {
    00052 protected:
    00053     FbxArray<Type*> mList;
    00054
    00055 public:
    00060
    00064     int     AddItem( Type* pItem )      { return mList.Add( pItem ); }
    00065
    00072     int     InsertItemAt( int pIndex, Type* pItem ) { return mList.InsertAt( pIndex, pItem ); }
    00073
    00075     Type*   GetItemAt( int pIndex ) const   { return mList[pIndex]; }
    00076
    00080     int     FindItem( Type* pItem ) const   { return mList.Find( pItem ); }
    00081     //}@
    00082
    00083 public :
    00088
    00090     FbxStringListT()
    00091     {
    00092     }
    00093
    00095     virtual ~FbxStringListT() { Clear(); }
    00096     //}@
    00097
    00099     void RemoveLast() { RemoveAt( mList.GetCount()-1 ); }
    00100
    00104     inline int      GetCount() const { return mList.GetCount(); }
    00105
    00107     FbxString&   operator[](int pIndex) { return mList[pIndex]->mString; }
    00108
    00110     FbxHandle       GetReferenceAt(int pIndex) const { return mList[pIndex]->mReference; }
    00111
    00113     void            SetReferenceAt(int pIndex, FbxHandle pRef) { mList[pIndex]->mReference = pRef; }
    00114
    00116     char*       GetStringAt(int pIndex) const { if (pIndex<mList.GetCount()) return mList[pIndex]->mString.Buffer(); else return NULL; }
    00117
    00119     virtual bool    SetStringAt(int pIndex, const char* pString)
    00120     {
    00121         if (pIndex<mList.GetCount())
    00122         {
    00123             mList[pIndex]->mString = pString;
    00124             return true;
    00125         } else return false;
    00126     }
    00127
    00132     int Find( Type& pItem ) const
    00133     {
    00134         for (int Count=0; Count<mList.GetCount(); Count++) {
    00135             if (mList[Count]==&pItem) {
    00136                 return Count;
    00137             }
    00138         }
    00139         return -1;
    00140     }
    00141
    00146     int FindIndex( FbxHandle pReference ) const
    00147     {
    00148         for (int Count=0; Count<mList.GetCount(); Count++) {
    00149             if (mList[Count]->mReference==pReference) {
    00150                 return Count;
    00151             }
    00152         }
    00153         return -1;
    00154     }
    00155
    00160     int FindIndex( const char* pString ) const
    00161     {
    00162         for (int lCount=0; lCount<mList.GetCount(); lCount++) {
    00163             if (mList[lCount]->mString==pString) {
    00164                 return lCount;
    00165             }
    00166         }
    00167         return -1;
    00168     }
    00169
    00175     FbxHandle FindReference(const char* pString ) const
    00176     {
    00177     int lIndex = FindIndex( pString );
    00178         if (lIndex!=-1) {
    00179             return mList[lIndex]->mReference;
    00180         }
    00181         return 0; // NULL
    00182     }
    00183
    00185     bool Remove ( Type& pItem )
    00186     {
    00187     int lIndex = Find( pItem );
    00188         if (lIndex>=0) {
    00189             RemoveAt( lIndex );
    00190             return true;
    00191         }
    00192         return false;
    00193     }
    00194
    00196     bool Remove (const char* pString )
    00197     {
    00198     int lIndex = FindIndex( pString );
    00199         if (lIndex>=0) {
    00200             RemoveAt( lIndex );
    00201             return true;
    00202         }
    00203         return false;
    00204     }
    00205
    00207     bool RemoveIt ( Type& pItem )
    00208     {
    00209     int lIndex = Find( pItem );
    00210         if (lIndex>=0) {
    00211             RemoveAt( lIndex );
    00212             return true;
    00213         }
    00214         return false;
    00215     }
    00216
    00218     void Sort( )
    00219     {
    00220         qsort( &(mList.GetArray()[0]),mList.GetCount(),sizeof(FbxStringListItem*),FbxCompareStringListSort );
    00221     }
    00222
    00227     void* FindEqual(const char* pString) const
    00228     {
    00229     FbxStringListItem Key(pString);
    00230
    00231         if (mList.GetCount() != 0)
    00232         {
    00233             return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(FbxStringListItem*),FbxCompareStringListFindEqual );
    00234         }
    00235         else
    00236         {
    00237             return NULL ;
    00238         }
    00239     }
    00240
    00245     void* FindCaseSensitive(const char* pString) const
    00246     {
    00247     FbxStringListItem Key(pString);
    00248
    00249         if (mList.GetCount() != 0)
    00250         {
    00251             return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(FbxStringListItem*), FbxCompareCaseSensitiveStringList);
    00252         }
    00253         else
    00254         {
    00255             return NULL ;
    00256         }
    00257
    00258     }
    00259
    00260
    00262     int Add( const char* pString, FbxHandle pItem=0 )
    00263     {
    00264         return InsertAt( mList.GetCount(),pString,pItem );
    00265     }
    00266
    00267     virtual int InsertAt( int pIndex, const char* pString, FbxHandle pItem=0 )
    00268     {
    00269         return mList.InsertAt( pIndex,FbxNew< Type >( pString,(FbxHandle)pItem ));
    00270     }
    00271
    00278     virtual void RemoveAt(int pIndex)
    00279     {
    00280         FbxDelete(mList.RemoveAt(pIndex));
    00281     }
    00282
    00284     virtual void Clear()
    00285     {
    00286         FbxArrayDelete(mList);
    00287     }
    00288
    00292    virtual void GetText(FbxString& pText) const
    00293     {
    00294         int lCount;
    00295         for (lCount=0; lCount<mList.GetCount(); lCount++)
    00296         {
    00297             pText += mList[lCount]->mString;
    00298             if (lCount<mList.GetCount()-1)
    00299             {
    00300                 pText += "~";
    00301             }
    00302         }
    00303     }
    00304
    00311     virtual int SetText(const char* pList)
    00312     {
    00313     int     lPos=0, lOldPos = 0;
    00314     int     lLastIndex=0;
    00315     FbxString   lName=pList;
    00316
    00317         Clear();
    00318         for (lPos=0; lName.Buffer()[lPos]!=0; lPos++) {
    00319             if (lName.Buffer()[lPos]=='~') {
    00320                 lName.Buffer()[lPos]=0;
    00321                 lLastIndex = Add(lName.Buffer()+lOldPos);
    00322                 lOldPos=lPos+1;
    00323             }
    00324         }
    00325
    00326         if(lOldPos != lPos)
    00327         {
    00328             lLastIndex = Add(lName.Buffer()+lOldPos);
    00329         }
    00330         return lLastIndex;
    00331     }
    00332
    00333
    00334 };
    00335
    00338 class FBXSDK_DLL FbxStringList : public FbxStringListT<FbxStringListItem>
    00339 {
    00340 public:
    00345
    00346         FbxStringList();
    00347
    00349         FbxStringList( const FbxStringList& pOriginal );
    00351
    00356
    00357         void CopyFrom( const FbxStringList* pOriginal  );
    00358
    00360         FbxStringList& operator=(const FbxStringList& pOriginal);
    00362 };
    00363
    00364 #include <fbxsdk/fbxsdk_nsend.h>
    00365
    00366 #endif /* _FBXSDK_CORE_BASE_STRING_LIST_H_ */