StrStatic.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __STRSTATIC_H__
  21. #define __STRSTATIC_H__
  22. /*
  23. ================================================
  24. idStrStatic
  25. ================================================
  26. */
  27. template< int _size_ >
  28. class idStrStatic : public idStr {
  29. public:
  30. ID_INLINE void operator=( const idStrStatic &text ) {
  31. // we should only get here when the types, including the size, are identical
  32. len = text.Length();
  33. memcpy( data, text.data, len+1 );
  34. }
  35. // all idStr operators are overloaded and the idStr default constructor is called so that the
  36. // static buffer can be initialized in the body of the constructor before the data is ever
  37. // copied.
  38. ID_INLINE idStrStatic() {
  39. buffer[ 0 ] = '\0';
  40. SetStaticBuffer( buffer, _size_ );
  41. }
  42. ID_INLINE idStrStatic( const idStrStatic & text ) :
  43. idStr() {
  44. buffer[ 0 ] = '\0';
  45. SetStaticBuffer( buffer, _size_ );
  46. idStr::operator=( text );
  47. }
  48. ID_INLINE idStrStatic( const idStr & text ) :
  49. idStr() {
  50. buffer[ 0 ] = '\0';
  51. SetStaticBuffer( buffer, _size_ );
  52. idStr::operator=( text );
  53. }
  54. ID_INLINE idStrStatic( const idStrStatic & text, int start, int end ) :
  55. idStr() {
  56. buffer[ 0 ] = '\0';
  57. SetStaticBuffer( buffer, _size_ );
  58. CopyRange( text.c_str(), start, end );
  59. }
  60. ID_INLINE idStrStatic( const char * text ) :
  61. idStr() {
  62. buffer[ 0 ] = '\0';
  63. SetStaticBuffer( buffer, _size_ );
  64. idStr::operator=( text );
  65. }
  66. ID_INLINE idStrStatic( const char * text, int start, int end ) :
  67. idStr() {
  68. buffer[ 0 ] = '\0';
  69. SetStaticBuffer( buffer, _size_ );
  70. CopyRange( text, start, end );
  71. }
  72. ID_INLINE explicit idStrStatic( const bool b ) :
  73. idStr() {
  74. buffer[ 0 ] = '\0';
  75. SetStaticBuffer( buffer, _size_ );
  76. idStr::operator=( b );
  77. }
  78. ID_INLINE explicit idStrStatic( const char c ) :
  79. idStr() {
  80. buffer[ 0 ] = '\0';
  81. SetStaticBuffer( buffer, _size_ );
  82. idStr::operator=( c );
  83. }
  84. ID_INLINE explicit idStrStatic( const int i ) :
  85. idStr() {
  86. buffer[ 0 ] = '\0';
  87. SetStaticBuffer( buffer, _size_ );
  88. idStr::operator=( i );
  89. }
  90. ID_INLINE explicit idStrStatic( const unsigned u ) :
  91. idStr() {
  92. buffer[ 0 ] = '\0';
  93. SetStaticBuffer( buffer, _size_ );
  94. idStr::operator=( u );
  95. }
  96. ID_INLINE explicit idStrStatic( const float f ) :
  97. idStr() {
  98. buffer[ 0 ] = '\0';
  99. SetStaticBuffer( buffer, _size_ );
  100. idStr::operator=( f );
  101. }
  102. private:
  103. char buffer[ _size_ ];
  104. };
  105. #endif // __STRSTATIC_H__