Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Examples  

bit_char_traits.h

Go to the documentation of this file.
00001 // Bit Character Traits for use by standard string and iostream -*- C++ -*-
00002 
00003 // This file is a modification of of the GNU ISO C++ Library. char_traits 
00004 // Double check licensing restrictions (should be ok)
00005 
00011 #ifndef _BIT_CHAR_TRAITS_H
00012 #define _BIT_CHAR_TRAITS_H
00013 
00014 #include <bitset>
00015 #include <bits/fpos.h>          // For streampos
00016 #include <cassert>
00017 
00018 namespace std 
00019 {
00020 
00021 
00025   template<size_t NB>
00026     struct char_traits<bitset<NB> >
00027     {
00028       typedef bitset<NB>        char_type;
00029       typedef std::size_t       int_type;
00030       typedef streampos         pos_type;
00031       typedef streamoff         off_type;
00032       typedef mbstate_t         state_type;
00033 
00034       static void 
00035       assign(char_type& __c1, const char_type& __c2)
00036       { __c1 = __c2; }
00037 
00038       static bool 
00039       eq(const char_type& __c1, const char_type& __c2)
00040       { return __c1.to_ulong() == __c2.to_ulong(); }
00041 
00042       static bool 
00043       lt(const char_type& __c1, const char_type& __c2)
00044       { return __c1.to_ulong() < __c2.to_ulong(); }
00045 
00046       static int 
00047       compare(const char_type* __s1, const char_type* __s2, size_t __n)
00048       { 
00049         const char_type *su1, *su2;
00050         int res = 0;
00051 
00052         for( su1 = __s1, su2 = __s2; 0 < __n; ++su1, ++su2, __n--)
00053                 if ((res = su1->to_ulong() - su2->to_ulong()) != 0)
00054                         break;
00055         return res;
00056 
00057       }
00058 
00059       static size_t
00060       length(const char_type* __s)
00061       { 
00062         assert(0); return 0;
00063 #if 0
00064         const char_type* sc;
00065 
00066         for (sc = s; *sc != '\0'; ++sc)
00067                 /* nothing */;
00068         return sc - s;
00069         return strlen(__s); 
00070 #endif
00071       }
00072 
00073       static const char_type* 
00074       find(const char_type* __s, size_t __n, const char_type& __a)
00075       { 
00076         const char_type* p = __s;
00077         while (__n-- ) {
00078           if (eq(__c,*p++)) {
00079             return (p-1);
00080           }
00081         }
00082         return NULL;
00083       }
00084 
00085         //assert(0); return static_cast<const char_type*>(memchr(__s, __a, __n)); }
00086 
00087       static char_type* 
00088       move(char_type* __s1, const char_type* __s2, size_t __n)
00089       { assert(0); return NULL; }
00090       //return static_cast<char_type*>(memmove(__s1, __s2, __n)); }
00091 
00092       static char_type* 
00093       copy(char_type* __s1, const char_type* __s2, size_t __n)
00094       {  
00095         while(__n--) {
00096           *__s1 = *__s2;
00097           ++__s1;
00098           ++__s2;
00099         }
00100         return __s1;
00101       }
00102 
00103       static char_type* 
00104       assign(char_type* __s, size_t __n, char_type __a) {
00105         while(__n--)
00106           *(__s)++ = __a;
00107         return __s;
00108       }
00109 
00110       static char_type 
00111       to_char_type(const int_type& __c)
00112       { return static_cast<char_type>(__c); }
00113 
00114       // To keep both the byte 0xff and the eof symbol 0xffffffff
00115       // from ending up as 0xffffffff.
00116       static int_type 
00117       to_int_type(const char_type& __c)
00118       { return static_cast<int_type>(__c.to_ulong()); }
00119 
00120       static bool 
00121       eq_int_type(const int_type& __c1, const int_type& __c2)
00122       { return __c1 == __c2; }
00123 
00124       static int_type 
00125       eof() { return static_cast<int_type>(EOF); }
00126 
00127       static int_type 
00128       not_eof(const int_type& __c)
00129       { return (__c == eof()) ? 0 : __c; }
00130   };
00131 
00132 
00133 } // namespace std
00134 
00135 #endif