home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _collate.h < prev    next >
C/C++ Source or Header  |  2001-01-26  |  5KB  |  183 lines

  1. /*
  2.  * Copyright (c) 1999
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Copyright (c) 1999 
  6.  * Boris Fomitchev
  7.  *
  8.  * This material is provided "as is", with absolutely no warranty expressed
  9.  * or implied. Any use is at your own risk.
  10.  *
  11.  * Permission to use or copy this software for any purpose is hereby granted 
  12.  * without fee, provided the above notices are retained on all copies.
  13.  * Permission to modify the code and to distribute modified code is granted,
  14.  * provided the above notices are retained, and a notice that the code was
  15.  * modified is included with the above copyright notice.
  16.  *
  17.  */ 
  18. // WARNING: This is an internal header file, included by other C++
  19. // standard library headers.  You should not attempt to use this header
  20. // file directly.
  21.  
  22. #ifndef _STLP_INTERNAL_COLLATE_H
  23. #define _STLP_INTERNAL_COLLATE_H
  24.  
  25. #ifndef _STLP_C_LOCALE_H
  26. # include <stl/c_locale.h>
  27. #endif
  28.  
  29. #ifndef _STLP_INTERNAL_LOCALE_H
  30. # include <stl/_locale.h>
  31. #endif
  32.  
  33. #ifndef _STLP_STRING_H
  34. # include <stl/_string.h>
  35. #endif
  36.  
  37. _STLP_BEGIN_NAMESPACE
  38.  
  39.  
  40. template <class _CharT> class collate {};
  41. template <class _CharT> class collate_byname {};
  42.  
  43. _STLP_TEMPLATE_NULL
  44. class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet 
  45. {
  46.   friend class _Locale;
  47. public:
  48.   typedef char   char_type;
  49.   typedef string string_type;
  50.  
  51.   explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
  52.  
  53.   int compare(const char* __low1, const char* __high1,
  54.               const char* __low2, const char* __high2) const {
  55.     return do_compare( __low1, __high1, __low2, __high2);
  56.   }
  57.  
  58.   string_type transform(const char* __low, const char* __high) const {
  59.     return do_transform(__low, __high);
  60.   }
  61.  
  62.   long hash(const char* __low, const char* __high) const
  63.     { return do_hash(__low, __high); }
  64.  
  65.   _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
  66.  
  67. protected:
  68.   ~collate();
  69.  
  70.   virtual int do_compare(const char*, const char*,
  71.                          const char*, const char*) const;
  72.   virtual string_type do_transform(const char*, const char*) const;
  73.   virtual long do_hash(const char*, const char*) const;
  74. private:
  75.   collate(const collate<char>&);
  76.   collate<char>& operator =(const collate<char>&);  
  77. };
  78.  
  79. # ifndef _STLP_NO_WCHAR_T
  80.  
  81. _STLP_TEMPLATE_NULL
  82. class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet 
  83. {
  84.   friend class _Locale;
  85. public:
  86.   typedef wchar_t char_type;
  87.   typedef wstring string_type;
  88.  
  89.   explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
  90.  
  91.   int compare(const wchar_t* __low1, const wchar_t* __high1,
  92.               const wchar_t* __low2, const wchar_t* __high2) const {
  93.     return do_compare( __low1, __high1, __low2, __high2);
  94.   }
  95.  
  96.   string_type transform(const wchar_t* __low, const wchar_t* __high) const {
  97.     return do_transform(__low, __high);
  98.   }
  99.  
  100.   long hash(const wchar_t* __low, const wchar_t* __high) const
  101.     { return do_hash(__low, __high); }
  102.  
  103.   _STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
  104.  
  105. protected:
  106.   ~collate();
  107.  
  108.   virtual int do_compare(const wchar_t*, const wchar_t*,
  109.                          const wchar_t*, const wchar_t*) const;
  110.   virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
  111.   virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
  112. private:
  113.   collate(const collate<wchar_t>&);
  114.   collate<wchar_t>& operator = (const collate<wchar_t>&);  
  115. };
  116.  
  117. # endif /* NO_WCHAR_T */
  118.  
  119. _STLP_TEMPLATE_NULL
  120. class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char> 
  121. {
  122. public:
  123.   explicit collate_byname(const char* __name, size_t __refs = 0);
  124.  
  125. protected:
  126.   ~collate_byname();
  127.  
  128.   virtual int do_compare(const char*, const char*,
  129.                          const char*, const char*) const;
  130.   virtual string_type do_transform(const char*, const char*) const;
  131.  
  132. private:
  133.   _Locale_collate* _M_collate;
  134.   collate_byname(const collate_byname<char>&);
  135.   collate_byname<char>& operator =(const collate_byname<char>&);  
  136. };
  137.  
  138. # ifndef _STLP_NO_WCHAR_T
  139.  
  140. _STLP_TEMPLATE_NULL
  141. class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t> 
  142. {
  143. public:
  144.   explicit collate_byname(const char * __name, size_t __refs = 0);
  145.  
  146. protected:
  147.   ~collate_byname();
  148.  
  149.   virtual int do_compare(const wchar_t*, const wchar_t*,
  150.                          const wchar_t*, const wchar_t*) const;
  151.   virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
  152.  
  153. private:
  154.   _Locale_collate* _M_collate;
  155.   collate_byname(const collate_byname<wchar_t>&);
  156.   collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);  
  157. };
  158.  
  159. # endif /* NO_WCHAR_T */
  160.  
  161.  
  162. template <class _CharT>
  163. bool 
  164. __locale_do_operator_call (const locale* __that, 
  165.                            const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __x,
  166.                            const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __y) 
  167. {
  168.   collate<_CharT>* __f = (collate<_CharT>*)__that->_M_get_facet(collate<_CharT>::id);
  169.   if (!__f)
  170.     __that->_M_throw_runtime_error();
  171.   return __f->compare(__x.data(), __x.data() + __x.size(),
  172.                       __y.data(), __y.data() + __y.size());
  173.   
  174. }
  175.  
  176. _STLP_END_NAMESPACE
  177.  
  178. #endif /* _STLP_INTERNAL_COLLATE_H */
  179.  
  180. // Local Variables:
  181. // mode:C++
  182. // End:
  183.