1 // Position types -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 27.4.1 - Types
33 // ISO C++ 14882: 27.4.3 - Template class fpos
37 * This is an internal header file, included by other library headers.
38 * You should not attempt to use it directly.
41 #ifndef _GLIBCXX_POSTYPES_H
42 #define _GLIBCXX_POSTYPES_H 1
44 #pragma GCC system_header
46 #include <cwchar> // For mbstate_t
50 // The types streamoff, streampos and wstreampos and the class
51 // template fpos<> are described in clauses 21.1.2, 21.1.3, 27.1.2,
52 // 27.2, 27.4.1, 27.4.3 and D.6. Despite all this verbage, the
53 // behaviour of these types is mostly implementation defined or
54 // unspecified. The behaviour in this implementation is as noted
56 typedef long __streamoff_base_type;
57 typedef ptrdiff_t streamsize; // Signed integral type
59 template<typename _StateT>
62 // Class streamoff is an implementation defined type that meets the
63 // requirements for streamoff. It stores an offset as a signed
64 // integer. Note: this class is an implementation detail.
68 __streamoff_base_type _M_off;
71 // Nothing in the standard requires that streamoff can be default
72 // constructed. In this implementation a default constructor that
73 // stores the value 0 is provided.
77 // The standard only requires that streamoff can be constructed
78 // from streamsize using the constructor syntax. This
79 // implementation also allows implicit conversion from integer
80 // types to streamoff.
81 streamoff(__streamoff_base_type __off)
84 // The standard requires that streamoff can be constructed from
85 // instances of fpos using the constructor syntax, but gives no
86 // semantics for this construction. In this implementation it
87 // extracts the offset stored by the fpos object.
88 // Note: In versions of GCC up to and including GCC 3.3, implicit
89 // conversion from fpos to streamoff was allowed. This constructor
90 // has now been made explicit to improve type safety.
91 template<typename _StateT>
93 streamoff(const fpos<_StateT>&);
95 // The standard requires that streamsize can be constructed from
96 // streamoff using the constructor syntax. This implementation
97 // also allows implicit conversion. This allows streamoff objects
98 // to be used in arithmetic expressions and to be compared against
99 // each other and integer types.
100 operator __streamoff_base_type() const
103 // This implementation allows the use of operators +=, -=, ++ and
104 // -- on streamoff objects.
106 operator+=(__streamoff_base_type __off)
113 operator-=(__streamoff_base_type __off)
120 // In clauses 21.1.3.1 and 27.4.1 streamoff is described as an
121 // implementation defined type. In this implementation it is a
122 // distinct class type.
123 // Note: In versions of GCC up to and including GCC 3.3, streamoff
125 typedef class streamoff streamoff;
127 // The standard fails to place any requiremens on the template
128 // argument StateT. In this implementation StateT must be
129 // DefaultConstructible, CopyConstructible and Assignable. The
130 // standard only requires that fpos should contain a member of type
131 // StateT. In this implementation it also contains an offset stored
132 // as a signed integer.
133 template<typename _StateT>
137 friend class streamoff;
139 __streamoff_base_type _M_off;
143 // The standard doesn't require that fpos objects can be default
144 // constructed. This implementation provides a default
145 // constructor that initializes the offset to 0 and default
146 // constructs the state.
148 : _M_off(0), _M_state() { }
150 // The standard requires implicit conversion from integers to
151 // fpos, but gives no meaningful semantics for this
152 // conversion. In this implementation this constructor stores
153 // the integer as the offset and default constructs the state.
154 fpos(__streamoff_base_type __off)
155 : _M_off(__off), _M_state() { }
157 // The standard requires that fpos objects can be constructed
158 // from streamoff objects using the constructor syntax, and
159 // fails to give any meaningful semantics. In this
160 // implementation implicit conversion is also allowed, and this
161 // constructor stores the streamoff as the offset and default
162 // constructs the state.
163 fpos(const streamoff& __off)
164 : _M_off(__off), _M_state() { }
174 // The standard only requires that operator== must be an
175 // equivalence relation. In this implementation two fpos<StateT>
176 // objects belong to the same equivalence class if the contained
177 // offsets compare equal.
179 operator==(const fpos& __other) const
180 { return _M_off == __other._M_off; }
183 operator!=(const fpos& __other) const
184 { return _M_off != __other._M_off; }
186 // The standard requires that this operator must be defined, but
187 // gives no semantics. In this implemenation it just adds it's
188 // argument to the stored offset and returns *this.
190 operator+=(const streamoff& __off)
196 // The standard requires that this operator must be defined, but
197 // gives no semantics. In this implemenation it just subtracts
198 // it's argument from the stored offset and returns *this.
200 operator-=(const streamoff& __off)
206 // The standard requires that this operator must be defined, but
207 // defines it's semantics only in terms of operator-. In this
208 // implementation it constructs a copy of *this, adds the
209 // argument to that copy using operator+= and then returns the
212 operator+(const streamoff& __off) const
219 // The standard requires that this operator must be defined, but
220 // defines it's semantics only in terms of operator+. In this
221 // implementation it constructs a copy of *this, subtracts the
222 // argument from that copy using operator-= and then returns the
225 operator-(const streamoff& __off) const
232 // The standard requires that this operator must be defined, but
233 // defines it's semantics only in terms of operator+. In this
234 // implementation it returns the difference between the offset
235 // stored in *this and in the argument.
237 operator-(const fpos& __other) const
238 { return _M_off - __other._M_off; }
241 template<typename _StateT>
243 streamoff::streamoff(const fpos<_StateT>& __pos)
244 : _M_off(__pos._M_off) { }
246 // Clauses 21.1.3.1 and 21.1.3.2 describe streampos and wstreampos
247 // as implementation defined types, but clause 27.2 requires that
248 // they must both be typedefs for fpos<mbstate_t>
249 typedef fpos<mbstate_t> streampos;
250 typedef fpos<mbstate_t> wstreampos;