Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_rawiter.h
Go to the documentation of this file.
1// -*- C++ -*-
2
43#ifndef _RWSTD_RW_RAWITER_H_INCLUDED
44#define _RWSTD_RW_RAWITER_H_INCLUDED
45
46#ifndef _RWSTD_ITERBASE_H_INCLUDED
47# include <rw/_iterbase.h>
48#endif // _RWSTD_ITERBASE_H_INCLUDED
49
50#ifndef _RWSTD_RW_NEW_H_INCLUDED
51# include <rw/_new.h>
52#endif // _RWSTD_RW_NEW_H_INCLUDED
53
54#ifndef _RWSTD_RW_PAIR_H_INCLUDED
55# include <rw/_pair.h>
56#endif // _RWSTD_RW_PAIR_H_INCLUDED
57
58
60
61
62// 20.4.2
63template <class _OutputIterator, class _TypeT>
64class raw_storage_iterator
65 : public iterator<output_iterator_tag, void, void, void, void>
66{
67 _OutputIterator _C_iter;
68public:
69
70 // for completeness and genericity
71 typedef _OutputIterator iterator_type;
72
73 // 20.4.2, p2
74 explicit raw_storage_iterator (iterator_type __x): _C_iter (__x) { }
75
76 // 20.4.2, p3
77 raw_storage_iterator& operator* () {
78 return *this;
79 }
80
81 // 20.4.2, p4
82 raw_storage_iterator& operator= (const _TypeT& __rhs) {
83 ::new (&(*_C_iter)) _TypeT (__rhs);
84 return *this;
85 }
86
87 // 20.4.2, p6
88 raw_storage_iterator& operator++ () {
89 return ++_C_iter, *this;
90 }
91
92 // 20.4.2, p7
93 raw_storage_iterator operator++ (int) {
94 const raw_storage_iterator __tmp = *this;
95 return ++*this, __tmp;
96 }
97};
98
99
100} // namespace std
101
102
104
105extern "C" {
106
107// [de]allocates a previously allocated temporary buffer
108// the constant _RWSTD_TMPBUF_SIZE controls the size of a static buffer
109// if request for area larger than _RWSTD_TMPBUF_SIZE comes in, space
110// is allocated dynamically, otherwise the static buffer is used
111// return value meaningful only when allocating
112_RWSTD_EXPORT _RWSTD_SIZE_T
113__rw_tmpbuf (void**, _RWSTD_PTRDIFF_T, _RWSTD_SIZE_T);
114
115}
116
117} // namespace __rw
118
119
121
122
123// 20.4.3 only specifies a get_temporary_buffer<>() that takes a ptrdiff_t.
124// We overload on all types so that signed integral types other than ptrdiff_t
125// can be used. This is important in getting algorithms to compile with
126// user-defined iterators (not derived from iterator<...>) whose difference
127// type is something other than ptrdiff_t.
128
129// having this overload is important in some cases for compilers that
130// do not support partial class specialization (and where as a consequence
131// iterator_traits<> isn't available)
132template <class _TypeT, class _Distance>
133inline pair<_TypeT*, _Distance>
134get_temporary_buffer (_Distance __nelems, _TypeT*)
135{
136 pair<_TypeT*, _Distance> __res (0, 0);
137
138#if __GNUG__ >= 4
139
140 // tell gcc 4 about type-punning in the cast below
141 typedef void* __attribute__ ((__may_alias__)) _VoidPtrT;
142
143#else // !gcc || gcc < 4
144
145 typedef void* _VoidPtrT;
146
147#endif // gcc
148
149 __res.second =
150 _RW::__rw_tmpbuf (_RWSTD_REINTERPRET_CAST (_VoidPtrT*, &__res.first),
151 __nelems < 0 ? 0 : __nelems, sizeof (_TypeT));
152
153 return __res;
154}
155
156
157#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
158
159// 20.4.3, p1
160template <class _TypeT>
161inline pair<_TypeT*, _RWSTD_PTRDIFF_T>
162get_temporary_buffer (_RWSTD_PTRDIFF_T __n)
163{
164 return get_temporary_buffer (__n, (_TypeT*)0);
165}
166
167#endif // _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
168
169
170// 20.4.3, p3
171template <class _TypeT>
172inline void
173return_temporary_buffer (_TypeT *__p)
174{
175#if __GNUG__ >= 4
176
177 // tell gcc 4 about type-punning in the cast below
178 typedef void* __attribute__ ((__may_alias__)) _VoidPtrT;
179
180#else // !gcc || gcc < 4
181
182 typedef void* _VoidPtrT;
183
184#endif // gcc
185
186 _RW::__rw_tmpbuf (_RWSTD_REINTERPRET_CAST (_VoidPtrT*, &__p),
187 0, sizeof (_TypeT));
188}
189
190
191} // namespace std
192
193
194#endif // _RWSTD_RW_RAWITER_H_INCLUDED
const plus_asgn< T > & operator*(const plus_asgn< T > &lhs, const plus_asgn< T > &rhs)
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_REINTERPRET_CAST(T, x)
Definition _defs.h:535
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
Definition json.h:5363