- Main Page
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# fbxstringlist.h

Go to the documentation of this file.

    00001 /****************************************************************************************
    00002
    00003    Copyright (C) 2012 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[pIndex]); mList.RemoveAt( pIndex );
    00281     }
    00282
    00284     virtual void Clear()
    00285     {
    00286         for (int Count=0; Count<mList.GetCount(); Count++ ) {
    00287             FbxDelete(mList[Count]);
    00288         }
    00289         mList.Clear();
    00290     }
    00291
    00295    virtual void GetText(FbxString& pText) const
    00296     {
    00297         int lCount;
    00298         for (lCount=0; lCount<mList.GetCount(); lCount++)
    00299         {
    00300             pText += mList[lCount]->mString;
    00301             if (lCount<mList.GetCount()-1)
    00302             {
    00303                 pText += "~";
    00304             }
    00305         }
    00306     }
    00307
    00314     virtual int SetText(const char* pList)
    00315     {
    00316     int     lPos=0, lOldPos = 0;
    00317     int     lLastIndex=0;
    00318     FbxString   lName=pList;
    00319
    00320         Clear();
    00321         for (lPos=0; lName.Buffer()[lPos]!=0; lPos++) {
    00322             if (lName.Buffer()[lPos]=='~') {
    00323                 lName.Buffer()[lPos]=0;
    00324                 lLastIndex = Add(lName.Buffer()+lOldPos);
    00325                 lOldPos=lPos+1;
    00326             }
    00327         }
    00328
    00329         if(lOldPos != lPos)
    00330         {
    00331             lLastIndex = Add(lName.Buffer()+lOldPos);
    00332         }
    00333         return lLastIndex;
    00334     }
    00335
    00336
    00337 };
    00338
    00341 class FBXSDK_DLL FbxStringList : public FbxStringListT<FbxStringListItem>
    00342 {
    00343 public:
    00348
    00349         FbxStringList();
    00350
    00352         FbxStringList( const FbxStringList& pOriginal );
    00354
    00359
    00360         void CopyFrom( const FbxStringList* pOriginal  );
    00361
    00363         FbxStringList& operator=(const FbxStringList& pOriginal);
    00365 };
    00366
    00367 #include <fbxsdk/fbxsdk_nsend.h>
    00368
    00369 #endif /* _FBXSDK_CORE_BASE_STRING_LIST_H_ */