]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/postypes.h
invoke.texi (-ansi): Mention explicitly corresponding -std= options.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / postypes.h
CommitLineData
4c4809c1
BK
1// Position types -*- C++ -*-
2
ee60de36 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4312e020 4// 2006, 2007, 2008
4c4809c1
BK
5// Free Software Foundation, Inc.
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
10// Free Software Foundation; either version 2, or (at your option)
11// any later version.
12
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License along
19// with this library; see the file COPYING. If not, write to the Free
83f51799 20// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
4c4809c1
BK
21// USA.
22
23// As a special exception, you may use this file as part of a free software
24// library without restriction. Specifically, if other files instantiate
25// templates or use macros or inline functions from this file, or you compile
26// this file and link it with other files to produce an executable, this
27// file does not by itself cause the resulting executable to be covered by
28// the GNU General Public License. This exception does not however
29// invalidate any other reasons why the executable file might be covered by
30// the GNU General Public License.
31
4c4809c1
BK
32/** @file postypes.h
33 * This is an internal header file, included by other library headers.
34 * You should not attempt to use it directly.
35 */
36
143c27b0
BK
37//
38// ISO C++ 14882: 27.4.1 - Types
39// ISO C++ 14882: 27.4.3 - Template class fpos
40//
41
4c4809c1
BK
42#ifndef _GLIBCXX_POSTYPES_H
43#define _GLIBCXX_POSTYPES_H 1
44
45#pragma GCC system_header
46
47#include <cwchar> // For mbstate_t
48
3d05b345
PC
49#ifdef _GLIBCXX_HAVE_STDINT_H
50#include <stdint.h> // For int64_t
51#endif
52
3cbc7af0
BK
53_GLIBCXX_BEGIN_NAMESPACE(std)
54
4c4809c1
BK
55 // The types streamoff, streampos and wstreampos and the class
56 // template fpos<> are described in clauses 21.1.2, 21.1.3, 27.1.2,
57 // 27.2, 27.4.1, 27.4.3 and D.6. Despite all this verbage, the
58 // behaviour of these types is mostly implementation defined or
59 // unspecified. The behaviour in this implementation is as noted
3d05b345
PC
60 // below.
61
0b1d67d2
PC
62 /**
63 * @brief Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
64 *
0b1d67d2
PC
65 * In clauses 21.1.3.1 and 27.4.1 streamoff is described as an
66 * implementation defined type.
67 * Note: In versions of GCC up to and including GCC 3.3, streamoff
68 * was typedef long.
0b1d67d2 69 */
3d05b345 70#ifdef _GLIBCXX_HAVE_INT64_T
0b1d67d2 71 typedef int64_t streamoff;
3d05b345 72#else
0b1d67d2 73 typedef long long streamoff;
3d05b345
PC
74#endif
75
ffcec5c8 76 /// Integral type for I/O operation counts and buffer sizes.
4c4809c1
BK
77 typedef ptrdiff_t streamsize; // Signed integral type
78
ffcec5c8
JQ
79 /**
80 * @brief Class representing stream positions.
81 *
82 * The standard places no requirements upon the template parameter StateT.
83 * In this implementation StateT must be DefaultConstructible,
84 * CopyConstructible and Assignable. The standard only requires that fpos
85 * should contain a member of type StateT. In this implementation it also
86 * contains an offset stored as a signed integer.
87 *
88 * @param StateT Type passed to and returned from state().
89 */
4c4809c1
BK
90 template<typename _StateT>
91 class fpos
92 {
93 private:
0b1d67d2 94 streamoff _M_off;
ed6814f7 95 _StateT _M_state;
4c4809c1
BK
96
97 public:
98 // The standard doesn't require that fpos objects can be default
99 // constructed. This implementation provides a default
100 // constructor that initializes the offset to 0 and default
101 // constructs the state.
102 fpos()
103 : _M_off(0), _M_state() { }
104
4c4809c1
BK
105 // The standard requires that fpos objects can be constructed
106 // from streamoff objects using the constructor syntax, and
107 // fails to give any meaningful semantics. In this
108 // implementation implicit conversion is also allowed, and this
109 // constructor stores the streamoff as the offset and default
110 // constructs the state.
ffcec5c8 111 /// Construct position from offset.
0b1d67d2 112 fpos(streamoff __off)
4c4809c1
BK
113 : _M_off(__off), _M_state() { }
114
0b1d67d2
PC
115 /// Convert to streamoff.
116 operator streamoff() const { return _M_off; }
117
ffcec5c8 118 /// Remember the value of @a st.
4c4809c1
BK
119 void
120 state(_StateT __st)
121 { _M_state = __st; }
122
ffcec5c8 123 /// Return the last set value of @a st.
4c4809c1
BK
124 _StateT
125 state() const
126 { return _M_state; }
127
4c4809c1
BK
128 // The standard requires that this operator must be defined, but
129 // gives no semantics. In this implemenation it just adds it's
130 // argument to the stored offset and returns *this.
ffcec5c8 131 /// Add offset to this position.
4c4809c1 132 fpos&
0b1d67d2 133 operator+=(streamoff __off)
4c4809c1
BK
134 {
135 _M_off += __off;
136 return *this;
137 }
138
139 // The standard requires that this operator must be defined, but
140 // gives no semantics. In this implemenation it just subtracts
141 // it's argument from the stored offset and returns *this.
ffcec5c8 142 /// Subtract offset from this position.
4c4809c1 143 fpos&
0b1d67d2 144 operator-=(streamoff __off)
4c4809c1
BK
145 {
146 _M_off -= __off;
147 return *this;
148 }
149
150 // The standard requires that this operator must be defined, but
151 // defines it's semantics only in terms of operator-. In this
152 // implementation it constructs a copy of *this, adds the
153 // argument to that copy using operator+= and then returns the
154 // copy.
ffcec5c8 155 /// Add position and offset.
4c4809c1 156 fpos
0b1d67d2 157 operator+(streamoff __off) const
4c4809c1
BK
158 {
159 fpos __pos(*this);
160 __pos += __off;
161 return __pos;
162 }
163
164 // The standard requires that this operator must be defined, but
165 // defines it's semantics only in terms of operator+. In this
166 // implementation it constructs a copy of *this, subtracts the
167 // argument from that copy using operator-= and then returns the
168 // copy.
ffcec5c8 169 /// Subtract offset from position.
4c4809c1 170 fpos
0b1d67d2 171 operator-(streamoff __off) const
4c4809c1
BK
172 {
173 fpos __pos(*this);
174 __pos -= __off;
175 return __pos;
176 }
177
178 // The standard requires that this operator must be defined, but
179 // defines it's semantics only in terms of operator+. In this
180 // implementation it returns the difference between the offset
181 // stored in *this and in the argument.
ffcec5c8 182 /// Subtract position to return offset.
4c4809c1
BK
183 streamoff
184 operator-(const fpos& __other) const
185 { return _M_off - __other._M_off; }
186 };
187
e0480f3f
PC
188 // The standard only requires that operator== must be an
189 // equivalence relation. In this implementation two fpos<StateT>
190 // objects belong to the same equivalence class if the contained
191 // offsets compare equal.
192 /// Test if equivalent to another position.
193 template<typename _StateT>
194 inline bool
195 operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
196 { return streamoff(__lhs) == streamoff(__rhs); }
197
198 template<typename _StateT>
199 inline bool
200 operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
201 { return streamoff(__lhs) != streamoff(__rhs); }
202
4c4809c1
BK
203 // Clauses 21.1.3.1 and 21.1.3.2 describe streampos and wstreampos
204 // as implementation defined types, but clause 27.2 requires that
205 // they must both be typedefs for fpos<mbstate_t>
ffcec5c8 206 /// File position for char streams.
4c4809c1 207 typedef fpos<mbstate_t> streampos;
ffcec5c8 208 /// File position for wchar_t streams.
4c4809c1 209 typedef fpos<mbstate_t> wstreampos;
3cbc7af0
BK
210
211_GLIBCXX_END_NAMESPACE
4c4809c1
BK
212
213#endif