00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ASTL_ALPHABET_H
00023 #define ASTL_ALPHABET_H
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <iterator>
00036 #include <string>
00037
00038 namespace astl {
00039
00040 using namespace std;
00041
00042 #if (__GNUG__ && __GNUG__ < 3)
00043 #define CHAR_TRAITS string_char_traits
00044 #else
00045 #define CHAR_TRAITS std::char_traits
00046 #endif
00047
00048 template <typename T, T lower_bound, T upper_bound>
00049 class range : public CHAR_TRAITS<T>
00050 {
00051 public:
00052 typedef typename CHAR_TRAITS<T>::char_type char_type;
00053 typedef long int_type;
00054 static const size_t size;
00055 static char_type to_char_type(int_type e) {
00056 return (char_type) (e + lower_bound);
00057 }
00058 static int_type to_int_type(char_type c) {
00059 return (int_type) c - lower_bound;
00060 }
00061 static bool eq_int_type(int_type x, int_type y) {
00062 return x == y;
00063 }
00064
00065 #if (__GNUG__ && __GNUG__ < 3)
00066 class const_iterator : public bidirectional_iterator<T, ptrdiff_t>
00067 #else
00068 class const_iterator
00069 : public std::iterator<std::bidirectional_iterator_tag, T>
00070 #endif
00071 {
00072 private:
00073 int_type c;
00074
00075 public:
00076 const_iterator()
00077 { }
00078
00079 const_iterator(int_type x)
00080 : c(x)
00081 { }
00082
00083 const_iterator& operator++ () {
00084 ++c;
00085 return (*this);
00086 }
00087
00088 const_iterator operator++ (int) {
00089 const_iterator tmp = *this;
00090 ++(*this);
00091 return (tmp);
00092 }
00093
00094 char_type operator* () const {
00095 return (char_type) c;
00096 }
00097
00098 bool operator== (const const_iterator& i) const {
00099 return c == i.c;
00100 }
00101
00102 bool operator!= (const const_iterator& i) const {
00103 return !(*this == i);
00104 }
00105 };
00106
00107 static const_iterator begin() { return const_iterator(lower_bound); }
00108 static const_iterator end() { return const_iterator(upper_bound + 1); }
00109
00110 static bool lt(const char_type &x, const char_type &y) {
00111 return x < y;
00112 }
00113
00114 static bool eq(const char_type &x, const char_type &y) {
00115 return x == y;
00116 }
00117
00118
00119 typedef const_iterator iterator;
00120 typedef char_type Alphabet;
00121 static unsigned long map(const char_type &x) {
00122 return (unsigned long) to_int_type(x);
00123 }
00124 static char_type unmap(unsigned long x) {
00125 return to_char_type((int_type) x);
00126 }
00127 };
00128
00129 template <typename T, T lower_bound, T upper_bound> const size_t
00130 range<T, lower_bound, upper_bound>::size = (size_t) upper_bound - lower_bound + 1;
00131
00132 typedef range<char, (char) -128, (char) 127> plain;
00133 typedef range<unsigned char, (unsigned char) 0, (unsigned char) 255> uplain;
00134 typedef range<char, (char) 0, (char) 127> ASCII;
00135 typedef std::char_traits<wchar_t> unicode;
00136
00137 class strings : public CHAR_TRAITS<string>
00138 {
00139 public:
00140 typedef string char_type;
00141 typedef long int_type;
00142 static const size_t size;
00143
00144 static bool eq(const char_type &x, const char_type &y) {
00145 return x == y;
00146 }
00147
00148 static bool lt(const char_type &x, const char_type &y) {
00149 return x < y;
00150 }
00151 };
00152
00153 class ucs2
00154 {
00155 public:
00156 typedef unsigned short char_type;
00157 typedef unsigned short int_type;
00158 static const size_t size = 65536;
00159
00160 static bool eq(const char_type &x, const char_type &y) {
00161 return x == y;
00162 }
00163
00164 static bool lt(const char_type &x, const char_type &y) {
00165 return x < y;
00166 }
00167 };
00168
00169 #ifdef _MSC_VER
00170
00171
00172
00173
00174
00175 #endif
00176
00177 }
00178
00179 #endif // ASTL_ALPHABET_H
00180
00181
00182
00183
00184
00185
00186