OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_filebuf/] [seekoff/] [char/] [11543.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// Copyright (C) 2003
2
// Free Software Foundation, Inc.
3
//
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)
8
// any later version.
9
 
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.
14
 
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,
18
// USA.
19
 
20
// 27.8.1.4 Overridden virtual functions
21
 
22
#include <fstream>
23
#include <locale>
24
#include <testsuite_hooks.h>
25
 
26
struct MyState
27
{
28
};
29
 
30
struct MyCharTraits : std::char_traits<char>
31
{
32
  typedef std::fpos<MyState> pos_type;
33
  typedef MyState state_type;
34
};
35
 
36
namespace std
37
{
38
  template <>
39
    class codecvt<char, char, MyState> :
40
      public locale::facet, public codecvt_base
41
    {
42
    public:
43
      typedef char 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* from,
87
                            const intern_type*, const intern_type*& from_next,
88
                            extern_type* to, extern_type*,
89
                            extern_type*& to_next) const
90
      {
91
        from_next = from;
92
        to_next = to;
93
        return noconv;
94
      }
95
 
96
      virtual result do_in(state_type&, const extern_type* from,
97
                           const extern_type*, const extern_type*& from_next,
98
                           intern_type* to, intern_type*,
99
                           intern_type*& to_next) const
100
      {
101
        from_next = from;
102
        to_next = to;
103
        return noconv;
104
      }
105
 
106
      virtual result do_unshift(state_type&, extern_type*, extern_type*,
107
                                extern_type*&) const
108
      { return noconv; }
109
 
110
      virtual int do_encoding() const throw()
111
      { return 1; }
112
 
113
      virtual bool do_always_noconv() const throw()
114
      { return true; }
115
 
116
      virtual int do_length(state_type&, const extern_type* from,
117
                            const extern_type* end, size_t max) const
118
      {
119
        size_t len = end - from;
120
        return std::min(max, len);
121
      }
122
 
123
      virtual int do_max_length() const throw()
124
      { return 1; }
125
    };
126
 
127
  locale::id codecvt<char, char, MyState>::id;
128
 
129
  codecvt<char, char, MyState>::~codecvt()
130
  { }
131
}
132
 
133
void test01()
134
{
135
  bool test __attribute__((unused)) = true;
136
 
137
  std::locale loc(std::locale::classic(),
138
                  new std::codecvt<char, char, MyState>);
139
  std::basic_filebuf<char, MyCharTraits> fb;
140
  fb.pubimbue(loc);
141
  fb.open("tmp_11543", std::ios_base::out);
142
  VERIFY( fb.is_open() );
143
  MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
144
  VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );
145
  fb.close();
146
}
147
 
148
int main()
149
{
150
  test01();
151
  return 0;
152
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.