CharBuffer.h (3248B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 #ifndef __CHARBUFFER_HPP 23 #define __CHARBUFFER_HPP 24 25 class CCharBuffer 26 { 27 char* m_pCharBuffer; 28 unsigned m_uSize; 29 30 public: 31 CCharBuffer(); 32 33 CCharBuffer(unsigned uSize); 34 35 CCharBuffer(const char* pString); 36 37 CCharBuffer(const CCharBuffer& rhs); 38 39 ~CCharBuffer(); 40 41 char* Allocate(uint uSize); 42 43 void DeAllocate(); 44 45 size_t StringLength() 46 { return strlen(m_pCharBuffer); } 47 48 void StripTrailing(char c, int nLen); 49 50 char& operator *() 51 { return *m_pCharBuffer; } 52 53 char& operator *() const 54 { return *const_cast<CCharBuffer*>(this)->m_pCharBuffer; } 55 56 operator void*() 57 { return m_pCharBuffer; } 58 59 operator char*() 60 { return m_pCharBuffer; } 61 62 operator const char*() 63 { return reinterpret_cast<const char*>(m_pCharBuffer); } 64 65 operator unsigned char*() 66 { return reinterpret_cast<unsigned char*>(m_pCharBuffer); } 67 68 operator const unsigned char*() 69 { return reinterpret_cast<const unsigned char*>(m_pCharBuffer); } 70 71 unsigned SizeOf() 72 { return m_uSize; } 73 74 CCharBuffer& operator =(const CCharBuffer& rhs); 75 76 CCharBuffer& operator =(const char* pString); 77 78 bool operator ==(const CCharBuffer& rhs) const 79 { return strcmp(m_pCharBuffer, rhs.m_pCharBuffer) == 0; } 80 81 bool operator ==(char* pString) const 82 { return strcmp(m_pCharBuffer, pString) == 0; } 83 84 bool operator ==(const char* pString) const 85 { return strcmp(m_pCharBuffer, pString) == 0; } 86 87 bool operator !=(CCharBuffer& rhs) const 88 { return strcmp(m_pCharBuffer, rhs.m_pCharBuffer) != 0; } 89 90 bool operator !=(char* pString) const 91 { return strcmp(m_pCharBuffer, pString) != 0; } 92 93 bool operator !=(const char* pString) const 94 { return strcmp(m_pCharBuffer, pString) != 0; } 95 96 char& operator [](int nIndex) 97 { return m_pCharBuffer[nIndex]; } 98 99 char& operator [](int nIndex) const 100 { return m_pCharBuffer[nIndex]; } 101 102 char* Fill(char FillChar) 103 { memset(m_pCharBuffer, FillChar, m_uSize-1); return m_pCharBuffer; } 104 }; 105 // 106 //----------------------------------------------------------------------------- 107 #endif // __CCHARBUFFER_HPP 108 //----------------------------------------------------------------------------- 109 //