DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

StrStatic.h (4110B)


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