libstdc++
codecvt
Go to the documentation of this file.
00001 // <codecvt> -*- C++ -*-
00002 
00003 // Copyright (C) 2015 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 // ISO C++ 14882: 22.5  Standard code conversion facets
00026 
00027 /** @file include/codecvt
00028  *  This is a Standard C++ Library header.
00029  */
00030 
00031 #ifndef _GLIBCXX_CODECVT
00032 #define _GLIBCXX_CODECVT 1
00033 
00034 #pragma GCC system_header
00035 
00036 #if __cplusplus < 201103L
00037 # include <bits/c++0x_warning.h>
00038 #else
00039 
00040 #include <bits/locale_classes.h>
00041 #include <bits/codecvt.h>
00042 
00043 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
00044 
00045 namespace std _GLIBCXX_VISIBILITY(default)
00046 {
00047 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00048 
00049   enum codecvt_mode
00050   {
00051     consume_header = 4,
00052     generate_header = 2,
00053     little_endian = 1
00054   };
00055 
00056   template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
00057            codecvt_mode _Mode = (codecvt_mode)0>
00058     class codecvt_utf8 : public codecvt<_Elem, char, mbstate_t>
00059     {
00060     public:
00061       explicit
00062       codecvt_utf8(size_t __refs = 0);
00063 
00064       ~codecvt_utf8();
00065     };
00066 
00067   template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
00068            codecvt_mode _Mode = (codecvt_mode)0>
00069     class codecvt_utf16 : public codecvt<_Elem, char, mbstate_t>
00070     {
00071     public:
00072       explicit
00073       codecvt_utf16(size_t __refs = 0);
00074 
00075       ~codecvt_utf16();
00076     };
00077 
00078   template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
00079            codecvt_mode _Mode = (codecvt_mode)0>
00080     class codecvt_utf8_utf16 : public codecvt<_Elem, char, mbstate_t>
00081     {
00082     public:
00083       explicit
00084       codecvt_utf8_utf16(size_t __refs = 0);
00085 
00086       ~codecvt_utf8_utf16();
00087     };
00088 
00089 #define _GLIBCXX_CODECVT_SPECIALIZATION2(_NAME, _ELEM) \
00090   template<> \
00091     class _NAME<_ELEM> \
00092     : public codecvt<_ELEM, char, mbstate_t> \
00093     { \
00094     public: \
00095       typedef _ELEM                     intern_type; \
00096       typedef char                      extern_type; \
00097       typedef mbstate_t                 state_type; \
00098  \
00099     protected: \
00100       _NAME(unsigned long __maxcode, codecvt_mode __mode, size_t __refs) \
00101       : codecvt(__refs), _M_maxcode(__maxcode), _M_mode(__mode) { } \
00102  \
00103       virtual \
00104       ~_NAME(); \
00105  \
00106       virtual result \
00107       do_out(state_type& __state, const intern_type* __from, \
00108              const intern_type* __from_end, const intern_type*& __from_next, \
00109              extern_type* __to, extern_type* __to_end, \
00110              extern_type*& __to_next) const; \
00111  \
00112       virtual result \
00113       do_unshift(state_type& __state, \
00114                  extern_type* __to, extern_type* __to_end, \
00115                  extern_type*& __to_next) const; \
00116  \
00117       virtual result \
00118       do_in(state_type& __state, \
00119              const extern_type* __from, const extern_type* __from_end, \
00120              const extern_type*& __from_next, \
00121              intern_type* __to, intern_type* __to_end, \
00122              intern_type*& __to_next) const; \
00123  \
00124       virtual \
00125       int do_encoding() const throw(); \
00126  \
00127       virtual \
00128       bool do_always_noconv() const throw(); \
00129  \
00130       virtual \
00131       int do_length(state_type&, const extern_type* __from, \
00132                     const extern_type* __end, size_t __max) const; \
00133  \
00134       virtual int \
00135       do_max_length() const throw(); \
00136  \
00137     private: \
00138       unsigned long     _M_maxcode; \
00139       codecvt_mode      _M_mode; \
00140     }
00141 
00142 #define _GLIBCXX_CODECVT_SPECIALIZATION(_NAME, _ELEM) \
00143   _GLIBCXX_CODECVT_SPECIALIZATION2(__ ## _NAME ## _base, _ELEM); \
00144   template<unsigned long _Maxcode, codecvt_mode _Mode> \
00145     class _NAME<_ELEM, _Maxcode, _Mode> \
00146     : public __ ## _NAME ## _base<_ELEM> \
00147     { \
00148     public: \
00149       explicit \
00150       _NAME(size_t __refs = 0) \
00151       : __ ## _NAME ## _base<_ELEM>(std::min(_Maxcode, 0x10fffful), \
00152                                     _Mode, __refs) \
00153       { } \
00154     }
00155 
00156   template<typename _Elem> class __codecvt_utf8_base;
00157   template<typename _Elem> class __codecvt_utf16_base;
00158   template<typename _Elem> class __codecvt_utf8_utf16_base;
00159 
00160   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char16_t);
00161   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char16_t);
00162   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char16_t);
00163 
00164   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char32_t);
00165   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char32_t);
00166   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char32_t);
00167 
00168 #ifdef _GLIBCXX_USE_WCHAR_T
00169   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, wchar_t);
00170   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, wchar_t);
00171   _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, wchar_t);
00172 #endif
00173 
00174 _GLIBCXX_END_NAMESPACE_VERSION
00175 } // namespace
00176 
00177 #endif // _GLIBCXX_USE_C99_STDINT_TR1
00178 
00179 #endif
00180 
00181 #endif /* _GLIBCXX_CODECVT */