fbxsdk/core/base/fbxstringlist.h Source File

fbxstringlist.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2015 Autodesk, Inc.
4  All rights reserved.
5 
6  Use of this software is subject to the terms of the Autodesk license agreement
7  provided at the time of installation or download, or which otherwise accompanies
8  this software in either electronic or hard copy form.
9 
10 ****************************************************************************************/
11 
13 #ifndef _FBXSDK_CORE_BASE_STRING_LIST_H_
14 #define _FBXSDK_CORE_BASE_STRING_LIST_H_
15 
16 #include <fbxsdk/fbxsdk_def.h>
17 
20 
21 #include <fbxsdk/fbxsdk_nsbegin.h>
22 
25 {
26 public:
28  FbxStringListItem(const char* pString, FbxHandle pRef=0){ mString = pString; mReference = pRef; }
29 
31  FbxHandle mReference;
32 };
33 
34 inline int FbxCompareStringListSort(const void* E1, const void* E2)
35 {
36  return FBXSDK_stricmp((*(FbxStringListItem**)E1)->mString.Buffer(), (*(FbxStringListItem**)E2)->mString.Buffer());
37 }
38 
39 inline int FbxCompareStringListFindEqual(const void* E1, const void* E2)
40 {
41  return FBXSDK_stricmp((*(FbxStringListItem*)E1).mString.Buffer(), (*(FbxStringListItem**)E2)->mString.Buffer());
42 }
43 
44 inline int FbxCompareCaseSensitiveStringList(const void *E1,const void *E2)
45 {
46  return strcmp((*(FbxStringListItem*)E1).mString.Buffer(), (*(FbxStringListItem**)E2)->mString.Buffer());
47 }
48 
50 template <class Type> class FbxStringListT
51 {
52 protected:
54 
55 public:
60 
64  int AddItem( Type* pItem ) { return mList.Add( pItem ); }
65 
72  int InsertItemAt( int pIndex, Type* pItem ) { return mList.InsertAt( pIndex, pItem ); }
73 
75  Type* GetItemAt( int pIndex ) const { return mList[pIndex]; }
76 
80  int FindItem( Type* pItem ) const { return mList.Find( pItem ); }
81  //}@
82 
83 public :
88 
91  {
92  }
93 
95  virtual ~FbxStringListT() { Clear(); }
96  //}@
97 
99  void RemoveLast() { RemoveAt( mList.GetCount()-1 ); }
100 
104  inline int GetCount() const { return mList.GetCount(); }
105 
107  FbxString& operator[](int pIndex) { return mList[pIndex]->mString; }
108 
110  FbxHandle GetReferenceAt(int pIndex) const { return mList[pIndex]->mReference; }
111 
113  void SetReferenceAt(int pIndex, FbxHandle pRef) { mList[pIndex]->mReference = pRef; }
114 
116  char* GetStringAt(int pIndex) const { if (pIndex<mList.GetCount()) return mList[pIndex]->mString.Buffer(); else return NULL; }
117 
119  virtual bool SetStringAt(int pIndex, const char* pString)
120  {
121  if (pIndex<mList.GetCount())
122  {
123  mList[pIndex]->mString = pString;
124  return true;
125  } else return false;
126  }
127 
132  int Find( Type& pItem ) const
133  {
134  for (int Count=0; Count<mList.GetCount(); Count++) {
135  if (mList[Count]==&pItem) {
136  return Count;
137  }
138  }
139  return -1;
140  }
141 
146  int FindIndex( FbxHandle pReference ) const
147  {
148  for (int Count=0; Count<mList.GetCount(); Count++) {
149  if (mList[Count]->mReference==pReference) {
150  return Count;
151  }
152  }
153  return -1;
154  }
155 
160  int FindIndex( const char* pString ) const
161  {
162  for (int lCount=0; lCount<mList.GetCount(); lCount++) {
163  if (mList[lCount]->mString==pString) {
164  return lCount;
165  }
166  }
167  return -1;
168  }
169 
175  FbxHandle FindReference(const char* pString ) const
176  {
177  int lIndex = FindIndex( pString );
178  if (lIndex!=-1) {
179  return mList[lIndex]->mReference;
180  }
181  return 0; // NULL
182  }
183 
185  bool Remove ( Type& pItem )
186  {
187  int lIndex = Find( pItem );
188  if (lIndex>=0) {
189  RemoveAt( lIndex );
190  return true;
191  }
192  return false;
193  }
194 
196  bool Remove (const char* pString )
197  {
198  int lIndex = FindIndex( pString );
199  if (lIndex>=0) {
200  RemoveAt( lIndex );
201  return true;
202  }
203  return false;
204  }
205 
207  bool RemoveIt ( Type& pItem )
208  {
209  int lIndex = Find( pItem );
210  if (lIndex>=0) {
211  RemoveAt( lIndex );
212  return true;
213  }
214  return false;
215  }
216 
218  void Sort( )
219  {
220  qsort( &(mList.GetArray()[0]),mList.GetCount(),sizeof(FbxStringListItem*),FbxCompareStringListSort );
221  }
222 
228  void* FindEqual(const char* pString) const
229  {
230  FbxStringListItem Key(pString);
231 
232  if (mList.GetCount() != 0)
233  {
234  return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(FbxStringListItem*),FbxCompareStringListFindEqual );
235  }
236  else
237  {
238  return NULL ;
239  }
240  }
241 
247  void* FindCaseSensitive(const char* pString) const
248  {
249  FbxStringListItem Key(pString);
250 
251  if (mList.GetCount() != 0)
252  {
253  return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(FbxStringListItem*), FbxCompareCaseSensitiveStringList);
254  }
255  else
256  {
257  return NULL ;
258  }
259 
260  }
261 
262 
264  int Add( const char* pString, FbxHandle pItem=0 )
265  {
266  return InsertAt( mList.GetCount(),pString,pItem );
267  }
268 
269  virtual int InsertAt( int pIndex, const char* pString, FbxHandle pItem=0 )
270  {
271  return mList.InsertAt( pIndex,FbxNew< Type >( pString,(FbxHandle)pItem ));
272  }
273 
280  virtual void RemoveAt(int pIndex)
281  {
282  FbxDelete(mList.RemoveAt(pIndex));
283  }
284 
286  virtual void Clear()
287  {
288  FbxArrayDelete(mList);
289  }
290 
294  virtual void GetText(FbxString& pText) const
295  {
296  int lCount;
297  for (lCount=0; lCount<mList.GetCount(); lCount++)
298  {
299  pText += mList[lCount]->mString;
300  if (lCount<mList.GetCount()-1)
301  {
302  pText += "~";
303  }
304  }
305  }
306 
313  virtual int SetText(const char* pList)
314  {
315  int lPos=0, lOldPos = 0;
316  int lLastIndex=0;
317  FbxString lName=pList;
318 
319  Clear();
320  for (lPos=0; lName.Buffer()[lPos]!=0; lPos++) {
321  if (lName.Buffer()[lPos]=='~') {
322  lName.Buffer()[lPos]=0;
323  lLastIndex = Add(lName.Buffer()+lOldPos);
324  lOldPos=lPos+1;
325  }
326  }
327 
328  if(lOldPos != lPos)
329  {
330  lLastIndex = Add(lName.Buffer()+lOldPos);
331  }
332  return lLastIndex;
333  }
334 
335 
336 };
337 
340 class FBXSDK_DLL FbxStringList : public FbxStringListT<FbxStringListItem>
341 {
342 public:
347  FbxStringList();
349 
351  FbxStringList( const FbxStringList& pOriginal );
353 
358  void CopyFrom( const FbxStringList* pOriginal );
360 
362  FbxStringList& operator=(const FbxStringList& pOriginal);
364 };
365 
366 #include <fbxsdk/fbxsdk_nsend.h>
367 
368 #endif /* _FBXSDK_CORE_BASE_STRING_LIST_H_ */
virtual void RemoveAt(int pIndex)
Remove the item at the given position in the array and delete the associated object.
FbxHandle FindReference(const char *pString) const
Access the value of reference of the first matching item in array whose string address is the same as...
void * FindEqual(const char *pString) const
Find first matching item which has the same string as given parameter,not case sensitive.
FBX SDK environment definition.
virtual int SetText(const char *pList)
Clear the array and set the array's new items with the substring separated by '~' from the given stri...
void FbxArrayDelete(FbxArray< T > &pArray)
Call FbxDelete on each element of the array, and then clear it.
Definition: fbxarray.h:463
FbxHandle GetReferenceAt(int pIndex) const
Access the value of reference in the item at given index.
virtual void Clear()
Delete the array.
FbxString & operator[](int pIndex)
Access the string in the item at given index.
#define NULL
Definition: fbxarch.h:210
Array that stores pairs of FbxString and a pointer.
int FindIndex(FbxHandle pReference) const
Find first matching item which has the same reference as given parameter.
Utility class to manipulate strings.
Definition: fbxstring.h:66
T RemoveAt(const int pIndex)
Remove an element at the given position in the array.
Definition: fbxarray.h:239
virtual bool SetStringAt(int pIndex, const char *pString)
Set string at given index.
int FindIndex(const char *pString) const
Find first matching item in array whose string address is the same as given pointer.
void RemoveLast()
Remove the item at the end of the array and delete the associated object.
Definition: fbxstringlist.h:99
FbxHandle mReference
Definition: fbxstringlist.h:31
void FbxDelete(T *p)
Deletion policy for pointer template classes that uses the FbxDelete() function.
Definition: fbxnew.h:341
FbxArray< Type * > mList
Definition: fbxstringlist.h:53
virtual ~FbxStringListT()
Destructor.
Definition: fbxstringlist.h:95
int FindItem(Type *pItem) const
Find first matching item.
Definition: fbxstringlist.h:80
int FbxCompareStringListSort(const void *E1, const void *E2)
Definition: fbxstringlist.h:34
int FbxCompareCaseSensitiveStringList(const void *E1, const void *E2)
Definition: fbxstringlist.h:44
int Add(const T &pElement)
Append an element at the end of the array, doubling the array if capacity is not sufficient.
Definition: fbxarray.h:83
FbxStringListItem(const char *pString, FbxHandle pRef=0)
Definition: fbxstringlist.h:28
virtual int InsertAt(int pIndex, const char *pString, FbxHandle pItem=0)
void * FindCaseSensitive(const char *pString) const
Find first matching item which has the same string as given parameter, case sensitive.
int FbxCompareStringListFindEqual(const void *E1, const void *E2)
Definition: fbxstringlist.h:39
FbxStringListT()
Default constructor.
Definition: fbxstringlist.h:90
int GetCount() const
Get number of items in the array.
int Find(Type &pItem) const
Find first matching item.
char * Buffer()
Non-const buffer access.
int AddItem(Type *pItem)
Append a item at the end of the array.
Definition: fbxstringlist.h:64
int InsertItemAt(int pIndex, Type *pItem)
Insert a item in the array.
Definition: fbxstringlist.h:72
T * GetArray() const
Get pointer to internal array of elements.
Definition: fbxarray.h:369
Wraps a string (FbxString) and a pointer (FbxHandle).
Definition: fbxstringlist.h:24
char * GetStringAt(int pIndex) const
Access the pointer of string at given index.
Type * GetItemAt(int pIndex) const
Access item at given index.
Definition: fbxstringlist.h:75
bool RemoveIt(Type &pItem)
Remove first matching item.
#define FBXSDK_DLL
Definition: fbxarch.h:173
virtual void GetText(FbxString &pText) const
Get the string of all the item.
bool Remove(const char *pString)
Remove first matching item in array whose string address is the same as given pointer.
Base class of FbxStringList.
Definition: fbxstringlist.h:50
int InsertAt(const int pIndex, const T &pElement, bool pCompact=false)
Insert an element at the given position, growing the array if capacity is not sufficient.
Definition: fbxarray.h:48
void Sort()
Sort the array by the string of every item,not case sensitive.
int Add(const char *pString, FbxHandle pItem=0)
Add a new item at the end of array.
bool Remove(Type &pItem)
Remove first matching item.
void SetReferenceAt(int pIndex, FbxHandle pRef)
Set the value of reference at given index.
int Find(const T &pElement, const int pStartIndex=0) const
Find first matching element, from first to last.
Definition: fbxarray.h:164