1 // Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING.  If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18 
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction.  Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License.  This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27 
28 // Written by Benjamin Kosnik <[email protected]>
29 
30 #include <locale>
31 
32 namespace std
33 {
34   // Definitions for locale::id of standard facets that are specialized.
35  locale::id codecvt<char, char, mbstate_t>::id;
36 
37 #ifdef _GLIBCPP_USE_WCHAR_T
38   locale::id codecvt<wchar_t, char, mbstate_t>::id;
39 #endif
40 
41 #ifdef _GLIBCPP_USE___ENC_TRAITS
42   // Definitions for static const data members of __enc_traits.
43   const int __enc_traits::_S_max_size;
44 #endif
45 
46   codecvt<char, char, mbstate_t>::
47   codecvt(size_t __refs)
48   : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
49   { }
50 
51   codecvt<char, char, mbstate_t>::
52   ~codecvt()
53   { }
54 
55   codecvt_base::result
56   codecvt<char, char, mbstate_t>::
57   do_out(state_type&, const intern_type* __from,
58 	 const intern_type*, const intern_type*& __from_next,
59 	 extern_type* __to, extern_type*,
60 	 extern_type*& __to_next) const
61   {
62     // _GLIBCPP_RESOLVE_LIB_DEFECTS
63     // According to the resolution of DR19, "If returns noconv [...]
64     // there are no changes to the values in [to, to_limit)."
65     __from_next = __from;
66     __to_next = __to;
67     return noconv;
68   }
69 
70   codecvt_base::result
71   codecvt<char, char, mbstate_t>::
72   do_unshift(state_type&, extern_type* __to,
73              extern_type*, extern_type*& __to_next) const
74   {
75     __to_next = __to;
76     return noconv;
77   }
78 
79   codecvt_base::result
80   codecvt<char, char, mbstate_t>::
81   do_in(state_type&, const extern_type* __from,
82 	const extern_type*, const extern_type*& __from_next,
83 	intern_type* __to, intern_type*,
84 	intern_type*& __to_next) const
85   {
86     // _GLIBCPP_RESOLVE_LIB_DEFECTS
87     // According to the resolution of DR19, "If returns noconv [...]
88     // there are no changes to the values in [to, to_limit)."
89     __from_next = __from;
90     __to_next = __to;
91     return noconv;
92   }
93 
94   int
95   codecvt<char, char, mbstate_t>::
96   do_encoding() const throw()
97   { return 1; }
98 
99   bool
100   codecvt<char, char, mbstate_t>::
101   do_always_noconv() const throw()
102   { return true; }
103 
104   int
105   codecvt<char, char, mbstate_t>::
106   do_length (const state_type&, const extern_type* __from,
107 	     const extern_type* __end, size_t __max) const
108   { return min(__max, static_cast<size_t>(__end - __from)); }
109 
110   int
111   codecvt<char, char, mbstate_t>::
112   do_max_length() const throw()
113   { return 1; }
114 
115 #ifdef _GLIBCPP_USE_WCHAR_T
116   // codecvt<wchar_t, char, mbstate_t> required specialization
117   codecvt<wchar_t, char, mbstate_t>::
118   codecvt(size_t __refs)
119   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
120   { }
121 
122   codecvt<wchar_t, char, mbstate_t>::
123   ~codecvt()
124   { }
125 
126   codecvt_base::result
127   codecvt<wchar_t, char, mbstate_t>::
128   do_unshift(state_type&, extern_type* __to,
129 	     extern_type*, extern_type*& __to_next) const
130   {
131     __to_next = __to;
132     return noconv;
133   }
134 
135   int
136   codecvt<wchar_t, char, mbstate_t>::
137   do_encoding() const throw()
138   { return sizeof(wchar_t); }
139 
140   bool
141   codecvt<wchar_t, char, mbstate_t>::
142   do_always_noconv() const throw()
143   { return false; }
144 
145   int
146   codecvt<wchar_t, char, mbstate_t>::
147   do_length(const state_type&, const extern_type* __from,
148 	    const extern_type* __end, size_t __max) const
149   { return min(__max, static_cast<size_t>(__end - __from)); }
150 
151   int
152   codecvt<wchar_t, char, mbstate_t>::
153   do_max_length() const throw()
154   { return 1; }
155 #endif //  _GLIBCPP_USE_WCHAR_T
156 } // namespace std
157