00001
00018 #ifndef INC_MI32_FIXEDSTRCHAR_H
00019 #define INC_MI32_FIXEDSTRCHAR_H
00020
00021 #ifndef INC_MI32_INIBASE_H
00022 #include <mi32/inibase.h>
00023 #endif
00024
00025 #ifndef INC_MEMORY_H
00026 #include <memory.h>
00027 #define INC_MEMORY_H
00028 #endif
00029
00034 template <int _CT> class FIXEDSTRCHAR {
00035 public:
00036
00038 FIXEDSTRCHAR (
00039 ) { Clear(); }
00040
00042 FIXEDSTRCHAR (
00043 const FIXEDSTRCHAR& rhs
00044 ) { memcpy(m_String, rhs.m_String, sizeof(m_String)); }
00045
00047 FIXEDSTRCHAR (
00048 const char* string
00049 ) { Clear(); strncpy(m_String, string, _CT - 1); }
00050
00052 ~FIXEDSTRCHAR (
00053 ) { m_String[0] = 0; }
00054
00056 FIXEDSTRCHAR& operator= (
00057 const FIXEDSTRCHAR& rhs
00058 ) {
00059 if (this != &rhs) {
00060 memcpy(m_String, rhs.m_String, sizeof(m_String));
00061 }
00062 return (*this);
00063 }
00064
00066 FIXEDSTRCHAR& operator= (
00067 const char* rhs
00068 ) {
00069 if (m_String != rhs) {
00070 Clear();
00071 strncpy(m_String, rhs, _CT - 1);
00072 }
00073 return (*this);
00074 }
00075
00077 FIXEDSTRCHAR& operator+= (
00078 const FIXEDSTRCHAR& rhs
00079 ) {
00080 strncat(m_String, rhs.m_String, _CT - (strlen(m_String) + 1));
00081 return (*this);
00082 }
00083
00085 FIXEDSTRCHAR& operator+= (
00086 const char* rhs
00087 ) {
00088 strncat(m_String, rhs, _CT - (strlen(m_String) + 1));
00089 return (*this);
00090 }
00091
00093 bool operator== (
00094 const FIXEDSTRCHAR& rhs
00095 ) const { return (Compare(rhs) == 0); }
00096
00098 bool operator== (
00099 const char *rhs
00100 ) const { return (Compare(rhs) == 0); }
00101
00103 bool operator!= (
00104 const FIXEDSTRCHAR& rhs
00105 ) const { return (!(*this == rhs)); }
00106
00108 bool operator!= (
00109 const char *rhs
00110 ) const { return (!(*this == rhs)); }
00111
00113 bool operator< (
00114 const FIXEDSTRCHAR& rhs
00115 ) const { return (Compare(rhs) < 0); }
00116
00118 bool operator< (
00119 const char *rhs
00120 ) const { return (Compare(rhs) < 0); }
00121
00123 bool operator<= (
00124 const FIXEDSTRCHAR& rhs
00125 ) const { return (Compare(rhs) <= 0); }
00126
00128 bool operator<= (
00129 const char *rhs
00130 ) const { return (Compare(rhs) <= 0); }
00131
00133 bool operator> (
00134 const FIXEDSTRCHAR& rhs
00135 ) const { return (Compare(rhs) > 0); }
00136
00138 bool operator> (
00139 const char *rhs
00140 ) const { return (Compare(rhs) > 0); }
00141
00143 bool operator>= (
00144 const FIXEDSTRCHAR& rhs
00145 ) const { return (Compare(rhs) >= 0); }
00146
00148 bool operator>= (
00149 const char *rhs
00150 ) const { return (Compare(rhs) >= 0); }
00151
00153 operator const char* (
00154 ) const { return (m_String); }
00155
00157 void Assign (
00158 const char* name
00159 ) { strncpy(m_String, name, _CT - 1); }
00160
00162 void Assign (
00163 const char* name,
00164 int len
00165 ) { strncpy(m_String, name, MIN(_CT - 1, len)); }
00166
00168 void Clear (
00169 ) { memset(m_String, 0, sizeof(m_String)); }
00170
00173 int Compare (
00174 const FIXEDSTRCHAR& str
00175 ) const { return (strcmp(m_String, str.m_String)); }
00176
00179 int Compare (
00180 const char *str
00181 ) const { return (strcmp(m_String, str)); }
00182
00185 int CompareNoCase (
00186 const FIXEDSTRCHAR& str
00187 ) const { return (stricmp(m_String, str.m_String)); }
00188
00191 int CompareNoCase (
00192 const char *str
00193 ) const { return (stricmp(m_String, str)); }
00194
00196 bool IsEmpty (
00197 ) const { return (m_String[0] == 0); }
00198
00201 bool IniRead (
00202 INIHANDLE inih,
00203 const char *group,
00204 const char*const field
00205 ) { return (_iniReadString(inih, group, field, INITYPE_ASCII, m_String, _CT * sizeof(char)) > 0); }
00206
00208 void IniWrite (
00209 INIHANDLE inih,
00210 const char *group,
00211 const char*const field
00212 ) { _iniWriteString(inih, group, field, INITYPE_ASCII, m_String); }
00213
00215 int GetLength (
00216 ) const { return (strlen(m_String)); }
00217
00219 int GetMaxSize (
00220 ) const { return (_CT-1); }
00221
00223 const char* GetTail (
00224 int maxlen
00225 ) const { int len = strlen(m_String); return ((len <= maxlen) ? m_String : (m_String + (len - maxlen))); }
00226
00228 void PadToEnd (
00229 char item
00230 ) {
00231 for (int j = strlen(m_String);(j < _CT-1);++j) m_String[j] = item;
00232 m_String[_CT-1] = 0;
00233 }
00234
00236 void SetLowerCase (
00237 ) { strlwr(m_String); }
00238
00240 void SetUpperCase (
00241 ) { strupr(m_String); }
00242
00244 void Terminate (
00245 ) { m_String[_CT - 1] = 0; }
00246
00248 void Truncate (
00249 int NewLength
00250 ) { if (NewLength >= 0 && NewLength < (_CT - 1)) m_String[NewLength] = 0; }
00251
00252 protected:
00253 #ifndef GENERATING_DOXYGEN_OUTPUT
00254 char m_String[_CT];
00255 #endif // GENERATING_DOXYGEN_OUTPUT
00256 };
00257
00258 #endif // INC_MI32_FIXEDSTRCHAR_H
00259