1 // Copyright (C) 2003, 2009
2 // Free Software Foundation, Inc.
4 // This file is part of the GNU ISO C++ Library. This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 3, or (at your option)
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
19 // 27.8.1.4 Overridden virtual functions
21 // { dg-require-fileio "" }
25 #include <testsuite_hooks.h>
31 struct MyCharTraits : std::char_traits<char>
33 typedef std::fpos<MyState> pos_type;
34 typedef MyState state_type;
40 class codecvt<char, char, MyState> :
41 public locale::facet, public codecvt_base
44 typedef char intern_type;
45 typedef char extern_type;
46 typedef MyState state_type;
48 explicit codecvt(size_t refs = 0)
49 : locale::facet(refs) { }
51 result out(state_type& state, const intern_type* from,
52 const intern_type* from_end, const intern_type*& from_next,
53 extern_type* to, extern_type* to_limit,
54 extern_type*& to_next) const
55 { return do_out(state, from, from_end, from_next,
56 to, to_limit, to_next); }
58 result unshift(state_type& state, extern_type* to, extern_type* to_limit,
59 extern_type*& to_next) const
60 { return do_unshift(state, to, to_limit, to_next); }
62 result in(state_type& state, const extern_type* from,
63 const extern_type* from_end, const extern_type*& from_next,
64 intern_type* to, intern_type* to_limit,
65 intern_type*& to_next) const
66 { return do_in(state, from, from_end, from_next,
67 to, to_limit, to_next); }
69 int encoding() const throw()
70 { return do_encoding(); }
72 bool always_noconv() const throw()
73 { return do_always_noconv(); }
75 int length(state_type& state, const extern_type* from,
76 const extern_type* end, size_t max) const
77 { return do_length(state, from, end, max); }
79 int max_length() const throw()
80 { return do_max_length(); }
87 virtual result do_out(state_type&, const intern_type* from,
88 const intern_type*, const intern_type*& from_next,
89 extern_type* to, extern_type*,
90 extern_type*& to_next) const
97 virtual result do_in(state_type&, const extern_type* from,
98 const extern_type*, const extern_type*& from_next,
99 intern_type* to, intern_type*,
100 intern_type*& to_next) const
107 virtual result do_unshift(state_type&, extern_type*, extern_type*,
111 virtual int do_encoding() const throw()
114 virtual bool do_always_noconv() const throw()
117 virtual int do_length(state_type&, const extern_type* from,
118 const extern_type* end, size_t max) const
120 size_t len = end - from;
121 return std::min(max, len);
124 virtual int do_max_length() const throw()
128 locale::id codecvt<char, char, MyState>::id;
130 codecvt<char, char, MyState>::~codecvt()
136 bool test __attribute__((unused)) = true;
138 std::locale loc(std::locale::classic(),
139 new std::codecvt<char, char, MyState>);
140 std::basic_filebuf<char, MyCharTraits> fb;
142 fb.open("tmp_11543", std::ios_base::out);
143 VERIFY( fb.is_open() );
144 MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
145 VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );