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 2, 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 COPYING. If not, write to the Free
17 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // 27.8.1.4 Overridden virtual functions
22 // { dg-require-fileio "" }
26 #include <testsuite_hooks.h>
32 struct MyCharTraits : std::char_traits<char>
34 typedef std::fpos<MyState> pos_type;
35 typedef MyState state_type;
41 class codecvt<char, char, MyState> :
42 public locale::facet, public codecvt_base
45 typedef char intern_type;
46 typedef char extern_type;
47 typedef MyState state_type;
49 explicit codecvt(size_t refs = 0)
50 : locale::facet(refs) { }
52 result out(state_type& state, const intern_type* from,
53 const intern_type* from_end, const intern_type*& from_next,
54 extern_type* to, extern_type* to_limit,
55 extern_type*& to_next) const
56 { return do_out(state, from, from_end, from_next,
57 to, to_limit, to_next); }
59 result unshift(state_type& state, extern_type* to, extern_type* to_limit,
60 extern_type*& to_next) const
61 { return do_unshift(state, to, to_limit, to_next); }
63 result in(state_type& state, const extern_type* from,
64 const extern_type* from_end, const extern_type*& from_next,
65 intern_type* to, intern_type* to_limit,
66 intern_type*& to_next) const
67 { return do_in(state, from, from_end, from_next,
68 to, to_limit, to_next); }
70 int encoding() const throw()
71 { return do_encoding(); }
73 bool always_noconv() const throw()
74 { return do_always_noconv(); }
76 int length(state_type& state, const extern_type* from,
77 const extern_type* end, size_t max) const
78 { return do_length(state, from, end, max); }
80 int max_length() const throw()
81 { return do_max_length(); }
88 virtual result do_out(state_type&, const intern_type* from,
89 const intern_type*, const intern_type*& from_next,
90 extern_type* to, extern_type*,
91 extern_type*& to_next) const
98 virtual result do_in(state_type&, const extern_type* from,
99 const extern_type*, const extern_type*& from_next,
100 intern_type* to, intern_type*,
101 intern_type*& to_next) const
108 virtual result do_unshift(state_type&, extern_type*, extern_type*,
112 virtual int do_encoding() const throw()
115 virtual bool do_always_noconv() const throw()
118 virtual int do_length(state_type&, const extern_type* from,
119 const extern_type* end, size_t max) const
121 size_t len = end - from;
122 return std::min(max, len);
125 virtual int do_max_length() const throw()
129 locale::id codecvt<char, char, MyState>::id;
131 codecvt<char, char, MyState>::~codecvt()
137 bool test __attribute__((unused)) = true;
139 std::locale loc(std::locale::classic(),
140 new std::codecvt<char, char, MyState>);
141 std::basic_filebuf<char, MyCharTraits> fb;
143 fb.open("tmp_11543", std::ios_base::out);
144 VERIFY( fb.is_open() );
145 MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
146 VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );