1 // Copyright (c) 2001-2011 Hartmut Kaiser
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #if !defined(BOOST_SPIRIT_ADAPT_ADT_ATTRIBUTES_SEP_15_2010_1219PM)
7 #define BOOST_SPIRIT_ADAPT_ADT_ATTRIBUTES_SEP_15_2010_1219PM
13 #include <boost/spirit/home/support/attributes.hpp>
14 #include <boost/spirit/home/support/container.hpp>
15 #include <boost/spirit/home/support/numeric_traits.hpp>
16 #include <boost/fusion/include/adapt_adt.hpp>
17 #include <boost/utility/enable_if.hpp>
19 ///////////////////////////////////////////////////////////////////////////////
20 // customization points allowing to use adapted classes with spirit
21 namespace boost { namespace spirit { namespace traits
23 ///////////////////////////////////////////////////////////////////////////
24 template <typename T, int N, bool Const, typename Domain>
25 struct not_is_variant<
26 fusion::extension::adt_attribute_proxy<T, N, Const>, Domain>
28 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
32 template <typename T, int N, bool Const, typename Domain>
33 struct not_is_optional<
34 fusion::extension::adt_attribute_proxy<T, N, Const>, Domain>
36 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
40 ///////////////////////////////////////////////////////////////////////////
41 template <typename T, int N, bool Const>
42 struct is_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
44 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
48 template <typename T, int N, bool Const>
49 struct container_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
51 typename remove_reference<
52 typename fusion::extension::adt_attribute_proxy<
59 template <typename T, int N, bool Const>
60 struct container_value<
61 fusion::extension::adt_attribute_proxy<T, N, Const> const>
64 typename remove_reference<
65 typename fusion::extension::adt_attribute_proxy<
73 template <typename T, int N, typename Val>
74 struct push_back_container<
75 fusion::extension::adt_attribute_proxy<T, N, false>
77 , typename enable_if<is_reference<
78 typename fusion::extension::adt_attribute_proxy<T, N, false>::type
82 fusion::extension::adt_attribute_proxy<T, N, false>& p
86 fusion::extension::adt_attribute_proxy<T, N, false>::type
88 return push_back(type(p), val);
92 template <typename T, int N, bool Const>
93 struct container_iterator<
94 fusion::extension::adt_attribute_proxy<T, N, Const> >
96 typename remove_reference<
97 typename fusion::extension::adt_attribute_proxy<
104 template <typename T, int N, bool Const>
105 struct container_iterator<
106 fusion::extension::adt_attribute_proxy<T, N, Const> const>
107 : container_iterator<
109 typename remove_reference<
110 typename fusion::extension::adt_attribute_proxy<
118 template <typename T, int N, bool Const>
119 struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
121 typedef typename remove_reference<
122 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
123 >::type container_type;
125 static typename container_iterator<container_type>::type
126 call(fusion::extension::adt_attribute_proxy<T, N, Const>& c)
128 return c.get().begin();
132 template <typename T, int N, bool Const>
133 struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const> const>
135 typedef typename add_const<
136 typename remove_reference<
137 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
139 >::type container_type;
141 static typename container_iterator<container_type>::type
142 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& c)
144 return c.get().begin();
148 template <typename T, int N, bool Const>
149 struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
151 typedef typename remove_reference<
152 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
153 >::type container_type;
155 static typename container_iterator<container_type>::type
156 call(fusion::extension::adt_attribute_proxy<T, N, Const>& c)
158 return c.get().end();
162 template <typename T, int N, bool Const>
163 struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const> const>
165 typedef typename add_const<
166 typename remove_reference<
167 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
169 >::type container_type;
171 static typename container_iterator<container_type>::type
172 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& c)
174 return c.get().end();
178 ///////////////////////////////////////////////////////////////////////////
179 template <typename T, int N, typename Val>
180 struct assign_to_attribute_from_value<
181 fusion::extension::adt_attribute_proxy<T, N, false>
186 , fusion::extension::adt_attribute_proxy<T, N, false>& attr)
192 template <typename T, int N, bool Const, typename Exposed>
193 struct extract_from_attribute<
194 fusion::extension::adt_attribute_proxy<T, N, Const>, Exposed>
196 typedef typename remove_const<
197 typename remove_reference<
198 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
200 >::type embedded_type;
202 typename spirit::result_of::extract_from<Exposed, embedded_type>::type
205 template <typename Context>
207 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val, Context& ctx)
209 return extract_from<Exposed>(val.get(), ctx);
213 ///////////////////////////////////////////////////////////////////////////
214 template <typename T, int N, bool Const>
215 struct attribute_type<fusion::extension::adt_attribute_proxy<T, N, Const> >
216 : fusion::extension::adt_attribute_proxy<T, N, Const>
219 ///////////////////////////////////////////////////////////////////////////
220 template <typename T, int N, bool Const>
221 struct optional_attribute<
222 fusion::extension::adt_attribute_proxy<T, N, Const> >
224 typedef typename result_of::optional_value<
225 typename remove_reference<
226 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
231 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
233 return optional_value(val.get());
237 is_valid(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
239 return has_optional_value(val.get());
243 ///////////////////////////////////////////////////////////////////////////
244 template <typename T, int N, typename Attribute, typename Domain>
245 struct transform_attribute<
246 fusion::extension::adt_attribute_proxy<T, N, false>
249 , typename disable_if<is_reference<
250 typename fusion::extension::adt_attribute_proxy<T, N, false>::type
253 typedef Attribute type;
256 pre(fusion::extension::adt_attribute_proxy<T, N, false>& val)
262 fusion::extension::adt_attribute_proxy<T, N, false>& val
263 , Attribute const& attr)
268 fail(fusion::extension::adt_attribute_proxy<T, N, false>&)
274 typename T, int N, bool Const, typename Attribute, typename Domain>
275 struct transform_attribute<
276 fusion::extension::adt_attribute_proxy<T, N, Const>
279 , typename enable_if<is_reference<
280 typename fusion::extension::adt_attribute_proxy<
285 typedef Attribute& type;
288 pre(fusion::extension::adt_attribute_proxy<T, N, Const>& val)
294 fusion::extension::adt_attribute_proxy<T, N, Const>&
299 fail(fusion::extension::adt_attribute_proxy<T, N, Const>&)
304 template <typename T, int N, bool Const>
305 struct clear_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
308 fusion::extension::adt_attribute_proxy<T, N, Const>& val)
311 fusion::extension::adt_attribute_proxy<T, N, Const>::type
317 template <typename T, int N, bool Const>
318 struct attribute_size<fusion::extension::adt_attribute_proxy<T, N, Const> >
320 typedef typename remove_const<
321 typename remove_reference<
322 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
324 >::type embedded_type;
326 typedef typename attribute_size<embedded_type>::type type;
329 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
331 return attribute_size<embedded_type>::call(val.get());
335 ///////////////////////////////////////////////////////////////////////////
336 // customization point specializations for numeric generators
337 template <typename T, int N, bool Const>
338 struct absolute_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
341 fusion::extension::adt_attribute_proxy<T, N, Const>::type
345 call (fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
347 return get_absolute_value(val.get());
351 template <typename T, int N, bool Const>
352 struct is_negative<fusion::extension::adt_attribute_proxy<T, N, Const> >
355 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
357 return test_negative(val.get());
361 template <typename T, int N, bool Const>
362 struct is_zero<fusion::extension::adt_attribute_proxy<T, N, Const> >
365 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
367 return test_zero(val.get());
371 template <typename T, int N, bool Const>
372 struct is_nan<fusion::extension::adt_attribute_proxy<T, N, Const> >
375 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
377 return test_nan(val.get());
381 template <typename T, int N, bool Const>
382 struct is_infinite<fusion::extension::adt_attribute_proxy<T, N, Const> >
385 call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
387 return test_infinite(val.get());
392 ///////////////////////////////////////////////////////////////////////////////
393 namespace boost { namespace spirit { namespace result_of
395 template <typename T, int N, bool Const>
396 struct optional_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
397 : result_of::optional_value<
398 typename remove_const<
399 typename remove_reference<
400 typename fusion::extension::adt_attribute_proxy<T, N, Const>::type