]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/postypes.h
*: Use headername alias to associate private includes to public includes.
[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,
f910786b 4// 2006, 2007, 2008, 2009, 2010
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
748086b7 10// Free Software Foundation; either version 3, or (at your option)
4c4809c1
BK
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
748086b7
JJ
18// Under Section 7 of GPL version 3, you are granted additional
19// permissions described in the GCC Runtime Library Exception, version
20// 3.1, as published by the Free Software Foundation.
21
22// You should have received a copy of the GNU General Public License and
23// a copy of the GCC Runtime Library Exception along with this program;
24// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25// <http://www.gnu.org/licenses/>.
4c4809c1 26
f910786b 27/** @file bits/postypes.h
4c4809c1 28 * This is an internal header file, included by other library headers.
f910786b 29 * Do not attempt to use it directly. @headername{iosfwd}
4c4809c1
BK
30 */
31
143c27b0
BK
32//
33// ISO C++ 14882: 27.4.1 - Types
34// ISO C++ 14882: 27.4.3 - Template class fpos
35//
36
4c4809c1
BK
37#ifndef _GLIBCXX_POSTYPES_H
38#define _GLIBCXX_POSTYPES_H 1
39
40#pragma GCC system_header
41
42#include <cwchar> // For mbstate_t
43
802841eb
PC
44// XXX If <stdint.h> is really needed, make sure to define the macros
45// before including it, in order not to break <tr1/cstdint> (and <cstdint>
46// in C++0x). Reconsider all this as soon as possible...
fc9ab7b4
PC
47#if (defined(_GLIBCXX_HAVE_INT64_T) && !defined(_GLIBCXX_HAVE_INT64_T_LONG) \
48 && !defined(_GLIBCXX_HAVE_INT64_T_LONG_LONG))
802841eb 49
d27653b8 50#ifndef __STDC_LIMIT_MACROS
802841eb 51# define _UNDEF__STDC_LIMIT_MACROS
d27653b8
PC
52# define __STDC_LIMIT_MACROS
53#endif
54#ifndef __STDC_CONSTANT_MACROS
802841eb 55# define _UNDEF__STDC_CONSTANT_MACROS
d27653b8
PC
56# define __STDC_CONSTANT_MACROS
57#endif
58#include <stdint.h> // For int64_t
802841eb
PC
59#ifdef _UNDEF__STDC_LIMIT_MACROS
60# undef __STDC_LIMIT_MACROS
61# undef _UNDEF__STDC_LIMIT_MACROS
62#endif
63#ifdef _UNDEF__STDC_CONSTANT_MACROS
64# undef __STDC_CONSTANT_MACROS
65# undef _UNDEF__STDC_CONSTANT_MACROS
66#endif
67
d27653b8
PC
68#endif
69
3cbc7af0
BK
70_GLIBCXX_BEGIN_NAMESPACE(std)
71
4c4809c1
BK
72 // The types streamoff, streampos and wstreampos and the class
73 // template fpos<> are described in clauses 21.1.2, 21.1.3, 27.1.2,
28dac70a 74 // 27.2, 27.4.1, 27.4.3 and D.6. Despite all this verbiage, the
4c4809c1
BK
75 // behaviour of these types is mostly implementation defined or
76 // unspecified. The behaviour in this implementation is as noted
3d05b345
PC
77 // below.
78
0b1d67d2
PC
79 /**
80 * @brief Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
81 *
0b1d67d2
PC
82 * In clauses 21.1.3.1 and 27.4.1 streamoff is described as an
83 * implementation defined type.
84 * Note: In versions of GCC up to and including GCC 3.3, streamoff
85 * was typedef long.
0b1d67d2 86 */
fc9ab7b4
PC
87#ifdef _GLIBCXX_HAVE_INT64_T_LONG
88 typedef long streamoff;
89#elif defined(_GLIBCXX_HAVE_INT64_T_LONG_LONG)
90 typedef long long streamoff;
91#elif defined(_GLIBCXX_HAVE_INT64_T)
d27653b8 92 typedef int64_t streamoff;
3d05b345 93#else
0b1d67d2 94 typedef long long streamoff;
3d05b345
PC
95#endif
96
ffcec5c8 97 /// Integral type for I/O operation counts and buffer sizes.
4c4809c1
BK
98 typedef ptrdiff_t streamsize; // Signed integral type
99
ffcec5c8
JQ
100 /**
101 * @brief Class representing stream positions.
102 *
103 * The standard places no requirements upon the template parameter StateT.
104 * In this implementation StateT must be DefaultConstructible,
105 * CopyConstructible and Assignable. The standard only requires that fpos
106 * should contain a member of type StateT. In this implementation it also
107 * contains an offset stored as a signed integer.
108 *
109 * @param StateT Type passed to and returned from state().
110 */
4c4809c1
BK
111 template<typename _StateT>
112 class fpos
113 {
114 private:
0b1d67d2 115 streamoff _M_off;
ed6814f7 116 _StateT _M_state;
4c4809c1
BK
117
118 public:
119 // The standard doesn't require that fpos objects can be default
120 // constructed. This implementation provides a default
121 // constructor that initializes the offset to 0 and default
122 // constructs the state.
123 fpos()
124 : _M_off(0), _M_state() { }
125
4c4809c1
BK
126 // The standard requires that fpos objects can be constructed
127 // from streamoff objects using the constructor syntax, and
128 // fails to give any meaningful semantics. In this
129 // implementation implicit conversion is also allowed, and this
130 // constructor stores the streamoff as the offset and default
131 // constructs the state.
ffcec5c8 132 /// Construct position from offset.
0b1d67d2 133 fpos(streamoff __off)
4c4809c1
BK
134 : _M_off(__off), _M_state() { }
135
0b1d67d2
PC
136 /// Convert to streamoff.
137 operator streamoff() const { return _M_off; }
138
ffcec5c8 139 /// Remember the value of @a st.
4c4809c1
BK
140 void
141 state(_StateT __st)
142 { _M_state = __st; }
143
ffcec5c8 144 /// Return the last set value of @a st.
4c4809c1
BK
145 _StateT
146 state() const
147 { return _M_state; }
148
4c4809c1 149 // The standard requires that this operator must be defined, but
28dac70a 150 // gives no semantics. In this implementation it just adds its
4c4809c1 151 // argument to the stored offset and returns *this.
ffcec5c8 152 /// Add offset to this position.
4c4809c1 153 fpos&
0b1d67d2 154 operator+=(streamoff __off)
4c4809c1
BK
155 {
156 _M_off += __off;
157 return *this;
158 }
159
160 // The standard requires that this operator must be defined, but
28dac70a
RW
161 // gives no semantics. In this implementation it just subtracts
162 // its argument from the stored offset and returns *this.
ffcec5c8 163 /// Subtract offset from this position.
4c4809c1 164 fpos&
0b1d67d2 165 operator-=(streamoff __off)
4c4809c1
BK
166 {
167 _M_off -= __off;
168 return *this;
169 }
170
171 // The standard requires that this operator must be defined, but
28dac70a 172 // defines its semantics only in terms of operator-. In this
4c4809c1
BK
173 // implementation it constructs a copy of *this, adds the
174 // argument to that copy using operator+= and then returns the
175 // copy.
ffcec5c8 176 /// Add position and offset.
4c4809c1 177 fpos
0b1d67d2 178 operator+(streamoff __off) const
4c4809c1
BK
179 {
180 fpos __pos(*this);
181 __pos += __off;
182 return __pos;
183 }
184
185 // The standard requires that this operator must be defined, but
28dac70a 186 // defines its semantics only in terms of operator+. In this
4c4809c1
BK
187 // implementation it constructs a copy of *this, subtracts the
188 // argument from that copy using operator-= and then returns the
189 // copy.
ffcec5c8 190 /// Subtract offset from position.
4c4809c1 191 fpos
0b1d67d2 192 operator-(streamoff __off) const
4c4809c1
BK
193 {
194 fpos __pos(*this);
195 __pos -= __off;
196 return __pos;
197 }
198
199 // The standard requires that this operator must be defined, but
28dac70a 200 // defines its semantics only in terms of operator+. In this
4c4809c1
BK
201 // implementation it returns the difference between the offset
202 // stored in *this and in the argument.
ffcec5c8 203 /// Subtract position to return offset.
4c4809c1
BK
204 streamoff
205 operator-(const fpos& __other) const
206 { return _M_off - __other._M_off; }
207 };
208
e0480f3f
PC
209 // The standard only requires that operator== must be an
210 // equivalence relation. In this implementation two fpos<StateT>
211 // objects belong to the same equivalence class if the contained
212 // offsets compare equal.
213 /// Test if equivalent to another position.
214 template<typename _StateT>
215 inline bool
216 operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
217 { return streamoff(__lhs) == streamoff(__rhs); }
218
219 template<typename _StateT>
220 inline bool
221 operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
222 { return streamoff(__lhs) != streamoff(__rhs); }
223
4c4809c1
BK
224 // Clauses 21.1.3.1 and 21.1.3.2 describe streampos and wstreampos
225 // as implementation defined types, but clause 27.2 requires that
226 // they must both be typedefs for fpos<mbstate_t>
ffcec5c8 227 /// File position for char streams.
4c4809c1 228 typedef fpos<mbstate_t> streampos;
ffcec5c8 229 /// File position for wchar_t streams.
4c4809c1 230 typedef fpos<mbstate_t> wstreampos;
3cbc7af0 231
5e44d591
PC
232#ifdef __GXX_EXPERIMENTAL_CXX0X__
233 /// File position for char16_t streams.
234 typedef fpos<mbstate_t> u16streampos;
235 /// File position for char32_t streams.
236 typedef fpos<mbstate_t> u32streampos;
237#endif
238
3cbc7af0 239_GLIBCXX_END_NAMESPACE
4c4809c1
BK
240
241#endif