1 // Copyright (C) 2003-2013 Free Software Foundation, Inc.
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 3, or (at your option)
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.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 27.8.1.4 Overridden virtual functions
22 #include <testsuite_hooks.h>
28 struct MyCharTraits : std::char_traits<wchar_t>
30 typedef std::fpos<MyState> pos_type;
31 typedef MyState state_type;
37 class codecvt<wchar_t, char, MyState> :
38 public locale::facet, public codecvt_base
41 typedef wchar_t intern_type;
42 typedef char extern_type;
43 typedef MyState state_type;
45 explicit codecvt(size_t refs = 0)
46 : locale::facet(refs) { }
48 result out(state_type& state, const intern_type* from,
49 const intern_type* from_end, const intern_type*& from_next,
50 extern_type* to, extern_type* to_limit,
51 extern_type*& to_next) const
52 { return do_out(state, from, from_end, from_next,
53 to, to_limit, to_next); }
55 result unshift(state_type& state, extern_type* to, extern_type* to_limit,
56 extern_type*& to_next) const
57 { return do_unshift(state, to, to_limit, to_next); }
59 result in(state_type& state, const extern_type* from,
60 const extern_type* from_end, const extern_type*& from_next,
61 intern_type* to, intern_type* to_limit,
62 intern_type*& to_next) const
63 { return do_in(state, from, from_end, from_next,
64 to, to_limit, to_next); }
66 int encoding() const throw()
67 { return do_encoding(); }
69 bool always_noconv() const throw()
70 { return do_always_noconv(); }
72 int length(state_type& state, const extern_type* from,
73 const extern_type* end, size_t max) const
74 { return do_length(state, from, end, max); }
76 int max_length() const throw()
77 { return do_max_length(); }
84 virtual result do_out(state_type&, const intern_type*,
85 const intern_type*, const intern_type*&,
86 extern_type*, extern_type*, extern_type*&) const
89 virtual result do_in(state_type&, const extern_type*, const extern_type*,
90 const extern_type*&, intern_type*, intern_type*,
94 virtual result do_unshift(state_type&, extern_type*, extern_type*,
98 virtual int do_encoding() const throw()
101 virtual bool do_always_noconv() const throw()
104 virtual int do_length(state_type&, const extern_type* from,
105 const extern_type* end, size_t max) const
107 size_t len = end - from;
108 return std::min(max, len);
111 virtual int do_max_length() const throw()
115 locale::id codecvt<wchar_t, char, MyState>::id;
117 codecvt<wchar_t, char, MyState>::~codecvt()
123 bool test __attribute__((unused)) = true;
125 std::locale loc(std::locale::classic(),
126 new std::codecvt<wchar_t, char, MyState>);
127 std::basic_filebuf<wchar_t, MyCharTraits> fb;
129 fb.open("tmp_11543", std::ios_base::out);
130 VERIFY( fb.is_open() );
131 MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
132 VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );