]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | // Copyright (C) 2003-2021 Free Software Foundation, Inc. |
4c4809c1 BK |
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 | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
4c4809c1 BK |
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 | |
748086b7 JJ |
15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
4c4809c1 BK |
17 | |
18 | // 27.8.1.4 Overridden virtual functions | |
19 | ||
6cec3c81 SL |
20 | // { dg-require-fileio "" } |
21 | ||
4c4809c1 BK |
22 | #include <fstream> |
23 | #include <locale> | |
24 | #include <testsuite_hooks.h> | |
25 | ||
26 | struct MyState | |
27 | { | |
28 | }; | |
29 | ||
30 | struct MyCharTraits : std::char_traits<wchar_t> | |
31 | { | |
32 | typedef std::fpos<MyState> pos_type; | |
33 | typedef MyState state_type; | |
34 | }; | |
35 | ||
36 | namespace std | |
37 | { | |
38 | template <> | |
39 | class codecvt<wchar_t, char, MyState> : | |
40 | public locale::facet, public codecvt_base | |
41 | { | |
42 | public: | |
43 | typedef wchar_t intern_type; | |
44 | typedef char extern_type; | |
45 | typedef MyState state_type; | |
46 | ||
47 | explicit codecvt(size_t refs = 0) | |
48 | : locale::facet(refs) { } | |
49 | ||
50 | result out(state_type& state, const intern_type* from, | |
51 | const intern_type* from_end, const intern_type*& from_next, | |
52 | extern_type* to, extern_type* to_limit, | |
53 | extern_type*& to_next) const | |
54 | { return do_out(state, from, from_end, from_next, | |
55 | to, to_limit, to_next); } | |
56 | ||
57 | result unshift(state_type& state, extern_type* to, extern_type* to_limit, | |
58 | extern_type*& to_next) const | |
59 | { return do_unshift(state, to, to_limit, to_next); } | |
60 | ||
61 | result in(state_type& state, const extern_type* from, | |
62 | const extern_type* from_end, const extern_type*& from_next, | |
63 | intern_type* to, intern_type* to_limit, | |
64 | intern_type*& to_next) const | |
65 | { return do_in(state, from, from_end, from_next, | |
66 | to, to_limit, to_next); } | |
67 | ||
68 | int encoding() const throw() | |
69 | { return do_encoding(); } | |
70 | ||
71 | bool always_noconv() const throw() | |
72 | { return do_always_noconv(); } | |
73 | ||
74 | int length(state_type& state, const extern_type* from, | |
75 | const extern_type* end, size_t max) const | |
76 | { return do_length(state, from, end, max); } | |
77 | ||
78 | int max_length() const throw() | |
79 | { return do_max_length(); } | |
80 | ||
81 | static locale::id id; | |
82 | ||
83 | protected: | |
84 | virtual ~codecvt(); | |
85 | ||
86 | virtual result do_out(state_type&, const intern_type*, | |
87 | const intern_type*, const intern_type*&, | |
88 | extern_type*, extern_type*, extern_type*&) const | |
89 | { return error; } | |
90 | ||
91 | virtual result do_in(state_type&, const extern_type*, const extern_type*, | |
92 | const extern_type*&, intern_type*, intern_type*, | |
93 | intern_type*&) const | |
94 | { return error; } | |
95 | ||
96 | virtual result do_unshift(state_type&, extern_type*, extern_type*, | |
97 | extern_type*&) const | |
98 | { return noconv; } | |
99 | ||
100 | virtual int do_encoding() const throw() | |
101 | { return 1; } | |
102 | ||
103 | virtual bool do_always_noconv() const throw() | |
104 | { return false; } | |
105 | ||
106 | virtual int do_length(state_type&, const extern_type* from, | |
107 | const extern_type* end, size_t max) const | |
108 | { | |
109 | size_t len = end - from; | |
110 | return std::min(max, len); | |
111 | } | |
112 | ||
113 | virtual int do_max_length() const throw() | |
114 | { return 1; } | |
115 | }; | |
116 | ||
117 | locale::id codecvt<wchar_t, char, MyState>::id; | |
118 | ||
119 | codecvt<wchar_t, char, MyState>::~codecvt() | |
120 | { } | |
121 | } | |
122 | ||
123 | void test01() | |
124 | { | |
4c4809c1 BK |
125 | std::locale loc(std::locale::classic(), |
126 | new std::codecvt<wchar_t, char, MyState>); | |
127 | std::basic_filebuf<wchar_t, MyCharTraits> fb; | |
128 | fb.pubimbue(loc); | |
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)) ); | |
133 | fb.close(); | |
134 | } | |
135 | ||
136 | int main() | |
137 | { | |
138 | test01(); | |
139 | return 0; | |
140 | } |