fixedstr.h

Go to the documentation of this file.
00001 /**
00002 *  mi32/fixedstr.h - FIXEDSTRING<> template class.
00003 *
00004 *  \if NODOC
00005 *  $Id: fixedstr.h_v 1.54 2004/04/12 20:08:49 scowan Exp $
00006 *
00007 *  $Log: fixedstr.h_v $
00008 *  Revision 1.54  2004/04/12 20:08:49  scowan
00009 *  Added more ctor's and assignments with different sized strings.
00010 *
00011 *  Revision 1.53  2004/03/31 18:55:37  dwilliss
00012 *  fixed a template func that didn't compile.
00013 *  (you only find out if something uses it - arg!)
00014 *
00015 *  Revision 1.52  2004/03/31 18:15:28  dwilliss
00016 *  Added Assign() variant that takes a CHAR_ENCODING to make it match the
00017 *  one that MISTRING has
00018 *
00019 *  Revision 1.51  2004/02/26 20:48:04  scowan
00020 *  Added another assign method.
00021 *
00022 *  Revision 1.50  2003/11/19 23:03:08  scowan
00023 *  Comment out cast operator to mistring.
00024 *
00025 *  Revision 1.49  2003/09/15 13:49:56  fileserver!dwilliss
00026 *  Doxygen
00027 *
00028 *  Revision 1.48  2003/04/15 17:06:40  scowan
00029 *  Make sure string is cleared to zero from the terminator to the end in generate unique name.
00030 *
00031 *  Revision 1.47  2003/04/15 16:33:59  scowan
00032 *  Added a generate unique name method with filter.
00033 *
00034 *  Revision 1.46  2003/04/10 15:55:58  scowan
00035 *  nc.
00036 *
00037 *  Revision 1.45  2003/04/10 15:42:09  dwilliss
00038 *  Don't use _T in templates.  Mac's ctype.h defines a global _T
00039 *
00040 *  Revision 1.44  2003/02/06 17:33:27  scowan
00041 *  Made get max size a static method.
00042 *
00043 *  Revision 1.43  2002/09/09 13:21:52  mju
00044 *  Remove deprecated methods.
00045 *
00046 *  Revision 1.42  2002/08/28 13:34:25  mju
00047 *  Remove prompt stuff as causes lots of header conflicts with Windows.
00048 *
00049 *  Revision 1.41  2002/08/27 16:58:25  mju
00050 *  Use Widget, not MDLGPARENT.
00051 *
00052 *  Revision 1.40  2002/08/27 14:13:57  scowan
00053 *  Hack for lack of function template support in some compilers.
00054 *
00055 *  Revision 1.39  2002/08/22 19:38:43  scowan
00056 *  Damn annoying compilers.  Made the concatinate operator work again.
00057 *
00058 *  Revision 1.38  2002/08/22 19:02:59  scowan
00059 *  Oops.
00060 *
00061 *  Revision 1.37  2002/08/22 17:33:46  scowan
00062 *  UNIX compiler confusion.
00063 *
00064 *  Revision 1.36  2002/08/22 17:07:06  scowan
00065 *  *** empty log message ***
00066 *
00067 *  Revision 1.35  2002/08/22 17:05:52  scowan
00068 *  Check for null in constructor.
00069 *
00070 *  Revision 1.34  2002/08/19 15:38:22  scowan
00071 *  Fixed g++3.1 warnings.
00072 *
00073 *  Revision 1.33  2002/07/08 14:49:16  scowan
00074 *  nc.
00075 *
00076 *  Revision 1.32  2002/05/17 17:37:29  mju
00077 *  Add GetTail() methods.
00078 *
00079 *  Revision 1.31  2002/05/17 16:53:55  mju
00080 *  Add FIXEDSTRCHAR template defn.
00081 *
00082 *  Revision 1.30  2002/05/02 16:03:46  scowan
00083 *  Nothing.
00084 *
00085 *  Revision 1.29  2002/04/25 22:07:24  mju
00086 *  Remove confusing comment.
00087 *
00088 *  Revision 1.28  2002/04/08 16:48:04  mju
00089 *  Remove sprintf methods.
00090 *
00091 *  Revision 1.27  2002/04/08 16:01:45  mju
00092 *  Add dEPRECATE_FIXEDSTR check.
00093 *
00094 *  Revision 1.26  2002/04/04 22:10:36  mju
00095 *  Remove AssignMsgf as no longer used.
00096 *
00097 *  Revision 1.24  2002/03/28 15:05:02  scowan
00098 *  Deprecated assign message.
00099 *
00100 *  Revision 1.23  2002/03/27 16:36:19  mju
00101 *  Add ctor, op= using TEXTID.
00102 *  Deprecate varargs.
00103 *
00104 *  Revision 1.21  2002/03/25 18:06:10  scowan
00105 *  Added pad to end method.
00106 *
00107 *  Revision 1.20  2002/03/19 18:11:23  mju
00108 *  Rename SetString() as AssignMsgF and add AssignMsg() which does no formatting.
00109 *
00110 *  Revision 1.19  2002/02/19 23:20:58  scowan
00111 *  Added upper and lower case methods.
00112 *
00113 *  Revision 1.18  2002/02/19 18:18:53  scowan
00114 *  Added a conversion to a non-const unicode.
00115 *
00116 *  Revision 1.1  1999/08/26 16:11:28  scowan
00117 *  Initial revision
00118 *  \endif
00119 **/
00120 
00121 #ifndef INC_MI32_FIXEDSTR_H
00122 #define INC_MI32_FIXEDSTR_H
00123 
00124 #ifndef INC_MI32_STDDEFNS_H
00125    #include <mi32/stddefns.h>
00126 #endif
00127    
00128 #ifndef INC_MI32_STDANSIC_H
00129    #include <mi32/stdansic.h>
00130 #endif
00131 
00132 #ifndef INC_MI32_UCSTRING_H
00133    #include <mi32/ucstring.h>
00134 #endif
00135 
00136 #ifndef INC_MI32_MEMBUF_H
00137    #include <mi32/membuf.h>
00138 #endif
00139 
00140 #ifndef INC_MI32_INIDEFNS_H
00141    #include <mi32/inidefns.h>
00142 #endif
00143 
00144 #ifndef INC_MI32_MISTRING_H
00145    #include <mi32/mistring.h>
00146 #endif
00147 
00148 //! Fixed-size array-based UNICODE string.
00149 //!   This class is designed to replace fixed size UNICODE array string constructs in other classes and structures.
00150 //! It is not meant as a STRING class implementation.  Therefore, the class cannot have virtual methods nor any
00151 //!   other members except for the string storage itself.
00152 template <size_t _CT> class FIXEDSTRING {
00153    public:
00154 
00155       //! Default constructor, clears the string.
00156       FIXEDSTRING (                          
00157          ) { Clear(); }
00158 
00159       //! Copy constructor.
00160       FIXEDSTRING (                          
00161          const FIXEDSTRING& rhs
00162          ) { memcpy(m_String, rhs.m_String, sizeof(m_String)); }
00163 
00164       //! Copy constructor
00165       template <int _T2>
00166       FIXEDSTRING (
00167          const FIXEDSTRING<_T2>& rhs            //!< String to concatinate from
00168          ) {
00169          Clear();
00170          ucstrncpy(m_String, rhs.GetReference(), _CT-1);
00171          }
00172 
00173       //! Construct from UNICODE string.
00174       FIXEDSTRING (                          
00175          const UNICODE* string
00176          ) { 
00177          Clear(); 
00178          if (string != 0) ucstrncpy(m_String, string, _CT - 1);
00179          }
00180 
00181       //! Construct from MISTRING string.
00182       FIXEDSTRING (                          
00183          const MISTRING& string
00184          ) { 
00185          Clear(); 
00186          ucstrncpy(m_String, string, _CT - 1);
00187          }
00188 
00189       //! Construct from TEXTID.
00190       FIXEDSTRING (
00191          TEXTID textid
00192          ) { Clear(); MISTRING str(textid); ucstrncpy(m_String,str,_CT-1); }
00193 
00194       //! Destructor.
00195       ~FIXEDSTRING (                         
00196          ) { m_String[0] = 0; }
00197 
00198       //! Assignment operator.
00199       FIXEDSTRING& operator= (                  
00200          const FIXEDSTRING& rhs           //!< String to assign from
00201          ) {
00202          if (this != &rhs) {
00203             memcpy(m_String, rhs.m_String, sizeof(m_String));
00204             }
00205          return (*this);
00206          }
00207 
00208       //! Assignment operator.
00209       template <int _T2>
00210       FIXEDSTRING<_CT>& operator= (
00211          const FIXEDSTRING<_T2>& rhs            //!< String to concatinate from
00212          ) {
00213          Clear();
00214          ucstrncpy(m_String, rhs.GetReference(), _CT-1);
00215          return (*this);
00216          }
00217 
00218       //! Assign from UNICODE string.
00219       FIXEDSTRING& operator= (               
00220          const UNICODE* rhs               //!< String to assign from
00221          ) {
00222          if (m_String != rhs) {
00223             Clear();
00224             if (rhs != 0) ucstrncpy(m_String, rhs, _CT - 1);
00225             }
00226          return (*this);
00227          }
00228 
00229       //! Assign from MISTRING string.
00230       FIXEDSTRING& operator= (               
00231          const MISTRING& rhs              //!< String to assign from
00232          ) {
00233          Clear();
00234          ucstrncpy(m_String, rhs, _CT - 1);
00235          return (*this);
00236          }
00237 
00238       //! Assign from TEXTID.
00239       FIXEDSTRING& operator= (
00240          TEXTID textid                    //!< Message text ID
00241          ) { Clear(); MISTRING str(textid); ucstrncpy(m_String,str,_CT-1); return(*this); }
00242 
00243       //! Concatenate operator.
00244       template <int _T2>
00245       FIXEDSTRING<_CT>& operator+= (
00246          const FIXEDSTRING<_T2>& rhs            //!< String to concatinate from
00247          ) {
00248          ucstrncat(m_String, static_cast<const UNICODE*>(rhs), _CT - (ucstrlen(m_String) + 1));
00249          return (*this);
00250          }
00251 
00252       //! Concatenate from UNICODE string.
00253       FIXEDSTRING& operator+= (                 
00254          const UNICODE* rhs               //!< String to concatinate from
00255          ) {
00256          if (rhs != 0) ucstrncat(m_String, rhs, _CT - (ucstrlen(m_String) + 1));
00257          return (*this);
00258          }
00259          
00260       //! Equality.
00261       bool operator== (
00262          const FIXEDSTRING& rhs
00263          ) const { return (Compare(rhs) == 0); }
00264 
00265       //! Equality.
00266       bool operator== (
00267          const UNICODE *rhs
00268          ) const { return (Compare(rhs) == 0); }
00269 
00270       //! Inequality.
00271       bool operator!= (
00272          const FIXEDSTRING& rhs
00273          ) const { return (!(*this == rhs)); }
00274 
00275       //! Inequality.
00276       bool operator!= (
00277          const UNICODE *rhs
00278          ) const { return (!(*this == rhs)); }
00279 
00280       //! Less Than
00281       bool operator< (
00282          const FIXEDSTRING& rhs
00283          ) const { return (Compare(rhs) < 0); }
00284 
00285       //! Less Than
00286       bool operator< (
00287          const UNICODE *rhs
00288          ) const { return (Compare(rhs) < 0); }
00289 
00290       //! Less Than or Equal to
00291       bool operator<= (
00292          const FIXEDSTRING& rhs
00293          ) const { return (Compare(rhs) <= 0); }
00294 
00295       //! Less Than or Equal to
00296       bool operator<= (
00297          const UNICODE *rhs
00298          ) const { return (Compare(rhs) <= 0); }
00299 
00300       //! Greater Than
00301       bool operator> (
00302          const FIXEDSTRING& rhs
00303          ) const { return (Compare(rhs) > 0); }
00304 
00305       //! Greater Than
00306       bool operator> (
00307          const UNICODE *rhs
00308          ) const { return (Compare(rhs) > 0); }
00309 
00310       //! Greater Than or Equal to
00311       bool operator>= (
00312          const FIXEDSTRING& rhs
00313          ) const { return (Compare(rhs) >= 0); }
00314 
00315       //! Greater Than or Equal to
00316       bool operator>= (
00317          const UNICODE *rhs
00318          ) const { return (Compare(rhs) >= 0); }
00319 
00320       //! Cast to <const UNICODE*>.
00321       operator const UNICODE* (
00322          ) const { return (m_String); }
00323 
00324       //! Cast to <const MISTRING>.
00325 //    operator const MISTRING (
00326 //       ) const { return (MISTRING(m_String)); }
00327 
00328       //! Append from character string, not a constructor so that it is locatable in code.
00329       void Append (                          
00330          const char* name                 //!< Character string to append from
00331          ) {
00332          UNICODE *p = ucstrchr(m_String, 0);
00333          strntouc(p, name, _CT - (p - m_String) - 1);
00334          return;
00335          }
00336 
00337       //! Assign from character string, not a constructor so that it is locatable in code.
00338       void Assign (                          
00339          const char* name                 //!< Character string to assign from
00340          ) { strntouc(m_String, name, _CT - 1); }
00341 
00342       //! Assign from character string, not a constructor so that it is locatable in code.
00343       void Assign (                          
00344          const char* name,                //!< Character string to assign from
00345          size_t len
00346          ) { strntouc(m_String, name, MIN(_CT - 1, len)); }
00347 
00348       //! Assign from character string, not a constructor so that it is locatable in code.
00349       void Assign (                          
00350          const char* name,                //!< Character string to assign from
00351          CHAR_ENCODING encoding           //!< Encoding to use
00352          ) { 
00353          if (encoding == CHAR_ENCODING_ASCII) {
00354             strtouc(m_String, name); 
00355             }
00356          else {
00357             MISTRING mistr(name, encoding);
00358             Clear();
00359             ucstrncpy(m_String, mistr, _CT - 1);
00360             }
00361          }
00362 
00363       //! Assign from UNICODE string with a max length given
00364       void Assign (                          
00365          const UNICODE* name,                //!< UNICODE string to assign from
00366          size_t len
00367          ) { ucstrncpy(m_String, name, MIN(_CT - 1, len)); }
00368 
00369       //! Clear the whole string.
00370       void Clear (                           
00371          ) { memset(m_String, 0, sizeof(m_String)); }
00372       
00373       //! Case-sensitive comparison, length limited (similar to strncmp).
00374       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00375       int Compare (
00376          const FIXEDSTRING& str                 //!< String to compare to
00377          ) const { return (ucstrcmp(m_String, str.m_String)); }
00378 
00379       //! Case-sensitive comparison, length limited (similar to strncmp).
00380       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00381       int Compare (
00382          const UNICODE *str                  //!< String to compare to
00383          ) const { return (ucstrcmp(m_String, str)); }
00384 
00385       //! Case-insensitive comparison (similar to stricmp).
00386       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00387       int CompareNoCase (
00388          const FIXEDSTRING& str                 //!< String to compare to
00389          ) const { return (ucstricmp(m_String, str.m_String)); }
00390 
00391       //! Case-insensitive comparison (similar to stricmp).
00392       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00393       int CompareNoCase (
00394          const UNICODE *str                  //!< String to compare to
00395          ) const { return (ucstricmp(m_String, str)); }
00396          
00397       //! Unique name filter class to determine if the name given is unique               
00398       class UNIQUENAMEFILTER {
00399          public:
00400             UNIQUENAMEFILTER () {}
00401 
00402             //! Filter called to determine if the name is unique
00403             //! @return '1' if unique, '0' if not, < 0 error
00404             int Filter (const FIXEDSTRING<_CT>& string) { return (v_Filter(string)); }
00405          private:
00406             virtual int v_Filter (const FIXEDSTRING<_CT>& string) = 0;
00407          };
00408 
00409       //! Generate an unique name based on the filter passed in
00410       ERRVALUE GenerateUniqueName (
00411          UNIQUENAMEFILTER& FilterInst
00412          ) {
00413          ERRVALUE err;
00414          if ((err = FilterInst.Filter(*this)) < 0) return (err);
00415          if (err > 0) return (0);      //! String is already unique
00416 
00417          //! Initialize string and pointer for character replacement 
00418          int k = 0, len = GetLength();
00419          memset(&m_String[len], 0, (_CT - len) * sizeof(UNICODE));         //! Make sure rest of m_String is set to 0
00420          UNICODE* where = &m_String[len];
00421          if (len == (_CT-1)) where --;
00422          UNICODE* start = where;
00423          UINT8 count[_CT];
00424          memset(count, 0, _CT);
00425 
00426          static char *AddArray = "1234567890abcdefghijklmnopqrstuvwxyz_?";
00427          do {
00428             *where = static_cast<UNICODE>(AddArray[k++]);
00429             if (*where == static_cast<UNICODE>('?')) {
00430                k = 1;
00431                *where = static_cast<UNICODE>(AddArray[0]);
00432                UNICODE *p;
00433                for (p = where - 1;(p >= start);--p) {
00434                   *p = static_cast<UNICODE>(AddArray[count[p-m_String]++]);
00435                   if (*p == static_cast<UNICODE>('?')) {
00436                      *p = static_cast<UNICODE>(AddArray[0]);
00437                      count[p-m_String] = 0;
00438                      }
00439                   else break;
00440                   }
00441                if (p < start) {     //! Reset system and increment where
00442                   ++where;
00443                   if (where - start == 4) return (EProgramError); //! Reality check, if need to increase, it can be. 37 ^ 4 tried!
00444                   memset(count, 0, _CT);
00445                   if (where - m_String == (_CT-1)) {     //! As far out a possible, retreat until a match is not found
00446                      start --;
00447                      where = start;
00448                      if (start < m_String) return (EProgramError);      //! Out of 37 ^ (_CT-1) possible combinations, none found
00449                      }  
00450                   for (p = where;(p >= start);--p) *p = static_cast<UNICODE>(AddArray[0]);
00451                   }
00452                }
00453             err = FilterInst.Filter(*this);
00454             } while (err == 0);
00455          if (err < 0) return (err);
00456          return (0);
00457          }
00458          
00459       //! Get string in specified encoding.
00460       //! @return Encoded string caller must free.
00461       void* GetEncoded (
00462          CHAR_ENCODING encoding              //!< Encoding
00463          ) const {
00464          MISTRING tstr(m_String);
00465          return (tstr.GetEncoded(encoding));
00466          }
00467 
00468       //! Return length of string, not including terminator.
00469       size_t GetLength (                        
00470          ) const { return (ucstrlen(m_String)); }
00471 
00472       //! Return maximum string size, not including terminator.
00473       static size_t GetMaxSize (                      
00474          ) { return (_CT-1); }
00475          
00476       //! Return const string pointer, used for sprintf type parameters
00477       const UNICODE* GetReference (
00478          ) const { return (m_String); }
00479          
00480       //! Get tail of string having up to specified number of characters.
00481       const UNICODE* GetTail (
00482          int maxlen
00483          ) const { int len = ucstrlen(m_String); return ((len <= maxlen) ? m_String : (m_String + (len - maxlen))); }
00484          
00485       //! Find out if the string is empty.   
00486       bool IsEmpty (                         
00487          ) const { return (m_String[0] == 0); }
00488          
00489       //! Set the string according to values in ini file
00490       //! @return: 'true' if entry found and information read, false if empty field or field does not exist
00491       bool IniRead (
00492          INIHANDLE inih,
00493          const char *group,
00494          const char*const field
00495          ) { return (::IniRead(inih, group, field, m_String, _CT * sizeof(UNICODE)) > 0); }
00496 
00497       //! Save the string to values in ini file
00498       void IniWrite (
00499          INIHANDLE inih,
00500          const char *group,
00501          const char*const field
00502          ) { ::IniWrite(inih, group, field, m_String); }
00503 
00504       //! Pad the string with a char to the end of the buffer
00505       void PadToEnd (
00506          char item
00507          ) {
00508          for (int j = ucstrlen(m_String);(j < _CT-1);++j) m_String[j] = item;
00509          m_String[_CT-1] = 0;
00510          }
00511          
00512       //! Set the string to lower case letters
00513       void SetLowerCase (
00514          ) { ucstrlwr(m_String); }
00515 
00516       //! Set the string to upper case letters
00517       void SetUpperCase (
00518          ) { ucstrupr(m_String); }
00519          
00520       //! Swap bytes of the string, used for RVC strings
00521       void SwapBytes (
00522          ) { ::SwapBytes(m_String, _CT); }
00523 
00524       //! Force termination of string at the end.
00525       void Terminate (                       
00526          ) { m_String[_CT - 1] = 0; }
00527 
00528       //! Truncate the string, has no effect if the string is shorter than NewLength.
00529       void Truncate (                           
00530          size_t NewLength
00531          ) { if (NewLength < (_CT - 1)) m_String[NewLength] = 0; }
00532 
00533    private:
00534       #ifndef GENERATING_DOXYGEN_OUTPUT
00535       UNICODE m_String[_CT];
00536       #endif // GENERATING_DOXYGEN_OUTPUT
00537    };
00538 
00539 //! Fixed-size array-based 'char' string.
00540 //!   This class is designed to replace fixed size 'char' array string constructs in other classes and structures.
00541 //! It is not meant as a STRING class implementation.  Therefore, the class cannot have virtual methods nor any
00542 //!   other members except for the string storage itself.
00543 template <size_t _CT> class FIXEDSTRCHAR {
00544    public:
00545 
00546       //! Default constructor, clears the string.
00547       FIXEDSTRCHAR (                         
00548          ) { Clear(); }
00549 
00550       //! Copy constructor.
00551       FIXEDSTRCHAR (                         
00552          const FIXEDSTRCHAR& rhs
00553          ) { memcpy(m_String, rhs.m_String, sizeof(m_String)); }
00554 
00555       //! Construct from char string.
00556       FIXEDSTRCHAR (                         
00557          const char* string
00558          ) { Clear(); strncpy(m_String, string, _CT - 1); }
00559 
00560       //! Destructor.
00561       ~FIXEDSTRCHAR (                           
00562          ) { m_String[0] = 0; }
00563 
00564       //! Assignment operator.
00565       FIXEDSTRCHAR& operator= (                 
00566          const FIXEDSTRCHAR& rhs          //!< String to assign from
00567          ) {
00568          if (this != &rhs) {
00569             memcpy(m_String, rhs.m_String, sizeof(m_String));
00570             }
00571          return (*this);
00572          }
00573 
00574       //! Assign from char string.
00575       FIXEDSTRCHAR& operator= (              
00576          const char* rhs               //!< String to assign from
00577          ) {
00578          if (m_String != rhs) {
00579             Clear();
00580             strncpy(m_String, rhs, _CT - 1);
00581             }
00582          return (*this);
00583          }
00584 
00585       //! Concatenate operator.
00586       FIXEDSTRCHAR& operator+= (                
00587          const FIXEDSTRCHAR& rhs          //!< String to concatinate from
00588          ) {
00589          strncat(m_String, rhs.m_String, _CT - (strlen(m_String) + 1));
00590          return (*this);
00591          }
00592 
00593       //! Concatenate from char string.
00594       FIXEDSTRCHAR& operator+= (                
00595          const char* rhs               //!< String to concatinate from
00596          ) {
00597          strncat(m_String, rhs, _CT - (strlen(m_String) + 1));
00598          return (*this);
00599          }
00600          
00601       //! Equality.
00602       bool operator== (
00603          const FIXEDSTRCHAR& rhs
00604          ) const { return (Compare(rhs) == 0); }
00605 
00606       //! Equality.
00607       bool operator== (
00608          const char *rhs
00609          ) const { return (Compare(rhs) == 0); }
00610 
00611       //! Inequality.
00612       bool operator!= (
00613          const FIXEDSTRCHAR& rhs
00614          ) const { return (!(*this == rhs)); }
00615 
00616       //! Inequality.
00617       bool operator!= (
00618          const char *rhs
00619          ) const { return (!(*this == rhs)); }
00620 
00621       //! Less Than
00622       bool operator< (
00623          const FIXEDSTRCHAR& rhs
00624          ) const { return (Compare(rhs) < 0); }
00625 
00626       //! Less Than
00627       bool operator< (
00628          const char *rhs
00629          ) const { return (Compare(rhs) < 0); }
00630 
00631       //! Less Than or Equal to
00632       bool operator<= (
00633          const FIXEDSTRCHAR& rhs
00634          ) const { return (Compare(rhs) <= 0); }
00635 
00636       //! Less Than or Equal to
00637       bool operator<= (
00638          const char *rhs
00639          ) const { return (Compare(rhs) <= 0); }
00640 
00641       //! Greater Than
00642       bool operator> (
00643          const FIXEDSTRCHAR& rhs
00644          ) const { return (Compare(rhs) > 0); }
00645 
00646       //! Greater Than
00647       bool operator> (
00648          const char *rhs
00649          ) const { return (Compare(rhs) > 0); }
00650 
00651       //! Greater Than or Equal to
00652       bool operator>= (
00653          const FIXEDSTRCHAR& rhs
00654          ) const { return (Compare(rhs) >= 0); }
00655 
00656       //! Greater Than or Equal to
00657       bool operator>= (
00658          const char *rhs
00659          ) const { return (Compare(rhs) >= 0); }
00660 
00661       //! Cast to <const char*>.
00662       operator const char* (
00663          ) const { return (m_String); }
00664 
00665       //! Assign from character string.
00666       void Assign (
00667          const char* name                 //!< Character string to assign from
00668          ) { strncpy(m_String, name, _CT - 1); }
00669 
00670       //! Assign from char string with a max length given
00671       void Assign (                          
00672          const char* name,                //!< char string to assign from
00673          size_t len
00674          ) { strncpy(m_String, name, MIN(_CT - 1, len)); }
00675 
00676       //! Clear the whole string.
00677       void Clear (                           
00678          ) { memset(m_String, 0, sizeof(m_String)); }
00679       
00680       //! Case-sensitive comparison, similar to strcmp.
00681       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00682       int Compare (
00683          const FIXEDSTRCHAR& str                //!< String to compare to
00684          ) const { return (strcmp(m_String, str.m_String)); }
00685 
00686       //! Case-sensitive comparison, (similar to strcmp).
00687       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00688       int Compare (
00689          const char *str                  //!< String to compare to
00690          ) const { return (strcmp(m_String, str)); }
00691 
00692       //! Case-insensitive comparison (similar to stricmp).
00693       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00694       int CompareNoCase (
00695          const FIXEDSTRCHAR& str                //!< String to compare to
00696          ) const { return (stricmp(m_String, str.m_String)); }
00697 
00698       //! Case-insensitive comparison (similar to stricmp).
00699       //! @return 0 if strings equal, -1 if this < str, 1 if this > str.
00700       int CompareNoCase (
00701          const char *str                  //!< String to compare to
00702          ) const { return (stricmp(m_String, str)); }
00703          
00704       //! Find out if the string is empty.   
00705       bool IsEmpty (                         
00706          ) const { return (m_String[0] == 0); }
00707          
00708       //! Set the string according to values in ini file
00709       //! @return: 'true' if entry found and information read, false if empty field or field does not exist
00710       bool IniRead (
00711          INIHANDLE inih,
00712          const char *group,
00713          const char*const field
00714          ) { return (::IniRead(inih, group, field, m_String, _CT * sizeof(char)) > 0); }
00715 
00716       //! Save the string to values in ini file
00717       void IniWrite (
00718          INIHANDLE inih,
00719          const char *group,
00720          const char*const field
00721          ) { ::IniWrite(inih, group, field, m_String); }
00722 
00723       //! Return length of string, not including terminator.
00724       size_t GetLength (                        
00725          ) const { return (strlen(m_String)); }
00726 
00727       //! Return maximum string size, not including terminator.
00728       size_t GetMaxSize (                       
00729          ) const { return (_CT-1); }
00730 
00731       //! Get tail of string having up to specified number of characters.
00732       const char* GetTail (
00733          int maxlen
00734          ) const { int len = strlen(m_String); return ((len <= maxlen) ? m_String : (m_String + (len - maxlen))); }
00735          
00736       //! Pad the string with a char to the end of the buffer
00737       void PadToEnd (
00738          char item
00739          ) {
00740          for (int j = strlen(m_String);(j < _CT-1);++j) m_String[j] = item;
00741          m_String[_CT-1] = 0;
00742          }
00743          
00744       //! Set the string to lower case letters
00745       void SetLowerCase (
00746          ) { strlwr(m_String); }
00747 
00748       //! Set the string to upper case letters
00749       void SetUpperCase (
00750          ) { strupr(m_String); }
00751          
00752       //! Force termination of string at the end.
00753       void Terminate (                       
00754          ) { m_String[_CT - 1] = 0; }
00755 
00756       //! Truncate the string, has no effect if the string is shorter than NewLength.
00757       void Truncate (                           
00758          size_t NewLength
00759          ) { if (NewLength >= 0 && NewLength < (_CT - 1)) m_String[NewLength] = 0; }
00760 
00761    protected:
00762       #ifndef GENERATING_DOXYGEN_OUTPUT
00763       char m_String[_CT];
00764       #endif //!< GENERATING_DOXYGEN_OUTPUT
00765    };
00766 
00767 #endif      //!< INC_MI32_FIXEDSTR_H

Generated on Tue Dec 14 13:18:21 2004 for TNTsdk by  doxygen 1.3.8-20040913