6 #ifndef xmog_quickstring_inc
7 #define xmog_quickstring_inc
10 #if (XMOG_WINDOWS==1 && _MSC_VER <= 1200)
12 #define XMOG_QSTR(x) xmog_qstr_##x##_char
13 #define XMOG_QSTR_1(x,y) xmog_qstr_##x##_##y
14 #define XMOG_QSTR_TYPE(x,y) class xmog_qstr_##x##_##y \
26 xmog_qstr_##x##_##y() :\
33 xmog_qstr_##x##_##y( const y * pStr, size_t max = (size_t)-1 ) :\
38 append( pStr, max == (size_t)-1 ? 0 : max );\
43 xmog_qstr_##x##_##y( xmog_qstr_##x##_##y & rhs ) :\
48 append( (const y*)rhs, rhs.cUsed );\
54 xmog_qstr_##x##_##y & operator = ( const xmog_qstr_##x##_##y & rhs )\
56 if( pBuffer != NULL )\
65 append( (const y*)rhs, rhs.cUsed );\
73 xmog_qstr_##x##_##y & operator = ( const y * pStr )\
75 if( pBuffer != NULL )\
89 ~xmog_qstr_##x##_##y()\
99 return pBuffer ? pBuffer : buffer;\
102 operator const y * () const\
104 return pBuffer ? pBuffer : buffer;\
107 void alloc( size_t size )\
110 pBuffer = new y[ size ];\
113 void append( const y * str, size_t max = 0 )\
118 size_t len = max ? max : strlen( str );\
120 if( pBuffer == 0 && cUsed + len < x )\
122 strncpy( buffer + cUsed, str, len + 1 );\
127 y * temp = new y[ cUsed + len + 1 ];\
131 strncpy( temp, pBuffer, cUsed );\
135 strncpy( temp, buffer, cUsed );\
137 strncpy( temp + cUsed, str, len + 1 );\
142 (pBuffer?pBuffer:buffer)[ cUsed ] = 0;\
145 void replace( y src, y dest )\
147 y * pElem = pBuffer ? pBuffer : buffer;\
149 for( jint i=(jint)cUsed-1; i>=0; --i, pElem++ )\
154 size_t length() const\
160 XMOG_QSTR_TYPE(32,
char)
161 XMOG_QSTR_TYPE(64,
char)
162 XMOG_QSTR_TYPE(256,
char)
163 XMOG_QSTR_TYPE(512,
char)
164 XMOG_QSTR_TYPE(1024,
char)
168 #define XMOG_QSTR(x) xmog_qstr<x>
169 #define XMOG_QSTR_1(x,y) xmog_qstr<x,y>
171 template <
int PreAlloc,
class ElemType =
char >
class xmog_qstr
175 ElemType buffer[ PreAlloc ];
190 xmog_qstr(
const ElemType * pStr,
size_t max = (
size_t)-1 ) :
195 append( pStr, max == (
size_t)-1 ? 0 : max );
205 append( (
const ElemType*)rhs, rhs.cUsed );
213 if( pBuffer != NULL )
222 append( (
const ElemType*)rhs, rhs.cUsed );
230 xmog_qstr & operator = (
const ElemType * pStr )
232 if( pBuffer != NULL )
254 operator ElemType * ()
256 return pBuffer ? pBuffer : buffer;
259 operator const ElemType * ()
const
261 return pBuffer ? pBuffer : buffer;
264 void alloc(
size_t size )
266 if( size > PreAlloc )
267 pBuffer =
new ElemType[ size ];
270 void append(
const ElemType * str,
size_t max = 0 )
275 size_t len = max ? max : strlen( str );
277 if( pBuffer == 0 && cUsed + len < PreAlloc )
279 strncpy( buffer + cUsed, str, len + 1 );
284 ElemType * temp =
new ElemType[ cUsed + len + 1 ];
288 strncpy( temp, pBuffer, cUsed );
292 strncpy( temp, buffer, cUsed );
294 strncpy( temp + cUsed, str, len + 1 );
299 (pBuffer?pBuffer:buffer)[ cUsed ] = 0;
302 void replace( ElemType src, ElemType dest )
304 ElemType * pElem = pBuffer ? pBuffer : buffer;
306 for( jint i=(jint)cUsed-1; i>=0; --i, pElem++ )
311 size_t length()
const
317 #endif // _MSC_VER <= 1200
319 #endif //xmog_quickstring_inc