SIBCString.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Softimage 3D Games & 3D Bridge team
00004 //
00005 // (c) Copyright 1999-2002 Avid Technology, Inc. . All rights reserved.
00006 //
00007 // SIBCString.h | Main header file for SIBCString implementation
00008 //***************************************************************************************
00009 
00010 /****************************************************************************************
00011 THIS CODE IS PUBLISHED AS A SAMPLE ONLY AND IS PROVIDED "AS IS".
00012 IN NO EVENT SHALL SOFTIMAGE, AVID TECHNOLOGY, INC. AND/OR THEIR RESPECTIVE
00013 SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00014 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00016 CONNECTION WITH THE USE OR PERFORMANCE OF THIS CODE .
00017 
00018 COPYRIGHT NOTICE. Copyright © 1999-2002 Avid Technology Inc. . All rights reserved. 
00019 
00020 SOFTIMAGE is a registered trademark of Avid Technology Inc. or its subsidiaries 
00021 or divisions. Windows NT is a registered trademark of Microsoft Corp. All other
00022 trademarks contained herein are the property of their respective owners. 
00023 ****************************************************************************************/
00024 
00025 //***************************************************************************************
00026 // Defines
00027 //***************************************************************************************
00028 #ifndef __CSIBCString_H__
00029 #define __CSIBCString_H__
00030 
00031 //***************************************************************************************
00032 // Includes
00033 //***************************************************************************************
00034 #include <SIBCUtil.h>
00035 
00036 
00037 //***************************************************************************************
00038 // CSIBCString | General purpose string class
00039 //***************************************************************************************
00040 
00042 
00046 class XSICOREEXPORT CSIBCString
00047 {
00048 public:
00049 
00053     CSIBCString();
00054 
00059     CSIBCString( const CSIBCString &in_pString );
00060 
00061 
00067     CSIBCString(const SI_Char *in_pString );            // Constructor
00068 
00069     ~CSIBCString();                                     // Default Destructor
00070 
00074     SI_Int GetLength();
00075 
00092     SI_Char *GetText();
00093 
00096     void Clear();
00097 
00106     SI_Error Concat(CSIBCString *in_pString);
00107 
00117     SI_Error Concat(const SI_Char *in_pString);         // Concatenate to the string
00118 
00139     SI_Error Concat(const SI_Int in_lInt);
00140 
00159     SI_Error Concat(const SI_Float in_fFloat);          // Concatenate to the string
00160 
00169     SI_Error SetText(CSIBCString *in_pString);          // Assign to the string
00170 
00180     SI_Error SetText(const SI_Char *in_pString);        // Assign to the string
00181 
00190     SI_Error SetText(const SI_Int in_lInt);             // Assign to the string
00191 
00200     SI_Error SetText(const SI_Float in_fFloat);         // Assign to the string
00201 
00216     SI_Int Compare(CSIBCString *in_pString);
00217 
00232     SI_Int Compare(const SI_Char *in_pString);          // Compare with the string
00233 
00241     SI_Int Compare(const SI_Int in_lInt);               // Compare with the string
00242 
00250     SI_Int Compare(const SI_Float in_fFloat);           // Compare with the string
00251 
00259     SI_Error LowerCase();
00260 
00268     SI_Error UpperCase();                               // Turns all characters in string to upper case
00269 
00273     SI_Error RemoveIllegalXSICharacters();
00274 
00278     SI_Bool IsXSILegalName();
00279 
00280 
00285     CSIBCString &operator = ( const CSIBCString & i_pString);
00286 
00292     CSIBCString &operator = ( const SI_Char * i_pString);
00293 
00298     bool operator == (CSIBCString & i_pString);
00299 
00304     bool operator == (const SI_Char * i_pString);
00305 
00310     bool operator != (CSIBCString & i_pString);                 // Tests to see if strings are not equal
00311 
00315     void Dump();
00316 
00322     SI_UInt UsedMemory();                               // returns the amount of used memory
00323 
00329     SI_UInt AllocatedMemory();                          // returns the amount of allocated memory.
00330 
00331 protected:
00332 
00333 
00334 private:
00335 
00336     SI_Int      m_lLength;                              // Length of the string
00337     SI_Char     *m_pBuffer;                             // Internal SI_Char buffer
00338 };
00339 
00340 //***************************************************************************************
00341 // CSIAccumString | Optimized string class.
00342 //***************************************************************************************
00343 
00345 
00349 class XSICOREEXPORT CSIAccumString
00350 {
00351     enum {eAllocSize = 0x100};
00352 public:
00353 
00358     CSIAccumString() 
00359     {
00360         m_AllocSize = eAllocSize;
00361         m_Buffer = (SI_Char*) malloc(m_AllocSize);
00362         m_BufferEnd = m_Buffer;
00363         *m_BufferEnd = 0;
00364     }
00365 
00366     ~CSIAccumString()
00367     {
00368         free( m_Buffer );
00369     }
00370 
00374     void Clear()
00375     {
00376         free( m_Buffer );
00377         m_AllocSize = eAllocSize;
00378         m_Buffer = (SI_Char*) malloc(m_AllocSize);
00379         m_BufferEnd = m_Buffer;
00380         *m_BufferEnd = 0;
00381     }
00382 
00386     void ConcatByte( SI_Byte in_Byte )
00387     {
00388         SI_Int l_iCurrDelta = (SI_Int)(m_BufferEnd - m_Buffer);
00389         if ( l_iCurrDelta > ( m_AllocSize - 2 ) )
00390         {
00391             // Array doubling... Good enough.
00392             m_AllocSize <<= 1;
00393             m_Buffer = (SI_Char*) realloc(m_Buffer,m_AllocSize);
00394             m_BufferEnd = m_Buffer + l_iCurrDelta;
00395         }
00396         *m_BufferEnd = in_Byte;
00397         ++m_BufferEnd;
00398         *m_BufferEnd = 0;
00399     }
00400 
00404     SI_Int GetLength() const { return (SI_Int)(m_BufferEnd - m_Buffer); }   
00405 
00411     SI_Char *GetText() const { return m_Buffer; }
00412 
00413 private:
00414 
00415     // No copy semantics needed. Play safe.
00416     CSIAccumString(const CSIAccumString&);
00417     const CSIAccumString& operator=( const CSIAccumString &);
00418 
00419     SI_Char*        m_Buffer;
00420     SI_Char*        m_BufferEnd;
00421     SI_Int          m_AllocSize;
00422 };
00423 
00424 #endif
00425 // CSIBCString