home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / fxstring.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  1.8 KB  |  69 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : fixstring.h                                                         //
  10. //  Description: Template class for fixed size string                                //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. // Fixed size character string
  15. template<int nMaxSize=256> 
  16. class KString
  17. {
  18.     TCHAR Buffer[nMaxSize];
  19.     int   nLength;
  20.  
  21. public:
  22.     KString(void)
  23.     {
  24.         Buffer[0] = 0;
  25.         nLength = 0;
  26.     }
  27.  
  28.     int GetLength(void) const
  29.     {
  30.         return nLength;
  31.     }
  32.  
  33.     operator LPCTSTR() const
  34.     {
  35.         return Buffer;
  36.     }
  37.  
  38.     LPCTSTR Append(LPCTSTR tail)
  39.     {
  40.         lstrcat(Buffer+nLength, tail);
  41.         nLength += lstrlen(tail);
  42.         
  43.         assert(nLength<nMaxSize);
  44.  
  45.         return Buffer;
  46.     }
  47.  
  48.     LPCTSTR Append(LPCTSTR format, unsigned number)
  49.     {
  50.         wsprintf(Buffer+nLength, format, number);
  51.         nLength = lstrlen(Buffer);
  52.         
  53.         assert(nLength<nMaxSize);
  54.  
  55.         return Buffer;
  56.     }
  57.  
  58.     LPCTSTR Format(LPCTSTR format, unsigned number)
  59.     {
  60.         wsprintf(Buffer, format, number);
  61.         nLength = lstrlen(Buffer);
  62.         
  63.         assert(nLength<nMaxSize);
  64.  
  65.         return Buffer;
  66.     }
  67.  
  68. };
  69.