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
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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>
00046
00047
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;
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
00334 pText += "~";
00335
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