00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00030 #include <string>
00031
00032 namespace ss {
00033
00039 class byte {
00040 public:
00041
00042 byte () : value(0) {}
00043
00044 byte (byte const& that) : value(that.value) {}
00045
00046 byte (int i) : value(static_cast<unsigned char>(i)) {}
00047
00048 byte
00049 operator= (byte const& that) {
00050 value = that.value;
00051 return *this;
00052 }
00053
00054 bool
00055 operator== (byte const& that) const {
00056 return value == that.value;
00057 }
00058
00059 bool
00060 operator< (byte const& that) const {
00061 return value < that.value;
00062 }
00063
00064 operator unsigned int() const {
00065 return static_cast<unsigned int>(value);
00066 }
00067
00068 private:
00069 unsigned char value;
00070 };
00071
00072 }
00073
00074 namespace std {
00075
00076 template <>
00077 struct char_traits<ss::byte> {
00078
00079 typedef ss::byte char_type;
00080
00081 typedef unsigned int int_type;
00082
00083 typedef streampos pos_type;
00084 typedef streamoff off_type;
00085 typedef mbstate_t state_type;
00086
00087 static void
00088 assign (char_type& c1, char_type const& c2) {
00089 c1 = c2;
00090 }
00091
00092 static bool
00093 eq (char_type const& c1, char_type const& c2) {
00094 return c1 == c2;
00095 }
00096
00097 static bool
00098 lt (char_type const& c1, char_type const& c2) {
00099 return c1 < c2;
00100 }
00101
00102 static int
00103 compare (char_type const* s1, char_type const* s2, size_t n) {
00104 for (size_t i = 0; i < n; ++i)
00105 if (!eq(s1[i], s2[i]))
00106 return lt(s1[i], s2[i]) ? -1 : 1;
00107 return 0;
00108 }
00109
00110 static size_t
00111 length (char_type const* s) {
00112 char_type const* p = s;
00113 while (*p) ++p;
00114 return (p - s);
00115 }
00116
00117 static char_type const*
00118 find (char_type const* s, size_t n, char_type const& c) {
00119 for (char_type const* p = s; size_t(p - s) < n; ++p)
00120 if (*p == c)
00121 return p;
00122 return 0;
00123 }
00124
00125 static char_type*
00126 move (char_type* s1, char_type const* s2, size_t n) {
00127 return reinterpret_cast<char_type*>(
00128 memmove(s1, s2, n * sizeof(char_type))
00129 );
00130 }
00131
00132 static char_type*
00133 copy (char_type* s1, char_type const* s2, size_t n) {
00134 return reinterpret_cast<char_type*>(
00135 memcpy(s1, s2, n * sizeof(char_type))
00136 );
00137 }
00138
00139 static char_type*
00140 assign (char_type* s, size_t n, char_type const& c) {
00141 for (char_type* p = s; p < s + n; ++p)
00142 assign(*p, c);
00143 return s;
00144 }
00145
00146 static char_type
00147 to_char_type (int_type const& c) { return char_type(c); }
00148
00149 static int_type
00150 to_int_type (char_type const& c) { return int_type(c); }
00151
00152 static bool
00153 eq_int_type (int_type const& c1, int_type const& c2) {
00154 return c1 == c2;
00155 }
00156
00157 static int_type
00158 eof () { return static_cast<int_type>(-1); }
00159
00160 static int_type
00161 not_eof (int_type const& c) {
00162 return eq_int_type(c, eof()) ? int_type(0) : c;
00163 }
00164
00165 };
00166
00167 }
00168