FBX SDK Reference Guide: kstringlist.h Source File
Go to the documentation of this file.
00001 
00004 #ifndef _FBXSDK_KSTRING_LIST_H_
00005 #define _FBXSDK_KSTRING_LIST_H_
00006 
00007 /**************************************************************************************
00008 
00009  Copyright ?2001 - 2008 Autodesk, Inc. and/or its licensors.
00010  All Rights Reserved.
00011 
00012  The coded instructions, statements, computer programs, and/or related material 
00013  (collectively the "Data") in these files contain unpublished information 
00014  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00015  Canada and United States of America federal copyright law and by international 
00016  treaties. 
00017  
00018  The Data may not be disclosed or distributed to third parties, in whole or in
00019  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00020 
00021  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00022  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00023  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00024  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00025  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00026  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00027  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00028  
00029  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00030  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00031  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00032  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00033  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00034  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00035  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00036  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00037  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00038  OR DAMAGE. 
00039 
00040 **************************************************************************************/
00041 #include <kbaselib_h.h>
00042 
00043 #include <stdlib.h> 
00044 
00045 #if defined(KARCH_ENV_MACOSX_CFM)
00046 #include <extras.h>
00047 #endif
00048 
00049 
00050 #include <klib/karrayul.h>
00051 
00052 #include <isocpp_conformant.h> // RR: for new deprecated functions introduced by VC++ 2005
00053 // We include the file here because we want to make sure that the symbols we have re-defined
00054 // in isocpp_conformat.h correctly overwrite the respective functions.
00055 
00056 #include <klib/t-str.h>
00057 #include <klib/kstring.h>
00058 #include <kbaselib_nsbegin.h>
00059 
00060     class KBASELIB_DLL KStringListItem {
00061     public:
00062         KString     mString; 
00063         kReference  mReference;
00064         KStringListItem( ) { mReference = 0;} 
00065         KStringListItem( const char* pString, kReference pRef=0 ) { mString = pString; mReference = pRef;} 
00066     };
00067 
00068     inline int CompareKStringListSort(const void *E1,const void *E2)
00069     {
00070         return t_stricmp((*(KStringListItem **)E1)->mString.Buffer(),(*(KStringListItem **)E2)->mString.Buffer());
00071     }
00072 
00073     inline int CompareKStringListFindEqual(const void *E1,const void *E2)
00074     {
00075         return t_stricmp((*(KStringListItem *)E1).mString.Buffer(),(*(KStringListItem **)E2)->mString.Buffer());
00076     }
00077 
00078     inline int CompareCaseSensitiveKStringList(const void *E1,const void *E2)
00079     {
00080         return strcmp((*(KStringListItem *)E1).mString.Buffer() ,(*(KStringListItem **)E2)->mString.Buffer());
00081     }
00082 
00083     typedef class KArrayTemplate<KStringListItem *> KArrayStringListItem;
00084 
00085      
00086     template <class Type> class KStringListTemplate {
00087     protected:
00088         KArrayTemplate<Type *> mList;
00089 
00090     public:
00095 
00099         int     AddItem( Type *pItem )      { return mList.Add( pItem ); }
00100 
00107         int     InsertItemAt( int pIndex, Type *pItem ) { return mList.InsertAt( pIndex, pItem ); }
00108 
00110         Type   *GetItemAt( int pIndex )     { return mList[pIndex]; }
00111 
00115         int     FindItem( Type *pItem )     { return mList.Find( pItem ); }
00116         //}@
00117 
00118     public : 
00123 
00125         KStringListTemplate()
00126         {
00127         }
00128 
00130         virtual ~KStringListTemplate() { Clear(); }
00131         //}@
00132 
00134         void RemoveLast() { RemoveAt( mList.GetCount()-1 ); }
00135 
00139         inline int      GetCount() { return mList.GetCount(); }
00140 
00142         KString   &operator[](int pIndex) { return mList[pIndex]->mString; }
00143 
00145         kReference      GetReferenceAt(int pIndex) { return mList[pIndex]->mReference; }
00146 
00148         void            SetReferenceAt(int pIndex, kReference pRef) { mList[pIndex]->mReference = pRef; }
00149 
00151         char*       GetStringAt(int pIndex) { if (pIndex<mList.GetCount()) return mList[pIndex]->mString.Buffer(); else return NULL; }
00152         
00154         virtual bool    SetStringAt(int pIndex,char* pString) 
00155         { 
00156             if (pIndex<mList.GetCount()) 
00157             {
00158                 mList[pIndex]->mString = pString; 
00159                 return true;
00160             } else return false; 
00161         }
00162        
00167         int Find( Type &pItem ) 
00168         { 
00169             for (int Count=0; Count<mList.GetCount(); Count++) {
00170                 if (mList[Count]==&pItem) {
00171                     return Count;
00172                 }
00173             }
00174             return -1;
00175         }
00176 
00181         int FindIndex( kReference pReference ) 
00182         { 
00183             for (int Count=0; Count<mList.GetCount(); Count++) {
00184                 if (mList[Count]->mReference==pReference) {
00185                     return Count;
00186                 }
00187             }
00188             return -1;
00189         }
00190 
00195         int FindIndex( const char* pString ) 
00196         { 
00197             for (int Count=0; Count<mList.GetCount(); Count++) {
00198                 if (mList[Count]->mString==pString) {
00199                     return Count;
00200                 }
00201             }
00202             return -1;
00203         }
00204 
00210         kReference FindReference( char* pString )
00211         {
00212         int Index = FindIndex( pString );
00213             if (Index!=-1) {
00214                 return mList[Index]->mReference;
00215             }
00216             return 0; // NULL
00217         }
00218 
00220         bool Remove ( Type &pItem )
00221         {
00222         int Index = Find( pItem );
00223             if (Index>=0) {
00224                 RemoveAt( Index );
00225                 return true;
00226             }
00227             return false;
00228         }
00229 
00231         bool Remove ( char* pString )
00232         {
00233         int Index = FindIndex( pString );
00234             if (Index>=0) {
00235                 RemoveAt( Index );
00236                 return true;
00237             }
00238             return false;
00239         }
00240 
00242         bool RemoveIt ( Type &pItem )
00243         {
00244         int Index = Find( pItem );
00245             if (Index>=0) {
00246                 RemoveAt( Index );
00247                 return true;
00248             }
00249             return false;
00250         }
00251 
00253         void Sort( )
00254         {
00255             qsort( &(mList.GetArray()[0]),mList.GetCount(),sizeof(KStringListItem *),CompareKStringListSort );
00256         }
00257 
00262         void* FindEqual( char* pString)
00263         {
00264         KStringListItem Key(pString);  
00265         
00266             if (mList.GetCount() != 0)
00267             {
00268                 return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(KStringListItem *),CompareKStringListFindEqual );
00269             }
00270             else
00271             {
00272                 return NULL ;
00273             }
00274         }
00275 
00280         void* FindCaseSensitive(char * pString)
00281         {
00282         KStringListItem Key(pString);  
00283         
00284             if (mList.GetCount() != 0)
00285             {
00286                 return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(KStringListItem *), CompareCaseSensitiveKStringList);
00287             }
00288             else
00289             {
00290                 return NULL ;
00291             }
00292         
00293         }
00294 
00295 
00297         int Add( char* pString, kReference pItem=0 ) 
00298         { 
00299             return InsertAt( mList.GetCount(),pString,pItem ); 
00300         }
00301 
00302         virtual int InsertAt( int pIndex, char* pString, kReference pItem=0 ) 
00303         { 
00304             return mList.InsertAt( pIndex,new Type( pString,(kReference)pItem )); 
00305         }
00306 
00313         virtual void RemoveAt( int pIndex ) 
00314         { 
00315             delete mList[pIndex]; mList.RemoveAt( pIndex ); 
00316         }
00317 
00319         virtual void Clear()
00320         {
00321             for (int Count=0; Count<mList.GetCount(); Count++ ) {
00322                 delete mList[Count];
00323             }
00324             mList.Clear();
00325         }
00326 
00330        virtual void GetText(KString& pText)
00331         {
00332             int     Count;
00333             for (Count=0; Count<mList.GetCount(); Count++) 
00334             {
00335                 pText += mList[Count]->mString;
00336                 if (Count<mList.GetCount()-1) 
00337                 {
00338                    // HACK: Fix this
00339                   #ifdef K_UNICODE
00340                     pText += _T("~");
00341                   #else
00342                     pText += "~";
00343                   #endif
00344                    //------- END HACK
00345                 }
00346             }
00347         }
00348 
00355         virtual int SetText(char* pList)
00356         {
00357         int     Pos=0, OldPos = 0;
00358         int     LastIndex=0;
00359         KString Name=pList;
00360 
00361             Clear();
00362             for (Pos=0; Name.Buffer()[Pos]!=0; Pos++) {
00363                 if (Name.Buffer()[Pos]==_T('~')) {
00364                     Name.Buffer()[Pos]=0;
00365                     LastIndex = Add(Name.Buffer()+OldPos);
00366                     OldPos=Pos+1;
00367                 }
00368             }
00369 
00370             if(OldPos != Pos)
00371             {
00372                 LastIndex = Add(Name.Buffer()+OldPos);
00373             }
00374             return LastIndex;
00375         } 
00376 
00377 
00378     };
00379 
00380     typedef class KBASELIB_DLL KStringListTemplate< KStringListItem > KStringListTemplateItem;
00381 
00382     class KBASELIB_DLL KStringList : public KStringListTemplate< KStringListItem >
00383     {
00384     public : 
00389 
00391         KStringList(); 
00392 
00394         KStringList( const KStringList &pOriginal );
00396 
00401 
00403         void CopyFrom( const KStringList *pOriginal  );
00404         
00406         KStringList& operator=(const KStringList& pOriginal);
00408     };
00409       
00410 
00411     typedef KStringList *HKStringList;
00412 
00413 #include <kbaselib_nsend.h>
00414 
00415 #endif