SIBCString.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.
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 
00012 //***************************************************************************************
00013 // Defines
00014 //***************************************************************************************
00015 #ifndef __CSIBCString_H__
00016 #define __CSIBCString_H__
00017 
00018 //***************************************************************************************
00019 // Includes
00020 //***************************************************************************************
00021 #include <SIBCUtil.h>
00022 
00023 
00024 //***************************************************************************************
00025 // CSIBCString | General purpose string class
00026 //***************************************************************************************
00027 
00029 
00033 class XSICOREEXPORT CSIBCString
00034 {
00035 public:
00036 
00040     CSIBCString();
00041 
00046     CSIBCString( const CSIBCString &in_pString );
00047 
00048 
00054     CSIBCString(const SI_Char *in_pString );            // Constructor
00055 
00056     ~CSIBCString();                                     // Default Destructor
00057 
00061     SI_Int GetLength();
00062 
00079     SI_Char *GetText();
00080 
00083     void Clear();
00084 
00093     SI_Error Concat(CSIBCString *in_pString);
00094 
00104     SI_Error Concat(const SI_Char *in_pString);         // Concatenate to the string
00105 
00126     SI_Error Concat(const SI_Int in_lInt);
00127 
00146     SI_Error Concat(const SI_Float in_fFloat);          // Concatenate to the string
00147 
00156     SI_Error SetText(CSIBCString *in_pString);          // Assign to the string
00157 
00167     SI_Error SetText(const SI_Char *in_pString);        // Assign to the string
00168 
00177     SI_Error SetText(const SI_Int in_lInt);             // Assign to the string
00178 
00187     SI_Error SetText(const SI_Float in_fFloat);         // Assign to the string
00188 
00203     SI_Int Compare(CSIBCString *in_pString);
00204 
00219     SI_Int Compare(const SI_Char *in_pString);          // Compare with the string
00220 
00228     SI_Int Compare(const SI_Int in_lInt);               // Compare with the string
00229 
00237     SI_Int Compare(const SI_Float in_fFloat);           // Compare with the string
00238 
00246     SI_Error LowerCase();
00247 
00255     SI_Error UpperCase();                               // Turns all characters in string to upper case
00256 
00260     SI_Error RemoveIllegalXSICharacters();
00261 
00265     SI_Bool IsXSILegalName();
00266 
00267 
00272     CSIBCString &operator = ( const CSIBCString & i_pString);
00273 
00279     CSIBCString &operator = ( const SI_Char * i_pString);
00280 
00285     bool operator == (CSIBCString & i_pString);
00286 
00291     bool operator == (const SI_Char * i_pString);
00292 
00297     bool operator != (CSIBCString & i_pString);                 // Tests to see if strings are not equal
00298 
00302     void Dump();
00303 
00309     SI_UInt UsedMemory();                               // returns the amount of used memory
00310 
00316     SI_UInt AllocatedMemory();                          // returns the amount of allocated memory.
00317 
00318 protected:
00319 
00320 
00321 private:
00322 
00323     SI_Int      m_lLength;                              // Length of the string
00324     SI_Char     *m_pBuffer;                             // Internal SI_Char buffer
00325 };
00326 
00327 //***************************************************************************************
00328 // CSIAccumString | Optimized string class.
00329 //***************************************************************************************
00330 
00332 
00336 class XSICOREEXPORT CSIAccumString
00337 {
00338     enum {eAllocSize = 0x100};
00339 public:
00340 
00345     CSIAccumString()
00346     {
00347         m_AllocSize = eAllocSize;
00348         m_Buffer = (SI_Char*) malloc(m_AllocSize);
00349         m_BufferEnd = m_Buffer;
00350         *m_BufferEnd = 0;
00351     }
00352 
00353     ~CSIAccumString()
00354     {
00355         free( m_Buffer );
00356     }
00357 
00361     void Clear()
00362     {
00363         free( m_Buffer );
00364         m_AllocSize = eAllocSize;
00365         m_Buffer = (SI_Char*) malloc(m_AllocSize);
00366         m_BufferEnd = m_Buffer;
00367         *m_BufferEnd = 0;
00368     }
00369 
00373     void ConcatByte( SI_Byte in_Byte )
00374     {
00375         SI_Int l_iCurrDelta = (SI_Int)(m_BufferEnd - m_Buffer);
00376         if ( l_iCurrDelta > ( m_AllocSize - 2 ) )
00377         {
00378             // Array doubling... Good enough.
00379             m_AllocSize <<= 1;
00380             m_Buffer = (SI_Char*) realloc(m_Buffer,m_AllocSize);
00381             m_BufferEnd = m_Buffer + l_iCurrDelta;
00382         }
00383         *m_BufferEnd = in_Byte;
00384         ++m_BufferEnd;
00385         *m_BufferEnd = 0;
00386     }
00387 
00391     SI_Int GetLength() const { return (SI_Int)(m_BufferEnd - m_Buffer); }
00392 
00398     SI_Char *GetText() const { return m_Buffer; }
00399 
00400 private:
00401 
00402     // No copy semantics needed. Play safe.
00403     CSIAccumString(const CSIAccumString&);
00404     const CSIAccumString& operator=( const CSIAccumString &);
00405 
00406     SI_Char*        m_Buffer;
00407     SI_Char*        m_BufferEnd;
00408     SI_Int          m_AllocSize;
00409 };
00410 
00411 #endif
00412 // CSIBCString