103a78d15Sespie // Locale support (codecvt) -*- C++ -*- 203a78d15Sespie 303a78d15Sespie // Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 403a78d15Sespie // 503a78d15Sespie // This file is part of the GNU ISO C++ Library. This library is free 603a78d15Sespie // software; you can redistribute it and/or modify it under the 703a78d15Sespie // terms of the GNU General Public License as published by the 803a78d15Sespie // Free Software Foundation; either version 2, or (at your option) 903a78d15Sespie // any later version. 1003a78d15Sespie 1103a78d15Sespie // This library is distributed in the hope that it will be useful, 1203a78d15Sespie // but WITHOUT ANY WARRANTY; without even the implied warranty of 1303a78d15Sespie // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1403a78d15Sespie // GNU General Public License for more details. 1503a78d15Sespie 1603a78d15Sespie // You should have received a copy of the GNU General Public License along 1703a78d15Sespie // with this library; see the file COPYING. If not, write to the Free 1803a78d15Sespie // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 1903a78d15Sespie // USA. 2003a78d15Sespie 2103a78d15Sespie // As a special exception, you may use this file as part of a free software 2203a78d15Sespie // library without restriction. Specifically, if other files instantiate 2303a78d15Sespie // templates or use macros or inline functions from this file, or you compile 2403a78d15Sespie // this file and link it with other files to produce an executable, this 2503a78d15Sespie // file does not by itself cause the resulting executable to be covered by 2603a78d15Sespie // the GNU General Public License. This exception does not however 2703a78d15Sespie // invalidate any other reasons why the executable file might be covered by 2803a78d15Sespie // the GNU General Public License. 2903a78d15Sespie 3003a78d15Sespie // 3103a78d15Sespie // ISO C++ 14882: 22.2.1.5 Template class codecvt 3203a78d15Sespie // 3303a78d15Sespie 3403a78d15Sespie // Written by Benjamin Kosnik <bkoz@cygnus.com> 3503a78d15Sespie 3603a78d15Sespie /** @file codecvt.h 3703a78d15Sespie * This is an internal header file, included by other library headers. 3803a78d15Sespie * You should not attempt to use it directly. 3903a78d15Sespie */ 4003a78d15Sespie 4103a78d15Sespie #ifndef _CPP_BITS_CODECVT_H 4203a78d15Sespie #define _CPP_BITS_CODECVT_H 1 4303a78d15Sespie 4403a78d15Sespie #pragma GCC system_header 4503a78d15Sespie 4603a78d15Sespie // 22.2.1.5 Template class codecvt 4703a78d15Sespie class codecvt_base 4803a78d15Sespie { 4903a78d15Sespie public: 5003a78d15Sespie enum result 5103a78d15Sespie { 5203a78d15Sespie ok, 5303a78d15Sespie partial, 5403a78d15Sespie error, 5503a78d15Sespie noconv 5603a78d15Sespie }; 5703a78d15Sespie }; 5803a78d15Sespie 5903a78d15Sespie // Template class __codecvt_abstract_base 6003a78d15Sespie // NB: An abstract base class that fills in the public inlines, so 6103a78d15Sespie // that the specializations don't have to re-copy the public 6203a78d15Sespie // interface. 6303a78d15Sespie template<typename _InternT, typename _ExternT, typename _StateT> 6403a78d15Sespie class __codecvt_abstract_base 6503a78d15Sespie : public locale::facet, public codecvt_base 6603a78d15Sespie { 6703a78d15Sespie public: 6803a78d15Sespie // Types: 6903a78d15Sespie typedef codecvt_base::result result; 7003a78d15Sespie typedef _InternT intern_type; 7103a78d15Sespie typedef _ExternT extern_type; 7203a78d15Sespie typedef _StateT state_type; 7303a78d15Sespie 7403a78d15Sespie // 22.2.1.5.1 codecvt members 7503a78d15Sespie result out(state_type & __state,const intern_type * __from,const intern_type * __from_end,const intern_type * & __from_next,extern_type * __to,extern_type * __to_end,extern_type * & __to_next)7603a78d15Sespie out(state_type& __state, const intern_type* __from, 7703a78d15Sespie const intern_type* __from_end, const intern_type*& __from_next, 7803a78d15Sespie extern_type* __to, extern_type* __to_end, 7903a78d15Sespie extern_type*& __to_next) const 8003a78d15Sespie { 8103a78d15Sespie return this->do_out(__state, __from, __from_end, __from_next, 8203a78d15Sespie __to, __to_end, __to_next); 8303a78d15Sespie } 8403a78d15Sespie 8503a78d15Sespie result unshift(state_type & __state,extern_type * __to,extern_type * __to_end,extern_type * & __to_next)8603a78d15Sespie unshift(state_type& __state, extern_type* __to, extern_type* __to_end, 8703a78d15Sespie extern_type*& __to_next) const 8803a78d15Sespie { return this->do_unshift(__state, __to,__to_end,__to_next); } 8903a78d15Sespie 9003a78d15Sespie result in(state_type & __state,const extern_type * __from,const extern_type * __from_end,const extern_type * & __from_next,intern_type * __to,intern_type * __to_end,intern_type * & __to_next)9103a78d15Sespie in(state_type& __state, const extern_type* __from, 9203a78d15Sespie const extern_type* __from_end, const extern_type*& __from_next, 9303a78d15Sespie intern_type* __to, intern_type* __to_end, 9403a78d15Sespie intern_type*& __to_next) const 9503a78d15Sespie { 9603a78d15Sespie return this->do_in(__state, __from, __from_end, __from_next, 9703a78d15Sespie __to, __to_end, __to_next); 9803a78d15Sespie } 9903a78d15Sespie 10003a78d15Sespie int encoding()10103a78d15Sespie encoding() const throw() 10203a78d15Sespie { return this->do_encoding(); } 10303a78d15Sespie 10403a78d15Sespie bool always_noconv()10503a78d15Sespie always_noconv() const throw() 10603a78d15Sespie { return this->do_always_noconv(); } 10703a78d15Sespie 10803a78d15Sespie int length(const state_type & __state,const extern_type * __from,const extern_type * __end,size_t __max)10903a78d15Sespie length(const state_type& __state, const extern_type* __from, 11003a78d15Sespie const extern_type* __end, size_t __max) const 11103a78d15Sespie { return this->do_length(__state, __from, __end, __max); } 11203a78d15Sespie 11303a78d15Sespie int max_length()11403a78d15Sespie max_length() const throw() 11503a78d15Sespie { return this->do_max_length(); } 11603a78d15Sespie 11703a78d15Sespie protected: 11803a78d15Sespie explicit facet(__refs)11903a78d15Sespie __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { } 12003a78d15Sespie 12103a78d15Sespie virtual ~__codecvt_abstract_base()12203a78d15Sespie ~__codecvt_abstract_base() { } 12303a78d15Sespie 12403a78d15Sespie virtual result 12503a78d15Sespie do_out(state_type& __state, const intern_type* __from, 12603a78d15Sespie const intern_type* __from_end, const intern_type*& __from_next, 12703a78d15Sespie extern_type* __to, extern_type* __to_end, 12803a78d15Sespie extern_type*& __to_next) const = 0; 12903a78d15Sespie 13003a78d15Sespie virtual result 13103a78d15Sespie do_unshift(state_type& __state, extern_type* __to, 13203a78d15Sespie extern_type* __to_end, extern_type*& __to_next) const = 0; 13303a78d15Sespie 13403a78d15Sespie virtual result 13503a78d15Sespie do_in(state_type& __state, const extern_type* __from, 13603a78d15Sespie const extern_type* __from_end, const extern_type*& __from_next, 13703a78d15Sespie intern_type* __to, intern_type* __to_end, 13803a78d15Sespie intern_type*& __to_next) const = 0; 13903a78d15Sespie 14003a78d15Sespie virtual int 14103a78d15Sespie do_encoding() const throw() = 0; 14203a78d15Sespie 14303a78d15Sespie virtual bool 14403a78d15Sespie do_always_noconv() const throw() = 0; 14503a78d15Sespie 14603a78d15Sespie virtual int 14703a78d15Sespie do_length(const state_type&, const extern_type* __from, 14803a78d15Sespie const extern_type* __end, size_t __max) const = 0; 14903a78d15Sespie 15003a78d15Sespie virtual int 15103a78d15Sespie do_max_length() const throw() = 0; 15203a78d15Sespie }; 15303a78d15Sespie 15403a78d15Sespie // 22.2.1.5 Template class codecvt 15503a78d15Sespie // NB: Generic, mostly useless implementation. 15603a78d15Sespie template<typename _InternT, typename _ExternT, typename _StateT> 15703a78d15Sespie class codecvt 15803a78d15Sespie : public __codecvt_abstract_base<_InternT, _ExternT, _StateT> 15903a78d15Sespie { 16003a78d15Sespie public: 16103a78d15Sespie // Types: 16203a78d15Sespie typedef codecvt_base::result result; 16303a78d15Sespie typedef _InternT intern_type; 16403a78d15Sespie typedef _ExternT extern_type; 16503a78d15Sespie typedef _StateT state_type; 16603a78d15Sespie 16703a78d15Sespie public: 16803a78d15Sespie static locale::id id; 16903a78d15Sespie 17003a78d15Sespie explicit 17103a78d15Sespie codecvt(size_t __refs = 0) 17203a78d15Sespie : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs) { } 17303a78d15Sespie 17403a78d15Sespie protected: 17503a78d15Sespie virtual ~codecvt()17603a78d15Sespie ~codecvt() { } 17703a78d15Sespie 17803a78d15Sespie virtual result 17903a78d15Sespie do_out(state_type& __state, const intern_type* __from, 18003a78d15Sespie const intern_type* __from_end, const intern_type*& __from_next, 18103a78d15Sespie extern_type* __to, extern_type* __to_end, 18203a78d15Sespie extern_type*& __to_next) const; 18303a78d15Sespie 18403a78d15Sespie virtual result 18503a78d15Sespie do_unshift(state_type& __state, extern_type* __to, 18603a78d15Sespie extern_type* __to_end, extern_type*& __to_next) const; 18703a78d15Sespie 18803a78d15Sespie virtual result 18903a78d15Sespie do_in(state_type& __state, const extern_type* __from, 19003a78d15Sespie const extern_type* __from_end, const extern_type*& __from_next, 19103a78d15Sespie intern_type* __to, intern_type* __to_end, 19203a78d15Sespie intern_type*& __to_next) const; 19303a78d15Sespie 19403a78d15Sespie virtual int 19503a78d15Sespie do_encoding() const throw(); 19603a78d15Sespie 19703a78d15Sespie virtual bool 19803a78d15Sespie do_always_noconv() const throw(); 19903a78d15Sespie 20003a78d15Sespie virtual int 20103a78d15Sespie do_length(const state_type&, const extern_type* __from, 20203a78d15Sespie const extern_type* __end, size_t __max) const; 20303a78d15Sespie 20403a78d15Sespie virtual int 20503a78d15Sespie do_max_length() const throw(); 20603a78d15Sespie }; 20703a78d15Sespie 20803a78d15Sespie template<typename _InternT, typename _ExternT, typename _StateT> 20903a78d15Sespie locale::id codecvt<_InternT, _ExternT, _StateT>::id; 21003a78d15Sespie 21103a78d15Sespie // codecvt<char, char, mbstate_t> required specialization 21203a78d15Sespie template<> 21303a78d15Sespie class codecvt<char, char, mbstate_t> 21403a78d15Sespie : public __codecvt_abstract_base<char, char, mbstate_t> 21503a78d15Sespie { 21603a78d15Sespie public: 21703a78d15Sespie // Types: 21803a78d15Sespie typedef char intern_type; 21903a78d15Sespie typedef char extern_type; 22003a78d15Sespie typedef mbstate_t state_type; 22103a78d15Sespie 22203a78d15Sespie public: 22303a78d15Sespie static locale::id id; 22403a78d15Sespie 22503a78d15Sespie explicit 22603a78d15Sespie codecvt(size_t __refs = 0); 22703a78d15Sespie 22803a78d15Sespie protected: 22903a78d15Sespie virtual 23003a78d15Sespie ~codecvt(); 23103a78d15Sespie 23203a78d15Sespie virtual result 23303a78d15Sespie do_out(state_type& __state, const intern_type* __from, 23403a78d15Sespie const intern_type* __from_end, const intern_type*& __from_next, 23503a78d15Sespie extern_type* __to, extern_type* __to_end, 23603a78d15Sespie extern_type*& __to_next) const; 23703a78d15Sespie 23803a78d15Sespie virtual result 23903a78d15Sespie do_unshift(state_type& __state, extern_type* __to, 24003a78d15Sespie extern_type* __to_end, extern_type*& __to_next) const; 24103a78d15Sespie 24203a78d15Sespie virtual result 24303a78d15Sespie do_in(state_type& __state, const extern_type* __from, 24403a78d15Sespie const extern_type* __from_end, const extern_type*& __from_next, 24503a78d15Sespie intern_type* __to, intern_type* __to_end, 24603a78d15Sespie intern_type*& __to_next) const; 24703a78d15Sespie 24803a78d15Sespie virtual int 24903a78d15Sespie do_encoding() const throw(); 25003a78d15Sespie 25103a78d15Sespie virtual bool 25203a78d15Sespie do_always_noconv() const throw(); 25303a78d15Sespie 25403a78d15Sespie virtual int 25503a78d15Sespie do_length(const state_type&, const extern_type* __from, 25603a78d15Sespie const extern_type* __end, size_t __max) const; 25703a78d15Sespie 25803a78d15Sespie virtual int 25903a78d15Sespie do_max_length() const throw(); 26003a78d15Sespie }; 26103a78d15Sespie 262*c2fb3212Sespie #if defined(_GLIBCPP_USE_WCHAR_T) || defined(_GLIBCPP_USE_TYPE_WCHAR_T) 26303a78d15Sespie // codecvt<wchar_t, char, mbstate_t> required specialization 26403a78d15Sespie template<> 26503a78d15Sespie class codecvt<wchar_t, char, mbstate_t> 26603a78d15Sespie : public __codecvt_abstract_base<wchar_t, char, mbstate_t> 26703a78d15Sespie { 26803a78d15Sespie public: 26903a78d15Sespie // Types: 27003a78d15Sespie typedef wchar_t intern_type; 27103a78d15Sespie typedef char extern_type; 27203a78d15Sespie typedef mbstate_t state_type; 27303a78d15Sespie 27403a78d15Sespie public: 27503a78d15Sespie static locale::id id; 27603a78d15Sespie 27703a78d15Sespie explicit 27803a78d15Sespie codecvt(size_t __refs = 0); 27903a78d15Sespie 28003a78d15Sespie protected: 28103a78d15Sespie virtual 28203a78d15Sespie ~codecvt(); 28303a78d15Sespie 28403a78d15Sespie virtual result 28503a78d15Sespie do_out(state_type& __state, const intern_type* __from, 28603a78d15Sespie const intern_type* __from_end, const intern_type*& __from_next, 28703a78d15Sespie extern_type* __to, extern_type* __to_end, 28803a78d15Sespie extern_type*& __to_next) const; 28903a78d15Sespie 29003a78d15Sespie virtual result 29103a78d15Sespie do_unshift(state_type& __state, 29203a78d15Sespie extern_type* __to, extern_type* __to_end, 29303a78d15Sespie extern_type*& __to_next) const; 29403a78d15Sespie 29503a78d15Sespie virtual result 29603a78d15Sespie do_in(state_type& __state, 29703a78d15Sespie const extern_type* __from, const extern_type* __from_end, 29803a78d15Sespie const extern_type*& __from_next, 29903a78d15Sespie intern_type* __to, intern_type* __to_end, 30003a78d15Sespie intern_type*& __to_next) const; 30103a78d15Sespie 30203a78d15Sespie virtual 30303a78d15Sespie int do_encoding() const throw(); 30403a78d15Sespie 30503a78d15Sespie virtual 30603a78d15Sespie bool do_always_noconv() const throw(); 30703a78d15Sespie 30803a78d15Sespie virtual 30903a78d15Sespie int do_length(const state_type&, const extern_type* __from, 31003a78d15Sespie const extern_type* __end, size_t __max) const; 31103a78d15Sespie 31203a78d15Sespie virtual int 31303a78d15Sespie do_max_length() const throw(); 31403a78d15Sespie }; 31503a78d15Sespie #endif //_GLIBCPP_USE_WCHAR_T 31603a78d15Sespie 31703a78d15Sespie // 22.2.1.6 Template class codecvt_byname 31803a78d15Sespie template<typename _InternT, typename _ExternT, typename _StateT> 31903a78d15Sespie class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> 32003a78d15Sespie { 32103a78d15Sespie public: 32203a78d15Sespie explicit 32303a78d15Sespie codecvt_byname(const char*, size_t __refs = 0) 32403a78d15Sespie : codecvt<_InternT, _ExternT, _StateT>(__refs) { } 32503a78d15Sespie 32603a78d15Sespie protected: 32703a78d15Sespie virtual ~codecvt_byname()32803a78d15Sespie ~codecvt_byname() { } 32903a78d15Sespie }; 33003a78d15Sespie 33103a78d15Sespie // Include host and configuration specific partial specializations 33203a78d15Sespie // with additional functionality, if possible. 333*c2fb3212Sespie #if defined(_GLIBCPP_USE_WCHAR_T) || defined(_GLIBCPP_USE_TYPE_WCHAR_T) 33403a78d15Sespie #include <bits/codecvt_specializations.h> 33503a78d15Sespie #endif 33603a78d15Sespie 33703a78d15Sespie #endif // _CPP_BITS_CODECVT_H 338