comparison DEPENDENCIES/generic/include/boost/spirit/home/karma/detail/pass_container.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
186 : pass_through_container_optional< 186 : pass_through_container_optional<
187 Container, ValueType, Attribute, Sequence> 187 Container, ValueType, Attribute, Sequence>
188 {}; 188 {};
189 189
190 // If both, the containers value type and the exposed attribute type are 190 // If both, the containers value type and the exposed attribute type are
191 // optionals we are allowed to pass through the the container only if the 191 // optionals we are allowed to pass through the container only if the
192 // embedded types of those optionals are not compatible. 192 // embedded types of those optionals are not compatible.
193 template <typename Container, typename ValueType, typename Attribute 193 template <typename Container, typename ValueType, typename Attribute
194 , typename Sequence> 194 , typename Sequence>
195 struct pass_through_container< 195 struct pass_through_container<
196 Container, boost::optional<ValueType>, boost::optional<Attribute> 196 Container, boost::optional<ValueType>, boost::optional<Attribute>
201 // Specialization for exposed variant attributes 201 // Specialization for exposed variant attributes
202 // 202 //
203 // We pass through the container attribute if at least one of the embedded 203 // We pass through the container attribute if at least one of the embedded
204 // types in the variant requires to pass through the attribute 204 // types in the variant requires to pass through the attribute
205 205
206 #if !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
207 template <typename Container, typename ValueType, typename Sequence
208 , typename T>
209 struct pass_through_container<Container, ValueType, boost::variant<T>
210 , Sequence>
211 : pass_through_container<Container, ValueType, T, Sequence>
212 {};
213
214 template <typename Container, typename ValueType, typename Sequence
215 , typename T0, typename ...TN>
216 struct pass_through_container<Container, ValueType
217 , boost::variant<T0, TN...>, Sequence>
218 : mpl::bool_<pass_through_container<
219 Container, ValueType, T0, Sequence
220 >::type::value || pass_through_container<
221 Container, ValueType, boost::variant<TN...>, Sequence
222 >::type::value>
223 {};
224 #else
206 #define BOOST_SPIRIT_PASS_THROUGH_CONTAINER(z, N, _) \ 225 #define BOOST_SPIRIT_PASS_THROUGH_CONTAINER(z, N, _) \
207 pass_through_container<Container, ValueType, \ 226 pass_through_container<Container, ValueType, \
208 BOOST_PP_CAT(T, N), Sequence>::type::value || \ 227 BOOST_PP_CAT(T, N), Sequence>::type::value || \
209 /***/ 228 /***/
210 229
222 : mpl::bool_<BOOST_PP_REPEAT(BOOST_VARIANT_LIMIT_TYPES 241 : mpl::bool_<BOOST_PP_REPEAT(BOOST_VARIANT_LIMIT_TYPES
223 , BOOST_SPIRIT_PASS_THROUGH_CONTAINER, _) false> 242 , BOOST_SPIRIT_PASS_THROUGH_CONTAINER, _) false>
224 {}; 243 {};
225 244
226 #undef BOOST_SPIRIT_PASS_THROUGH_CONTAINER 245 #undef BOOST_SPIRIT_PASS_THROUGH_CONTAINER
246 #endif
227 }}}} 247 }}}}
228 248
229 /////////////////////////////////////////////////////////////////////////////// 249 ///////////////////////////////////////////////////////////////////////////////
230 namespace boost { namespace spirit { namespace traits 250 namespace boost { namespace spirit { namespace traits
231 { 251 {
240 {}; 260 {};
241 }}} 261 }}}
242 262
243 namespace boost { namespace spirit { namespace karma { namespace detail 263 namespace boost { namespace spirit { namespace karma { namespace detail
244 { 264 {
265 template <typename Iterator>
266 struct pass_container_base
267 {
268 pass_container_base(Iterator begin, Iterator end)
269 : iter(begin), end(end)
270 {}
271
272 mutable Iterator iter;
273 mutable Iterator end;
274 };
275
276 template <typename Iterator>
277 struct pass_container_base<Iterator&>
278 {
279 pass_container_base(Iterator& begin, Iterator& end)
280 : iter(begin), end(end)
281 {}
282
283 Iterator& iter;
284 Iterator& end;
285 };
286
245 /////////////////////////////////////////////////////////////////////////// 287 ///////////////////////////////////////////////////////////////////////////
246 // This function handles the case where the attribute (Attr) given 288 // This function handles the case where the attribute (Attr) given
247 // to the sequence is an STL container. This is a wrapper around F. 289 // to the sequence is an STL container. This is a wrapper around F.
248 // The function F does the actual generating. 290 // The function F does the actual generating.
249 template <typename F, typename Attr, typename Iterator, typename Sequence> 291 template <typename F, typename Attr, typename Iterator, typename Sequence>
250 struct pass_container 292 struct pass_container : pass_container_base<Iterator>
251 { 293 {
294 typedef pass_container_base<Iterator> base_type;
252 typedef typename F::context_type context_type; 295 typedef typename F::context_type context_type;
253 296
254 pass_container(F const& f, Iterator begin, Iterator end) 297 pass_container(F const& f, Iterator begin, Iterator end)
255 : f(f), iter(begin), end(end) 298 : base_type(begin, end)
299 , f(f)
256 {} 300 {}
257 301
258 bool is_at_end() const 302 bool is_at_end() const
259 { 303 {
260 return traits::compare(iter, end); 304 return traits::compare(this->iter, this->end);
261 } 305 }
262 306
263 void next() 307 void next()
264 { 308 {
265 traits::next(iter); 309 traits::next(this->iter);
266 } 310 }
267 311
268 // this is for the case when the current element expects an attribute 312 // this is for the case when the current element expects an attribute
269 // which is taken from the next entry in the container 313 // which is taken from the next entry in the container
270 template <typename Component> 314 template <typename Component>
271 bool dispatch_container(Component const& component, mpl::false_) const 315 bool dispatch_container(Component const& component, mpl::false_) const
272 { 316 {
273 // get the next value to generate from container 317 // get the next value to generate from container
274 if (!is_at_end() && !f(component, traits::deref(iter))) 318 if (!is_at_end() && !f(component, traits::deref(this->iter)))
275 { 319 {
276 // needs to return false as long as everything is ok 320 // needs to return false as long as everything is ok
277 traits::next(iter); 321 traits::next(this->iter);
278 return false; 322 return false;
279 } 323 }
280 324
281 // either no elements available any more or generation failed 325 // either no elements available any more or generation failed
282 return true; 326 return true;
286 // attribute which is a container itself, this element will push its 330 // attribute which is a container itself, this element will push its
287 // data directly into the attribute container 331 // data directly into the attribute container
288 template <typename Component> 332 template <typename Component>
289 bool dispatch_container(Component const& component, mpl::true_) const 333 bool dispatch_container(Component const& component, mpl::true_) const
290 { 334 {
291 return f(component, make_iterator_range(iter, end)); 335 return f(component, make_iterator_range(this->iter, this->end));
292 } 336 }
293 337
294 /////////////////////////////////////////////////////////////////////// 338 ///////////////////////////////////////////////////////////////////////
295 // this is for the case when the current element doesn't expect an 339 // this is for the case when the current element doesn't expect an
296 // attribute 340 // attribute
336 380
337 return dispatch_attribute(component, predicate()); 381 return dispatch_attribute(component, predicate());
338 } 382 }
339 383
340 F f; 384 F f;
341 mutable Iterator iter;
342 mutable Iterator end;
343 385
344 private: 386 private:
345 // silence MSVC warning C4512: assignment operator could not be generated 387 // silence MSVC warning C4512: assignment operator could not be generated
346 pass_container& operator= (pass_container const&); 388 pass_container& operator= (pass_container const&);
347 }; 389 };