1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
4 Copyright (c) 2010-2011 Bryce Lelbach
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_OUTPUT_UTREE_TRAITS_APR_16_2010_0655AM)
10 #define BOOST_SPIRIT_OUTPUT_UTREE_TRAITS_APR_16_2010_0655AM
12 #include <boost/spirit/home/support/attributes.hpp>
13 #include <boost/spirit/home/support/container.hpp>
14 #include <boost/spirit/home/support/utree.hpp>
15 #include <boost/spirit/home/qi/domain.hpp>
16 #include <boost/spirit/home/karma/domain.hpp>
17 #include <boost/spirit/home/qi/nonterminal/nonterminal_fwd.hpp>
18 #include <boost/spirit/home/karma/nonterminal/nonterminal_fwd.hpp>
22 #include <boost/cstdint.hpp>
23 #include <boost/variant.hpp>
24 #include <boost/range/iterator_range.hpp>
25 #include <boost/mpl/bool.hpp>
26 #include <boost/mpl/identity.hpp>
27 #include <boost/mpl/or.hpp>
28 #include <boost/type_traits/is_same.hpp>
29 #include <boost/utility/enable_if.hpp>
31 ///////////////////////////////////////////////////////////////////////////////
35 inline T get(boost::spirit::utree const& x)
41 ///////////////////////////////////////////////////////////////////////////////
42 namespace boost { namespace spirit { namespace traits
46 inline bool is_list(utree const& ut)
48 switch (traits::which(ut))
50 case utree_type::reference_type:
51 return is_list(ut.deref());
53 case utree_type::list_type:
54 case utree_type::range_type:
63 inline bool is_uninitialized(utree const& ut)
65 return traits::which(ut) == utree_type::invalid_type;
69 // this specialization tells Spirit how to extract the type of the value
70 // stored in the given utree node
72 struct variant_which<utree>
74 static int call(utree const& u) { return u.which(); }
78 struct variant_which<utree::list_type>
80 static int call(utree::list_type const& u) { return u.which(); }
83 ///////////////////////////////////////////////////////////////////////////
84 // Make sure all components of an alternative expose utree, even if they
85 // actually expose a utree::list_type
86 template <typename Domain>
87 struct alternative_attribute_transform<utree::list_type, Domain>
88 : mpl::identity<utree>
91 ///////////////////////////////////////////////////////////////////////////
92 // Make sure all components of a sequence expose utree, even if they
93 // actually expose a utree::list_type
94 template <typename Domain>
95 struct sequence_attribute_transform<utree::list_type, Domain>
96 : mpl::identity<utree>
99 ///////////////////////////////////////////////////////////////////////////
100 // this specialization lets Spirit know that typed basic_strings
102 template <typename Base, utree_type::info I>
103 struct is_string<spirit::basic_string<Base, I> >
107 ///////////////////////////////////////////////////////////////////////////
108 // these specializations extract the character type of a utree typed string
109 template <typename T, utree_type::info I>
110 struct char_type_of<spirit::basic_string<iterator_range<T>, I> >
114 template <utree_type::info I>
115 struct char_type_of<spirit::basic_string<std::string, I> >
116 : mpl::identity<char>
119 ///////////////////////////////////////////////////////////////////////////
120 // these specializations extract a c string from a utree typed string
121 template <typename String>
122 struct extract_c_string;
124 template <typename T, utree_type::info I>
125 struct extract_c_string<
126 spirit::basic_string<iterator_range<T const*>, I>
130 typedef spirit::basic_string<iterator_range<T const*>, I> string;
132 static T const* call (string& s)
137 static T const* call (string const& s)
143 template <utree_type::info I>
144 struct extract_c_string<spirit::basic_string<std::string, I> >
146 typedef char char_type;
148 typedef spirit::basic_string<std::string, I> string;
150 static char const* call (string& s)
155 static char const* call (string const& s)
161 ///////////////////////////////////////////////////////////////////////////
162 // these specializations are needed because utree::value_type == utree
164 struct is_substitute<utree, utree>
169 struct is_weak_substitute<utree, utree>
174 struct is_substitute<utree::list_type, utree::list_type>
179 struct is_weak_substitute<utree::list_type, utree::list_type>
183 ///////////////////////////////////////////////////////////////////////////
184 // this specialization tells Spirit.Qi to allow assignment to an utree from
188 struct assign_to_utree_visitor : static_visitor<>
190 assign_to_utree_visitor(utree& ut) : ut_(ut) {}
192 template <typename T>
193 void operator()(T& val) const
202 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
203 struct assign_to_container_from_value<
204 utree, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
207 call(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& val, utree& attr)
209 apply_visitor(detail::assign_to_utree_visitor(attr), val);
213 ///////////////////////////////////////////////////////////////////////////
214 // this specialization tells Spirit.Qi to allow assignment to an utree from
216 template <typename Attribute>
217 struct assign_to_container_from_value<utree, Attribute>
219 // any non-container type will be either directly assigned or appended
220 static void call(Attribute const& val, utree& attr, mpl::false_)
225 push_back(attr, val);
228 // any container type will be converted into a list_type utree
229 static void call(Attribute const& val, utree& attr, mpl::true_)
231 typedef typename traits::container_iterator<Attribute const>::type
234 // make sure the attribute is a list, at least an empty one
238 iterator_type end = traits::end(val);
239 for (iterator_type i = traits::begin(val); i != end; traits::next(i))
240 push_back(attr, traits::deref(i));
243 static void call(Attribute const& val, utree& attr)
245 call(val, attr, is_container<Attribute>());
249 ///////////////////////////////////////////////////////////////////////////
250 // this specialization is required to disambiguate the specializations
253 struct assign_to_container_from_value<utree, utree>
255 static void call(utree const& val, utree& attr)
260 else if (detail::is_list(val)) {
261 typedef utree::const_iterator iterator_type;
263 iterator_type end = traits::end(val);
264 for (iterator_type i = traits::begin(val); i != end; traits::next(i))
265 push_back(attr, traits::deref(i));
268 push_back(attr, val);
274 struct assign_to_container_from_value<utree, utree::list_type>
275 : assign_to_container_from_value<utree, utree>
278 // If the destination is a utree_list, we need to force the right hand side
279 // value into a new sub-node, always, no questions asked.
281 struct assign_to_container_from_value<utree::list_type, utree>
283 static void call(utree const& val, utree& attr)
285 push_back(attr, val);
289 // If both, the right hand side and the left hand side are utree_lists
290 // we have a lhs rule which has a single rule exposing a utree_list as its
291 // rhs (optionally wrapped into a directive or other unary parser). In this
292 // case we do not create a new sub-node.
294 struct assign_to_container_from_value<utree::list_type, utree::list_type>
295 : assign_to_container_from_value<utree, utree>
298 ///////////////////////////////////////////////////////////////////////////
299 // this specialization makes sure strings get assigned as a whole and are
300 // not converted into a utree list
302 struct assign_to_container_from_value<utree, utf8_string_type>
304 static void call(utf8_string_type const& val, utree& attr)
309 push_back(attr, val);
313 // this specialization keeps symbols from being transformed into strings
315 struct assign_to_container_from_value<utree, utf8_symbol_type>
317 static void call (utf8_symbol_type const& val, utree& attr)
322 push_back(attr, val);
327 struct assign_to_container_from_value<utree, binary_string_type>
329 static void call(binary_string_type const& val, utree& attr)
334 push_back(attr, val);
339 struct assign_to_container_from_value<utree, utf8_symbol_range_type>
341 static void call (utf8_symbol_range_type const& val, utree& attr)
346 push_back(attr, val);
351 struct assign_to_container_from_value<utree, binary_range_type>
353 static void call(binary_range_type const& val, utree& attr)
358 push_back(attr, val);
363 struct assign_to_container_from_value<utree, std::string>
365 static void call(std::string const& val, utree& attr)
370 push_back(attr, val);
374 ///////////////////////////////////////////////////////////////////////////
375 // this specialization tells Spirit.Qi to allow assignment to an utree from
377 template <typename Iterator>
378 struct assign_to_attribute_from_iterators<utree, Iterator>
381 call(Iterator const& first, Iterator const& last, utree& attr)
384 attr.assign(first, last);
386 for (Iterator i = first; i != last; ++i)
387 push_back(attr, traits::deref(i));
392 ///////////////////////////////////////////////////////////////////////////
393 // Karma only: convert utree node to string
396 struct attribute_as_string_type
398 typedef utf8_string_range_type type;
400 static type call(utree const& attr)
402 return boost::get<utf8_string_range_type>(attr);
405 static bool is_valid(utree const& attr)
407 switch (traits::which(attr))
409 case utree_type::reference_type:
410 return is_valid(attr.deref());
412 case utree_type::string_range_type:
413 case utree_type::string_type:
424 struct attribute_as<std::string, utree>
425 : detail::attribute_as_string_type
429 struct attribute_as<utf8_string_type, utree>
430 : detail::attribute_as_string_type
434 struct attribute_as<utf8_string_range_type, utree>
435 : detail::attribute_as_string_type
438 ///////////////////////////////////////////////////////////////////////////
441 struct attribute_as_symbol_type
443 typedef utf8_symbol_range_type type;
445 static type call(utree const& attr)
447 return boost::get<utf8_symbol_range_type>(attr);
450 static bool is_valid(utree const& attr)
452 switch (traits::which(attr))
454 case utree_type::reference_type:
455 return is_valid(attr.deref());
457 case utree_type::symbol_type:
468 struct attribute_as<utf8_symbol_type, utree>
469 : detail::attribute_as_symbol_type
473 struct attribute_as<utf8_symbol_range_type, utree>
474 : detail::attribute_as_symbol_type
477 template <typename Attribute>
478 struct attribute_as<Attribute, utree::list_type>
479 : attribute_as<Attribute, utree>
482 ///////////////////////////////////////////////////////////////////////////
485 struct attribute_as_binary_string_type
487 typedef binary_range_type type;
489 static type call(utree const& attr)
491 return boost::get<binary_range_type>(attr);
494 static bool is_valid(utree const& attr)
496 switch (traits::which(attr))
498 case utree_type::reference_type:
499 return is_valid(attr.deref());
501 case utree_type::binary_type:
512 struct attribute_as<binary_string_type, utree>
513 : detail::attribute_as_binary_string_type
517 struct attribute_as<binary_range_type, utree>
518 : detail::attribute_as_binary_string_type
521 ///////////////////////////////////////////////////////////////////////////
522 // push_back support for utree
523 template <typename T>
524 struct push_back_container<utree, T>
526 static bool call(utree& c, T const& val)
528 switch (traits::which(c))
530 case utree_type::invalid_type:
531 case utree_type::nil_type:
532 case utree_type::list_type:
549 template <typename T>
550 struct push_back_container<utree::list_type, T>
551 : push_back_container<utree, T>
554 ///////////////////////////////////////////////////////////////////////////
555 // ensure the utree attribute is an empty list
557 struct make_container_attribute<utree>
559 static void call(utree& ut)
561 if (!detail::is_list(ut)) {
562 if (detail::is_uninitialized(ut))
565 utree retval (empty_list);
566 retval.push_back(ut);
574 struct make_container_attribute<utree::list_type>
575 : make_container_attribute<utree>
578 ///////////////////////////////////////////////////////////////////////////
579 // an utree is a container on its own
581 struct build_std_vector<utree>
587 struct build_std_vector<utree::list_type>
589 typedef utree::list_type type;
592 ///////////////////////////////////////////////////////////////////////////
593 // debug support for utree
594 template <typename Out>
595 struct print_attribute_debug<Out, utree>
597 static void call(Out& out, utree const& val)
603 ///////////////////////////////////////////////////////////////////////////
604 // force utree list attribute in a sequence to be dereferenced if a rule
605 // or a grammar exposes an utree as it's attribute
608 // Checks whether the exposed Attribute allows to handle utree or
609 // utree::list_type directly. Returning mpl::false_ from this meta
610 // function will force a new utree instance to be created for each
611 // invocation of the embedded parser.
613 // The purpose of using utree::list_type as an attribute is to force a
614 // new sub-node in the result.
615 template <typename Attribute, typename Enable = void>
616 struct handles_utree_list_container
618 mpl::not_<is_same<utree::list_type, Attribute> >,
619 traits::is_container<Attribute> >
622 // The following specializations make sure that the actual handling of
623 // an utree (or utree::list_type) attribute is deferred to the embedded
624 // parsers of a sequence, alternative or optional component.
625 template <typename Attribute>
626 struct handles_utree_list_container<Attribute
627 , typename enable_if<fusion::traits::is_sequence<Attribute> >::type>
631 template <typename Attribute>
632 struct handles_utree_list_container<boost::optional<Attribute> >
636 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
637 struct handles_utree_list_container<
638 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
644 typename IteratorA, typename IteratorB, typename Context
645 , typename T1, typename T2, typename T3, typename T4>
646 struct handles_container<qi::rule<IteratorA, T1, T2, T3, T4>
647 , utree, Context, IteratorB>
648 : detail::handles_utree_list_container<typename attribute_of<
649 qi::rule<IteratorA, T1, T2, T3, T4>, Context, IteratorB
654 typename IteratorA, typename IteratorB, typename Context
655 , typename T1, typename T2, typename T3, typename T4>
656 struct handles_container<qi::grammar<IteratorA, T1, T2, T3, T4>
657 , utree, Context, IteratorB>
658 : detail::handles_utree_list_container<typename attribute_of<
659 qi::grammar<IteratorA, T1, T2, T3, T4>, Context, IteratorB
664 typename IteratorA, typename IteratorB, typename Context
665 , typename T1, typename T2, typename T3, typename T4>
666 struct handles_container<qi::rule<IteratorA, T1, T2, T3, T4>
667 , utree::list_type, Context, IteratorB>
668 : detail::handles_utree_list_container<typename attribute_of<
669 qi::rule<IteratorA, T1, T2, T3, T4>, Context, IteratorB
674 typename IteratorA, typename IteratorB, typename Context
675 , typename T1, typename T2, typename T3, typename T4>
676 struct handles_container<qi::grammar<IteratorA, T1, T2, T3, T4>
677 , utree::list_type, Context, IteratorB>
678 : detail::handles_utree_list_container<typename attribute_of<
679 qi::grammar<IteratorA, T1, T2, T3, T4>, Context, IteratorB
683 ///////////////////////////////////////////////////////////////////////////
684 template <typename Attribute, typename Sequence>
685 struct pass_through_container<
686 utree, utree, Attribute, Sequence, qi::domain>
687 : detail::handles_utree_list_container<Attribute>
690 template <typename Attribute, typename Sequence>
691 struct pass_through_container<
692 utree::list_type, utree, Attribute, Sequence, qi::domain>
693 : detail::handles_utree_list_container<Attribute>
696 ///////////////////////////////////////////////////////////////////////////
699 // Checks whether the exposed Attribute allows to handle utree or
700 // utree::list_type directly. Returning mpl::false_ from this meta
701 // function will force a new utree instance to be created for each
702 // invocation of the embedded parser.
704 // The purpose of using utree::list_type as an attribute is to force a
705 // new sub-node in the result.
706 template <typename Attribute, typename Enable = void>
707 struct handles_utree_container
709 mpl::not_<is_same<utree, Attribute> >,
710 traits::is_container<Attribute> >
713 // The following specializations make sure that the actual handling of
714 // an utree (or utree::list_type) attribute is deferred to the embedded
715 // parsers of a sequence, alternative or optional component.
716 template <typename Attribute>
717 struct handles_utree_container<Attribute
718 , typename enable_if<fusion::traits::is_sequence<Attribute> >::type>
722 template <typename Attribute>
723 struct handles_utree_container<boost::optional<Attribute> >
727 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
728 struct handles_utree_container<
729 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
735 typename IteratorA, typename IteratorB, typename Context
736 , typename T1, typename T2, typename T3, typename T4>
737 struct handles_container<karma::rule<IteratorA, T1, T2, T3, T4>
738 , utree, Context, IteratorB>
739 : detail::handles_utree_container<typename attribute_of<
740 karma::rule<IteratorA, T1, T2, T3, T4>, Context, IteratorB
745 typename IteratorA, typename IteratorB, typename Context
746 , typename T1, typename T2, typename T3, typename T4>
747 struct handles_container<karma::grammar<IteratorA, T1, T2, T3, T4>
748 , utree, Context, IteratorB>
749 : detail::handles_utree_container<typename attribute_of<
750 karma::grammar<IteratorA, T1, T2, T3, T4>, Context, IteratorB
754 ///////////////////////////////////////////////////////////////////////////
755 template <typename Attribute, typename Sequence>
756 struct pass_through_container<
757 utree, utree, Attribute, Sequence, karma::domain>
758 : detail::handles_utree_container<Attribute>
761 ///////////////////////////////////////////////////////////////////////////
762 // the specialization below tells Spirit how to handle utree if it is used
763 // with an optional component
765 struct optional_attribute<utree>
767 typedef utree const& type;
769 static type call(utree const& val)
774 // only 'invalid_type' utree nodes are not valid
775 static bool is_valid(utree const& val)
777 return !detail::is_uninitialized(val);
782 struct build_optional<utree>
788 struct build_optional<utree::list_type>
790 typedef utree::list_type type;
793 // an utree is an optional (in any domain)
795 struct not_is_optional<utree, qi::domain>
800 struct not_is_optional<utree::list_type, qi::domain>
805 struct not_is_optional<utree, karma::domain>
810 struct not_is_optional<utree::list_type, karma::domain>
814 ///////////////////////////////////////////////////////////////////////////
815 // the specialization below tells Spirit to handle utree as if it
816 // where a 'real' variant (in the context of karma)
818 struct not_is_variant<utree, karma::domain>
823 struct not_is_variant<utree::list_type, karma::domain>
827 // The specializations below tell Spirit to verify whether an attribute
828 // type is compatible with a given variant type
830 struct compute_compatible_component_variant<
831 utree, iterator_range<utree::iterator> >
834 typedef iterator_range<utree::iterator> compatible_type;
836 static bool is_compatible(int d)
838 return d == utree_type::list_type;
843 struct compute_compatible_component_variant<
844 utree, iterator_range<utree::const_iterator> >
847 typedef iterator_range<utree::const_iterator> compatible_type;
849 static bool is_compatible(int d)
851 return d == utree_type::list_type;
856 struct compute_compatible_component_variant<utree, utree::invalid_type>
859 typedef utree::invalid_type compatible_type;
861 static bool is_compatible(int d)
863 return d == utree_type::invalid_type;
868 struct compute_compatible_component_variant<utree, utree::nil_type>
871 typedef utree::nil_type compatible_type;
873 static bool is_compatible(int d)
875 return d == utree_type::nil_type;
880 struct compute_compatible_component_variant<utree, bool>
883 typedef bool compatible_type;
885 static bool is_compatible(int d)
887 return d == utree_type::bool_type;
892 struct compute_compatible_component_variant<utree, int>
895 typedef int compatible_type;
897 static bool is_compatible(int d)
899 return d == utree_type::int_type;
904 struct compute_compatible_component_variant<utree, double>
907 typedef double compatible_type;
909 static bool is_compatible(int d)
911 return d == utree_type::double_type;
916 struct compute_compatible_component_variant<
917 utree, utf8_string_range_type>
920 typedef utf8_string_range_type compatible_type;
922 static bool is_compatible(int d)
924 return d == utree_type::string_type;
929 struct compute_compatible_component_variant<
930 utree, utf8_string_type>
933 typedef utf8_string_type compatible_type;
935 static bool is_compatible(int d)
937 return d == utree_type::string_type;
942 struct compute_compatible_component_variant<
943 utree, utf8_symbol_range_type>
946 typedef utf8_symbol_range_type compatible_type;
948 static bool is_compatible(int d)
950 return d == utree_type::symbol_type;
955 struct compute_compatible_component_variant<
956 utree, utf8_symbol_type>
959 typedef utf8_symbol_type compatible_type;
961 static bool is_compatible(int d)
963 return d == utree_type::symbol_type;
968 struct compute_compatible_component_variant<
969 utree, binary_range_type>
972 typedef binary_range_type compatible_type;
974 static bool is_compatible(int d)
976 return d == utree_type::binary_type;
981 struct compute_compatible_component_variant<
982 utree, binary_string_type>
985 typedef binary_string_type compatible_type;
987 static bool is_compatible(int d)
989 return d == utree_type::binary_type;
994 struct compute_compatible_component_variant<utree, utree>
997 typedef utree compatible_type;
999 static bool is_compatible(int d)
1001 return d >= utree_type::invalid_type &&
1002 d <= utree_type::reference_type;
1007 struct compute_compatible_component_variant<
1008 utree, std::vector<utree> >
1011 typedef utree compatible_type;
1013 static bool is_compatible(int d)
1015 return d >= utree_type::invalid_type &&
1016 d <= utree_type::reference_type;
1020 template <typename Sequence>
1021 struct compute_compatible_component_variant<utree, Sequence
1023 , typename enable_if<fusion::traits::is_sequence<Sequence> >::type>
1026 typedef iterator_range<utree::const_iterator> compatible_type;
1028 static bool is_compatible(int d)
1030 return d == utree_type::list_type;
1034 template <typename Attribute>
1035 struct compute_compatible_component_variant<utree::list_type, Attribute>
1036 : compute_compatible_component_variant<utree, Attribute>
1039 ///////////////////////////////////////////////////////////////////////////
1041 struct symbols_lookup<utree, utf8_symbol_type>
1043 typedef std::string type;
1045 static type call(utree const& t)
1047 utf8_symbol_range_type r = boost::get<utf8_symbol_range_type>(t);
1048 return std::string(traits::begin(r), traits::end(r));
1053 struct symbols_lookup<utf8_symbol_type, utf8_symbol_type>
1055 typedef std::string type;
1057 static type call(utf8_symbol_type const& t)
1063 ///////////////////////////////////////////////////////////////////////////
1066 template <typename T>
1067 inline T get_or_deref(utree const& t)
1069 if (detail::is_list(t))
1070 return boost::get<T>(t.front());
1071 return boost::get<T>(t);
1076 struct extract_from_container<utree, utree::nil_type>
1078 typedef utree::nil_type type;
1080 template <typename Context>
1081 static type call(utree const&, Context&)
1088 struct extract_from_container<utree, char>
1092 template <typename Context>
1093 static type call(utree const& t, Context&)
1095 utf8_symbol_range_type r = detail::get_or_deref<utf8_symbol_range_type>(t);
1101 struct extract_from_container<utree, bool>
1105 template <typename Context>
1106 static type call(utree const& t, Context&)
1108 return detail::get_or_deref<bool>(t);
1113 struct extract_from_container<utree, int>
1117 template <typename Context>
1118 static type call(utree const& t, Context&)
1120 return detail::get_or_deref<int>(t);
1125 struct extract_from_container<utree, double>
1127 typedef double type;
1129 template <typename Context>
1130 static type call(utree const& t, Context&)
1132 return detail::get_or_deref<double>(t);
1136 template <typename Traits, typename Alloc>
1137 struct extract_from_container<utree, std::basic_string<char, Traits, Alloc> >
1139 typedef std::basic_string<char, Traits, Alloc> type;
1141 template <typename Context>
1142 static type call(utree const& t, Context&)
1144 utf8_string_range_type r = detail::get_or_deref<utf8_string_range_type>(t);
1145 return type(traits::begin(r), traits::end(r));
1150 struct extract_from_container<utree, utf8_symbol_type>
1152 typedef std::string type;
1154 template <typename Context>
1155 static type call(utree const& t, Context&)
1157 utf8_symbol_range_type r = detail::get_or_deref<utf8_symbol_range_type>(t);
1158 return std::string(traits::begin(r), traits::end(r));
1163 struct extract_from_container<utree, utf8_string_type>
1165 typedef std::string type;
1167 template <typename Context>
1168 static type call(utree const& t, Context&)
1170 utf8_string_range_type r = detail::get_or_deref<utf8_string_range_type>(t);
1171 return std::string(traits::begin(r), traits::end(r));
1175 ///////////////////////////////////////////////////////////////////////////
1177 struct transform_attribute<utree const, utree::nil_type, karma::domain>
1179 typedef utree::nil_type type;
1181 static type pre(utree const&)
1188 struct transform_attribute<utree const, char, karma::domain>
1192 static type pre(utree const& t)
1194 utf8_string_range_type r = detail::get_or_deref<utf8_string_range_type>(t);
1200 struct transform_attribute<utree const, bool, karma::domain>
1204 static type pre(utree const& t)
1206 return detail::get_or_deref<bool>(t);
1211 struct transform_attribute<utree const, int, karma::domain>
1215 static type pre(utree const& t)
1217 return detail::get_or_deref<int>(t);
1222 struct transform_attribute<utree const, double, karma::domain>
1224 typedef double type;
1226 static type pre(utree const& t)
1228 return detail::get_or_deref<double>(t);
1232 template <typename Traits, typename Alloc>
1233 struct transform_attribute<
1234 utree const, std::basic_string<char, Traits, Alloc>, karma::domain>
1236 typedef std::basic_string<char, Traits, Alloc> type;
1238 static type pre(utree const& t)
1240 utf8_string_range_type r = detail::get_or_deref<utf8_string_range_type>(t);
1241 return type(traits::begin(r), traits::end(r));
1245 // this specialization is used whenever a utree is passed to a rule as part
1247 template <typename Iterator>
1248 struct transform_attribute<
1249 iterator_range<Iterator> const, utree, karma::domain>
1253 static type pre(iterator_range<Iterator> const& t)
1255 // return utree the begin iterator points to
1256 Iterator it = boost::begin(t);
1257 utree result(boost::ref(*it));
1263 ///////////////////////////////////////////////////////////////////////////
1265 struct transform_attribute<utree const, utf8_string_type, karma::domain>
1267 typedef std::string type;
1269 static type pre(utree const& t)
1271 utf8_string_range_type r = detail::get_or_deref<utf8_string_range_type>(t);
1272 return std::string(traits::begin(r), traits::end(r));
1277 struct transform_attribute<utree const, utf8_symbol_type, karma::domain>
1279 typedef std::string type;
1281 static type pre(utree const& t)
1283 utf8_symbol_range_type r = detail::get_or_deref<utf8_symbol_range_type>(t);
1284 return std::string(traits::begin(r), traits::end(r));
1288 template <typename Attribute>
1289 struct transform_attribute<utree::list_type const, Attribute, karma::domain>
1290 : transform_attribute<utree const, Attribute, karma::domain>