STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
postypes.h File Reference
#include <cwchar>

Go to the source code of this file.

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is an internal header file, included by other library headers. Do not attempt to use it directly. {iosfwd}

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

Type used by fpos, char_traits<char>, and char_traits<wchar_t>.

In clauses 21.1.3.1 and 27.4.1 streamoff is described as an implementation defined type. Note: In versions of GCC up to and including GCC 3.3, streamoff was typedef long.

Integral type for I/O operation counts and buffer sizes.

Class representing stream positions.

The standard places no requirements upon the template parameter StateT. In this implementation StateT must be DefaultConstructible, CopyConstructible and Assignable. The standard only requires that fpos should contain a member of type StateT. In this implementation it also contains an offset stored as a signed integer.

Parameters
StateTType passed to and returned from state().

Construct position from offset.

Convert to streamoff.

Remember the value of st.

Return the last set value of st.

Add offset to this position.

Subtract offset from this position.

Add position and offset.

Subtract offset from position.

Subtract position to return offset.

Test if equivalent to another position.

File position for char streams.

File position for wchar_t streams.

69 {
70 _GLIBCXX_BEGIN_NAMESPACE_VERSION
71 
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,
74  // 27.2, 27.4.1, 27.4.3 and D.6. Despite all this verbiage, the
75  // behaviour of these types is mostly implementation defined or
76  // unspecified. The behaviour in this implementation is as noted
77  // below.
78 
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)
92  typedef int64_t streamoff;
93 #else
94  typedef long long streamoff;
95 #endif
96 
98  typedef ptrdiff_t streamsize; // Signed integral type
99 
111  template<typename _StateT>
112  class fpos
113  {
114  private:
115  streamoff _M_off;
116  _StateT _M_state;
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 
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.
133  fpos(streamoff __off)
134  : _M_off(__off), _M_state() { }
135 
137  operator streamoff() const { return _M_off; }
138 
140  void
141  state(_StateT __st)
142  { _M_state = __st; }
143 
145  _StateT
146  state() const
147  { return _M_state; }
148 
149  // The standard requires that this operator must be defined, but
150  // gives no semantics. In this implementation it just adds its
151  // argument to the stored offset and returns *this.
153  fpos&
154  operator+=(streamoff __off)
155  {
156  _M_off += __off;
157  return *this;
158  }
159 
160  // The standard requires that this operator must be defined, but
161  // gives no semantics. In this implementation it just subtracts
162  // its argument from the stored offset and returns *this.
164  fpos&
165  operator-=(streamoff __off)
166  {
167  _M_off -= __off;
168  return *this;
169  }
170 
171  // The standard requires that this operator must be defined, but
172  // defines its semantics only in terms of operator-. In this
173  // implementation it constructs a copy of *this, adds the
174  // argument to that copy using operator+= and then returns the
175  // copy.
177  fpos
178  operator+(streamoff __off) const
179  {
180  fpos __pos(*this);
181  __pos += __off;
182  return __pos;
183  }
184 
185  // The standard requires that this operator must be defined, but
186  // defines its semantics only in terms of operator+. In this
187  // implementation it constructs a copy of *this, subtracts the
188  // argument from that copy using operator-= and then returns the
189  // copy.
191  fpos
192  operator-(streamoff __off) const
193  {
194  fpos __pos(*this);
195  __pos -= __off;
196  return __pos;
197  }
198 
199  // The standard requires that this operator must be defined, but
200  // defines its semantics only in terms of operator+. In this
201  // implementation it returns the difference between the offset
202  // stored in *this and in the argument.
204  streamoff
205  operator-(const fpos& __other) const
206  { return _M_off - __other._M_off; }
207  };
208 
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.
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 
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>
228  typedef fpos<mbstate_t> streampos;
230  typedef fpos<mbstate_t> wstreampos;
231 
232 #if __cplusplus >= 201103L
233  typedef fpos<mbstate_t> u16streampos;
236  typedef fpos<mbstate_t> u32streampos;
237 #endif
238 
239 _GLIBCXX_END_NAMESPACE_VERSION
240 } // namespace
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
_Safe_iterator< _Iterator, _Sequence > operator+(typename _Safe_iterator< _Iterator, _Sequence >::difference_type __n, const _Safe_iterator< _Iterator, _Sequence > &__i)
Definition: safe_iterator.h:712
_Safe_iterator< _IteratorL, _Sequence >::difference_type operator-(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:680
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
__PTRDIFF_TYPE__ ptrdiff_t
Definition: stddef.h:147