kstringlist.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KSTRINGLIST_H
00005 #define FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KSTRINGLIST_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2001 - 2010 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 <fbxfilesdk/fbxfilesdk_def.h>
00042 
00043 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00044 
00045 #include <fbxfilesdk/components/kbaselib/isocpp_conformant.h> // RR: for new deprecated functions introduced by VC++ 2005
00046 // We include the file here because we want to make sure that the symbols we have re-defined
00047 // in isocpp_conformat.h correctly overwrite the respective functions.
00048 
00049 #include <fbxfilesdk/fbxfilesdk_new.h>
00050 
00051 #include <fbxfilesdk/components/kbaselib/klib/t-str.h>
00052 #include <fbxfilesdk/components/kbaselib/klib/kstring.h>
00053 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00054 
00055     class KFBX_DLL KStringListItem {
00056     public:
00057         KString     mString; 
00058         kReference  mReference;
00059         KStringListItem( ) { mReference = 0;} 
00060         KStringListItem( const char* pString, kReference pRef=0 ) { mString = pString; mReference = pRef;} 
00061     };
00062 
00063     inline int CompareKStringListSort(const void *E1,const void *E2)
00064     {
00065         return t_stricmp((*(KStringListItem **)E1)->mString.Buffer(),(*(KStringListItem **)E2)->mString.Buffer());
00066     }
00067 
00068     inline int CompareKStringListFindEqual(const void *E1,const void *E2)
00069     {
00070         return t_stricmp((*(KStringListItem *)E1).mString.Buffer(),(*(KStringListItem **)E2)->mString.Buffer());
00071     }
00072 
00073     inline int CompareCaseSensitiveKStringList(const void *E1,const void *E2)
00074     {
00075         return strcmp((*(KStringListItem *)E1).mString.Buffer() ,(*(KStringListItem **)E2)->mString.Buffer());
00076     }
00077 
00078     typedef class KArrayTemplate<KStringListItem *> KArrayStringListItem;
00079 
00080      
00081     template <class Type> class KStringListTemplate {
00082     protected:
00083         KArrayTemplate<Type *> mList;
00084 
00085     public:
00090 
00094         int     AddItem( Type *pItem )      { return mList.Add( pItem ); }
00095 
00102         int     InsertItemAt( int pIndex, Type *pItem ) { return mList.InsertAt( pIndex, pItem ); }
00103 
00105         Type   *GetItemAt( int pIndex ) const   { return mList[pIndex]; }
00106 
00110         int     FindItem( Type *pItem ) const   { return mList.Find( pItem ); }
00111         //}@
00112 
00113     public : 
00118 
00120         KStringListTemplate()
00121         {
00122         }
00123 
00125         virtual ~KStringListTemplate() { Clear(); }
00126         //}@
00127 
00129         void RemoveLast() { RemoveAt( mList.GetCount()-1 ); }
00130 
00134         inline int      GetCount() const { return mList.GetCount(); }
00135 
00137         KString   &operator[](int pIndex) { return mList[pIndex]->mString; }
00138 
00140         kReference      GetReferenceAt(int pIndex) const { return mList[pIndex]->mReference; }
00141 
00143         void            SetReferenceAt(int pIndex, kReference pRef) { mList[pIndex]->mReference = pRef; }
00144 
00146         char*       GetStringAt(int pIndex) const { if (pIndex<mList.GetCount()) return mList[pIndex]->mString.Buffer(); else return NULL; }
00147         
00149         virtual bool    SetStringAt(int pIndex, const char* pString) 
00150         { 
00151             if (pIndex<mList.GetCount()) 
00152             {
00153                 mList[pIndex]->mString = pString; 
00154                 return true;
00155             } else return false; 
00156         }
00157        
00162         int Find( Type &pItem ) const
00163         { 
00164             for (int Count=0; Count<mList.GetCount(); Count++) {
00165                 if (mList[Count]==&pItem) {
00166                     return Count;
00167                 }
00168             }
00169             return -1;
00170         }
00171 
00176         int FindIndex( kReference pReference ) const
00177         { 
00178             for (int Count=0; Count<mList.GetCount(); Count++) {
00179                 if (mList[Count]->mReference==pReference) {
00180                     return Count;
00181                 }
00182             }
00183             return -1;
00184         }
00185 
00190         int FindIndex( const char* pString ) const
00191         { 
00192             for (int Count=0; Count<mList.GetCount(); Count++) {
00193                 if (mList[Count]->mString==pString) {
00194                     return Count;
00195                 }
00196             }
00197             return -1;
00198         }
00199 
00205         kReference FindReference(const char* pString ) const
00206         {
00207         int Index = FindIndex( pString );
00208             if (Index!=-1) {
00209                 return mList[Index]->mReference;
00210             }
00211             return 0; // NULL
00212         }
00213 
00215         bool Remove ( Type &pItem )
00216         {
00217         int Index = Find( pItem );
00218             if (Index>=0) {
00219                 RemoveAt( Index );
00220                 return true;
00221             }
00222             return false;
00223         }
00224 
00226         bool Remove (const char* pString )
00227         {
00228         int Index = FindIndex( pString );
00229             if (Index>=0) {
00230                 RemoveAt( Index );
00231                 return true;
00232             }
00233             return false;
00234         }
00235 
00237         bool RemoveIt ( Type &pItem )
00238         {
00239         int Index = Find( pItem );
00240             if (Index>=0) {
00241                 RemoveAt( Index );
00242                 return true;
00243             }
00244             return false;
00245         }
00246 
00248         void Sort( )
00249         {
00250             qsort( &(mList.GetArray()[0]),mList.GetCount(),sizeof(KStringListItem *),CompareKStringListSort );
00251         }
00252 
00257         void* FindEqual(const char* pString) const
00258         {
00259         KStringListItem Key(pString);  
00260         
00261             if (mList.GetCount() != 0)
00262             {
00263                 return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(KStringListItem *),CompareKStringListFindEqual );
00264             }
00265             else
00266             {
00267                 return NULL ;
00268             }
00269         }
00270 
00275         void* FindCaseSensitive(const char * pString) const
00276         {
00277         KStringListItem Key(pString);  
00278         
00279             if (mList.GetCount() != 0)
00280             {
00281                 return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(KStringListItem *), CompareCaseSensitiveKStringList);
00282             }
00283             else
00284             {
00285                 return NULL ;
00286             }
00287         
00288         }
00289 
00290 
00292         int Add( const char* pString, kReference pItem=0 ) 
00293         { 
00294             return InsertAt( mList.GetCount(),pString,pItem ); 
00295         }
00296 
00297         virtual int InsertAt( int pIndex, const char* pString, kReference pItem=0 ) 
00298         { 
00299             return mList.InsertAt( pIndex,FbxSdkNew< Type >( pString,(kReference)pItem )); 
00300         }
00301 
00308         virtual void RemoveAt( int pIndex ) 
00309         { 
00310             FbxSdkDelete(mList[pIndex]); mList.RemoveAt( pIndex ); 
00311         }
00312 
00314         virtual void Clear()
00315         {
00316             for (int Count=0; Count<mList.GetCount(); Count++ ) {
00317                 FbxSdkDelete(mList[Count]);
00318             }
00319             mList.Clear();
00320         }
00321 
00325        virtual void GetText(KString& pText) const
00326         {
00327             int     Count;
00328             for (Count=0; Count<mList.GetCount(); Count++) 
00329             {
00330                 pText += mList[Count]->mString;
00331                 if (Count<mList.GetCount()-1) 
00332                 {
00333                    // HACK: Fix this
00334                     pText += "~";
00335                    //------- END HACK
00336                 }
00337             }
00338         }
00339 
00346         virtual int SetText(const char* pList)
00347         {
00348         int     Pos=0, OldPos = 0;
00349         int     LastIndex=0;
00350         KString Name=pList;
00351 
00352             Clear();
00353             for (Pos=0; Name.Buffer()[Pos]!=0; Pos++) {
00354                 if (Name.Buffer()[Pos]==_T('~')) {
00355                     Name.Buffer()[Pos]=0;
00356                     LastIndex = Add(Name.Buffer()+OldPos);
00357                     OldPos=Pos+1;
00358                 }
00359             }
00360 
00361             if(OldPos != Pos)
00362             {
00363                 LastIndex = Add(Name.Buffer()+OldPos);
00364             }
00365             return LastIndex;
00366         } 
00367 
00368 
00369     };
00370 
00371     typedef class KFBX_DLL KStringListTemplate< KStringListItem > KStringListTemplateItem;
00372 
00373     class KFBX_DLL KStringList : public KStringListTemplate< KStringListItem >
00374     {
00375     public : 
00380 
00382         KStringList(); 
00383 
00385         KStringList( const KStringList &pOriginal );
00387 
00392 
00394         void CopyFrom( const KStringList *pOriginal  );
00395         
00397         KStringList& operator=(const KStringList& pOriginal);
00399     };
00400       
00401 
00402     typedef KStringList *HKStringList;
00403 
00404 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00405 
00406 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KSTRINGLIST_H
00407