CharBuffer.h 3.2 KB

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