fbxstring.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_H_
00014 #define _FBXSDK_CORE_BASE_STRING_H_
00015 
00016 #include <fbxsdk/fbxsdk_def.h>
00017 
00018 #if defined(FBXSDK_COMPILER_MSC)
00019     #if defined(FBXSDK_ARCH_32)
00020         #if _MSC_VER <= 1600
00021             #define SIZE_OF_STDSTRING 32
00022         #elif _MSC_VER == 1700
00023             #define SIZE_OF_STDSTRING 28
00024         #endif
00025     #else
00026         #if _MSC_VER <= 1600
00027             #define SIZE_OF_STDSTRING 48
00028         #elif _MSC_VER == 1700
00029             #define SIZE_OF_STDSTRING 40
00030         #endif
00031     #endif
00032 #elif defined(FBXSDK_COMPILER_GNU)
00033     #if defined(FBXSDK_ARCH_32)
00034         #define SIZE_OF_STDSTRING 4
00035     #else
00036         #define SIZE_OF_STDSTRING 8
00037     #endif
00038 #endif
00039 
00040 #if !defined(SIZE_OF_STDSTRING)
00041     #error Unsupported platform
00042 #endif
00043 
00044 #define FBXSDK_STRING_OPAQUE_OBJECT_HEADER void* mOpaqueChunk[SIZE_OF_STDSTRING/sizeof(void*)]
00045 #ifndef FBXSDK_STRING_OPAQUE_OBJECT
00046     #define FBXSDK_STRING_OPAQUE_OBJECT FBXSDK_STRING_OPAQUE_OBJECT_HEADER
00047 #endif
00048 
00049 #include <fbxsdk/fbxsdk_nsbegin.h>
00050 
00051 //Conversions between WideChar, UTF8 and ANSI
00052 
00059 FBXSDK_DLL void FbxUTF8ToWC(const char* pInUTF8, wchar_t*& pOutWideChar, size_t* pOutWideCharSize = NULL);
00060 
00067 FBXSDK_DLL void FbxWCToUTF8(const wchar_t* pInWideChar, char*& pOutUTF8, size_t* pOutUTF8Size = NULL);
00068 
00069 #if defined(FBXSDK_ENV_WIN)
00070 
00076     FBXSDK_DLL void FbxWCToAnsi(const wchar_t* pInWideChar, char*& pOutANSI, size_t* pOutANSISize = NULL);
00077 
00084     FBXSDK_DLL void FbxAnsiToWC(const char* pInANSI, wchar_t*& pOutWideChar, size_t* pOutWideCharSize = NULL);
00085 
00092     FBXSDK_DLL void FbxAnsiToUTF8(const char* pInANSI, char*& pOutUTF8, size_t* pOutUTF8Size = NULL);
00093 
00100     FBXSDK_DLL void FbxUTF8ToAnsi(const char* pInUTF8, char*& pOutANSI, size_t* pOutANSISize = NULL);
00101 #endif
00102 
00105 class FBXSDK_DLL FbxString
00106 {
00107 public:
00112 
00113         FbxString();
00114 
00117         FbxString(const FbxString& pStr);
00118 
00121         FbxString(const char* pStr);
00122 
00126         FbxString(char pChar, size_t pNbRepeat=1);
00127 
00131         FbxString(const char* pCharPtr, size_t pLength);
00132 
00135         FbxString(const int pValue);
00136 
00139         FbxString(const float pValue);
00140 
00143         FbxString(const double pValue);
00144 
00146         ~FbxString();
00147 
00149         void Destroy();
00151 
00156 
00157         size_t GetLen() const;
00158 
00160         bool IsEmpty() const;
00161 
00163         FbxString& Empty();
00164 
00168         char& operator[](int pIndex);
00169 
00173         char operator[](int pIndex) const;
00174 
00176         char* Buffer();
00177 
00179         const char* Buffer()const;
00181 
00188         const FbxString& operator=(const FbxString& pStr);
00189 
00192         const FbxString& operator=(char pChar);
00193 
00196         const FbxString& operator=(const char* pStr);
00197 
00200         const FbxString& operator=(int pValue);
00201 
00204         const FbxString& operator=(float pValue);
00205 
00208         const FbxString& operator=(double pValue);
00209 
00212         const FbxString& operator+=(const FbxString& pKStr);
00213 
00216         const FbxString& operator+=(char pChar);
00217 
00220         const FbxString& operator+=(const char* pStr);
00221 
00224         const FbxString& operator+=(int pValue);
00225 
00228         const FbxString& operator+=(float pValue);
00229 
00232         const FbxString& operator+=(double pValue);
00233 
00236         bool operator== (const FbxString& pStr) const;
00237 
00240         bool operator!= (const FbxString& pStr) const;
00241 
00244         bool operator< (const FbxString& pStr) const;
00245 
00248         bool operator<= (const FbxString& pStr) const;
00249 
00252         bool operator>= (const FbxString& pStr) const;
00253 
00256         bool operator> (const FbxString& pStr) const;
00257 
00260         bool operator== (const char* pStr) const;
00261 
00264         bool operator!= (const char* pStr) const;
00265 
00268         bool operator< (const char* pStr) const;
00269 
00272         bool operator<= (const char* pStr) const;
00273 
00276         bool operator>= (const char* pStr) const;
00277 
00280         bool operator> (const char* pStr) const;
00281 
00285         friend FBXSDK_DLL FbxString operator+(const FbxString& pKStr1, const FbxString& pKStr2);
00286 
00290         friend FBXSDK_DLL FbxString operator+(const FbxString& pKStr, char pChar);
00291 
00295         friend FBXSDK_DLL FbxString operator+(const FbxString& pKStr, const char* pStr);
00296 
00300         friend FBXSDK_DLL FbxString operator+(const FbxString& pKStr, int pValue);
00301 
00305         friend FBXSDK_DLL FbxString operator+(const FbxString& pKStr, float pValue);
00306 
00310         friend FBXSDK_DLL FbxString operator+(const FbxString& pKStr, double pValue);
00311 
00313         operator const char*() const;
00314 
00318         const FbxString& Copy(const char* pStr, size_t pLength);
00319 
00323         const FbxString& Append(const char* pStr, size_t pLength);
00324 
00327         int Compare(const char* pStr) const;
00328 
00331         int CompareNoCase(const char* pStr) const;
00332 
00335         void Swap(FbxString& pStr);
00336 
00338         FbxString Upper() const;
00339 
00341         FbxString Lower() const;
00343 
00351         FbxString Mid(size_t pFirst, size_t pCount) const;
00352 
00355         FbxString Mid(size_t pFirst) const;
00356 
00359         FbxString Left(size_t pCount) const;
00360 
00363         FbxString Right(size_t pCount) const;
00365 
00374         enum EPaddingType {eRight, eLeft, eBoth};
00375 
00380         FbxString Pad(EPaddingType pPadding, size_t pLen, char pCar=' ') const;
00381 
00384         FbxString UnPad(EPaddingType pPadding) const;
00386 
00395         int Find(char pChar, size_t pStartPosition=0) const;
00396 
00401         int Find(const char* pStrSub, size_t pStartPosition=0) const;
00402 
00406         int ReverseFind(char pChar) const;
00407 
00412         int FindOneOf(const char* pStrCharSet, size_t pStartPosition=0) const;
00413 
00419         bool FindAndReplace(const char* pFind, const char* pReplaceBy, size_t pStartPosition=0);
00420 
00425         bool ReplaceAll(const char* pFind, const char* pReplaceBy);
00426 
00431         bool ReplaceAll(char pFind, char pReplaceBy);
00433 
00441         int GetTokenCount(const char* pSpans) const;
00442 
00446         FbxString GetToken(int pTokenIndex, const char* pSpans) const;
00448 
00449 private:
00450     FBXSDK_STRING_OPAQUE_OBJECT;
00451 };
00452 
00453 FBXSDK_INCOMPATIBLE_WITH_ARRAY(FbxString);
00454 
00456 FBXSDK_DLL FbxString operator+(const FbxString& pKStr1, const FbxString& pKStr2);
00457 
00459 FBXSDK_DLL FbxString operator+(const FbxString& pKStr, char pChar);
00460 
00462 FBXSDK_DLL FbxString operator+(const FbxString& pKStr, const char* pStr);
00463 
00465 FBXSDK_DLL FbxString operator+(const FbxString& pKStr, int pValue);
00466 
00468 FBXSDK_DLL FbxString operator+(const FbxString& pKStr, float pValue);
00469 
00471 FBXSDK_DLL FbxString operator+(const FbxString& pKStr, double pValue);
00472 
00474 class FbxStringCompare
00475 {
00476 public:
00482     inline int operator()(const FbxString& pKeyA, const FbxString& pKeyB) const
00483     {
00484         return (pKeyA < pKeyB) ? -1 : ((pKeyB < pKeyA) ? 1 : 0);
00485     }
00486 };
00487 
00489 class FbxCharCompare
00490 {
00491 public:
00493     inline int operator()(char const* pKeyA, char const* pKeyB) const
00494     {
00495         return strcmp(pKeyA, pKeyB);
00496     }
00497 };
00498 
00503 inline void FbxRemoveChar(FbxString& pString, char pToRemove)
00504 {
00505     int lPos = pString.ReverseFind(pToRemove);
00506     while( lPos >= 0 )
00507     {
00508         pString = pString.Left(lPos) + pString.Mid(lPos + 1);
00509         lPos = pString.ReverseFind(pToRemove);
00510     }
00511 }
00512 
00513 #include <fbxsdk/fbxsdk_nsend.h>
00514 
00515 #endif /* _FBXSDK_CORE_BASE_STRING_H_ */