BasicChar.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2009  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_BasicChar_hxx
00024 #define __ccxx_BasicChar_hxx
00025 
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/CharTraits.h++>
00028 
00029 namespace ccxx {
00030 
00036 template<typename T> class BasicChar
00037 {
00038   public:
00039 
00041   BasicChar(T c = BasicCharTraits<T>::nul())
00042     : _char(c)
00043   { }
00044 
00046   BasicChar(const BasicChar &other)
00047     : _char(other._char)
00048   { }
00049 
00051   virtual ~BasicChar() throw() { }
00052 
00054   inline bool isAlpha() const throw()
00055   { return(BasicCharTraits<T>::isAlpha(_char)); }
00056 
00058   inline bool isAlphaNumeric() const throw()
00059   { return(isAlpha() || isDigit()); }
00060 
00062   inline bool isWhitespace() const throw()
00063   { return(BasicCharTraits<T>::isWhitespace(_char)); }
00064 
00066   inline bool isPrintable() const throw()
00067   { return(BasicCharTraits<T>::isPrintable(_char)); }
00068 
00070   inline bool isGraphical() const throw()
00071   { return(BasicCharTraits<T>::isGraphical(_char)); }
00072 
00074   inline bool isNul() const throw()
00075   { return(BasicCharTraits<T>::isNul(_char)); }
00076 
00078   inline bool isControl() const throw()
00079   { return(BasicCharTraits<T>::isControl(_char)); }
00080 
00082   inline bool isDigit() const throw()
00083   { return(BasicCharTraits<T>::isDigit(_char)); }
00084 
00086   bool isHexDigit() const throw()
00087   { return(BasicCharTraits<T>::isHexDigit(_char)); }
00088 
00090   bool isLowerCase() const throw()
00091   { return(BasicCharTraits<T>::isLowerCase(_char)); }
00092 
00094   bool isUpperCase() const throw()
00095   { return(BasicCharTraits<T>::isUpperCase(_char)); }
00096 
00098   bool isASCII() const throw()
00099   { return((_char | 0x80) == 0); }
00100 
00102   bool isHighASCII() const throw()
00103   { return((_char & 0x80) != 0); }
00104 
00106   BasicChar<T> upperCase() const throw()
00107   { return(BasicChar<T>(BasicCharTraits<T>::toUpperCase(_char))); }
00108 
00110   BasicChar<T> lowerCase() const throw()
00111   { return(BasicChar<T>(BasicCharTraits<T>::toLowerCase(_char))); }
00112 
00114   inline BasicChar<T>& toUpperCase() throw()
00115   {
00116     _char = BasicCharTraits<T>::toUpperCase(_char);
00117     return(*this);
00118   }
00119 
00121   inline BasicChar<T>& toLowerCase() throw()
00122   {
00123     _char = BasicCharTraits<T>::toLowerCase(_char);
00124     return(*this);
00125   }
00126 
00128   inline BasicChar<T>& operator++() throw()
00129   {
00130     ++_char;
00131     return(*this);
00132   }
00133 
00135   inline BasicChar<T> operator++(int) throw()
00136   { return(BasicChar<T>(_char++)); }
00137 
00139   inline BasicChar<T>& operator--() throw()
00140   {
00141     --_char;
00142     return(*this);
00143   }
00144 
00146   inline BasicChar<T> operator--(int) throw()
00147   { return(BasicChar<T>(_char--)); }
00148 
00150   BasicChar<T>& operator=(T other) throw()
00151   {
00152     _char = other;
00153     return(*this);
00154   }
00155 
00157   BasicChar<T>& operator=(int other) throw()
00158   {
00159     _char = static_cast<T>(other);
00160     return(*this);
00161   }
00162 
00163   bool operator==(T other) const throw()
00164   { return(_char == other); }
00165 
00166   bool operator!=(T other) const throw()
00167   { return(_char != other); }
00168 
00169   bool operator<(T other) const throw()
00170   { return(_char < other); }
00171 
00172   bool operator>(T other) const throw()
00173   { return(_char > other); }
00174 
00175   bool operator<=(T other) const throw()
00176   { return(_char <= other); }
00177 
00178   bool operator>=(T other) const throw()
00179   { return(_char >= other); }
00180 
00181   bool operator==(const BasicChar<T> &other) const throw()
00182   { return(_char == other._char); }
00183 
00184   bool operator!=(const BasicChar<T> &other) const throw()
00185   { return(_char != other._char); }
00186 
00187   bool operator<(const BasicChar<T> &other) const throw()
00188   { return(_char < other._char); }
00189 
00190   bool operator>(const BasicChar<T> &other) const throw()
00191   { return(_char > other._char); }
00192 
00193   bool operator<=(const BasicChar<T> &other) const throw()
00194   { return(_char <= other._char); }
00195 
00196   bool operator>=(const BasicChar<T> &other) const throw()
00197   { return(_char >= other._char); }
00198 
00204   inline bool operator!() const throw()
00205   { return(! isNul()); }
00206 
00208   inline operator T() const throw()
00209   { return(toCharType()); }
00210 
00212   inline T toCharType() const throw()
00213   { return(_char); }
00214 
00216   static COMMONCPP_API const BasicChar<T> EndOfFile;
00217 
00219   static COMMONCPP_API const BasicChar<T> Bell;
00220 
00222   static COMMONCPP_API const BasicChar<T> Backspace;
00223 
00225   static COMMONCPP_API const BasicChar<T> Tab;
00226 
00228   static COMMONCPP_API const BasicChar<T> NewLine;
00229 
00231   static COMMONCPP_API const BasicChar<T> VTab;
00232 
00234   static COMMONCPP_API const BasicChar<T> FormFeed;
00235 
00237   static COMMONCPP_API const BasicChar<T> Return;
00238 
00240   static COMMONCPP_API const BasicChar<T> Escape;
00241 
00243   static COMMONCPP_API const BasicChar<T> Space;
00244 
00246   static COMMONCPP_API const BasicChar<T> Delete;
00247 
00248   private:
00249 
00250   char _char;
00251 };
00252 
00253 template<typename T> inline bool operator==(T c1, const BasicChar<T> &c2)
00254 { return(c1 == c2.toCharType()); }
00255 
00256 template<typename T> inline bool operator!=(T c1, const BasicChar<T> &c2)
00257 { return(c1 != c2.toChar()); }
00258 
00259 template<typename T> inline bool operator<(T c1, const BasicChar<T> &c2)
00260 { return(c1 < c2.toCharType()); }
00261 
00262 template<typename T> inline bool operator<=(T c1, const BasicChar<T> &c2)
00263 { return(c1 <= c2.toCharType()); }
00264 
00265 template<typename T> inline bool operator>(T c1, const BasicChar<T> &c2)
00266 { return(c1 > c2.toCharType()); }
00267 
00268 template<typename T> inline bool operator>=(T c1, const BasicChar<T> &c2)
00269 { return(c1 >= c2.toCharType()); }
00270 
00271 typedef BasicChar<char> Char;
00272 typedef BasicChar<wchar_t> WChar;
00273 
00274 }; // namespace ccxx
00275 
00276 #endif // __ccxx_BasicChar_hxx
00277 
00278 /* end of header file */

Generated on Sat Apr 17 23:03:05 2010 for libcommonc++ by  doxygen 1.5.9