Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/spirit/home/karma/operator/optional.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // Copyright (c) 2001-2011 Joel de Guzman | |
2 // Copyright (c) 2001-2011 Hartmut Kaiser | |
3 // | |
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | |
7 #if !defined(SPIRIT_KARMA_OPTIONAL_MARCH_31_2007_0852AM) | |
8 #define SPIRIT_KARMA_OPTIONAL_MARCH_31_2007_0852AM | |
9 | |
10 #if defined(_MSC_VER) | |
11 #pragma once | |
12 #endif | |
13 | |
14 #include <boost/spirit/home/karma/domain.hpp> | |
15 #include <boost/spirit/home/karma/generator.hpp> | |
16 #include <boost/spirit/home/karma/meta_compiler.hpp> | |
17 #include <boost/spirit/home/support/info.hpp> | |
18 #include <boost/spirit/home/support/unused.hpp> | |
19 #include <boost/spirit/home/karma/detail/attributes.hpp> | |
20 #include <boost/spirit/home/support/container.hpp> | |
21 #include <boost/spirit/home/support/has_semantic_action.hpp> | |
22 #include <boost/spirit/home/support/handles_container.hpp> | |
23 #include <boost/mpl/assert.hpp> | |
24 #include <boost/optional.hpp> | |
25 #include <boost/type_traits/is_convertible.hpp> | |
26 | |
27 namespace boost { namespace spirit | |
28 { | |
29 /////////////////////////////////////////////////////////////////////////// | |
30 // Enablers | |
31 /////////////////////////////////////////////////////////////////////////// | |
32 template <> | |
33 struct use_operator<karma::domain, proto::tag::negate> // enables -g | |
34 : mpl::true_ {}; | |
35 | |
36 }} | |
37 | |
38 /////////////////////////////////////////////////////////////////////////////// | |
39 namespace boost { namespace spirit { namespace karma | |
40 { | |
41 /////////////////////////////////////////////////////////////////////////// | |
42 template <typename Subject> | |
43 struct optional : unary_generator<optional<Subject> > | |
44 { | |
45 typedef Subject subject_type; | |
46 typedef typename subject_type::properties properties; | |
47 | |
48 // Build a boost::optional from the subject's attribute. Note | |
49 // that boost::optional may return unused_type if the | |
50 // subject's attribute is an unused_type. | |
51 template <typename Context, typename Iterator = unused_type> | |
52 struct attribute | |
53 : traits::build_optional< | |
54 typename traits::attribute_of<Subject, Context, Iterator>::type | |
55 > | |
56 {}; | |
57 | |
58 optional(Subject const& subject) | |
59 : subject(subject) {} | |
60 | |
61 template < | |
62 typename OutputIterator, typename Context, typename Delimiter | |
63 , typename Attribute> | |
64 bool generate(OutputIterator& sink, Context& ctx | |
65 , Delimiter const& d, Attribute const& attr) const | |
66 { | |
67 if (traits::has_optional_value(attr)) | |
68 subject.generate(sink, ctx, d, traits::optional_value(attr)); | |
69 return sink_is_good(sink); | |
70 } | |
71 | |
72 template <typename Context> | |
73 info what(Context& context) const | |
74 { | |
75 return info("optional", subject.what(context)); | |
76 } | |
77 | |
78 Subject subject; | |
79 }; | |
80 | |
81 /////////////////////////////////////////////////////////////////////////// | |
82 // Generator generators: make_xxx function (objects) | |
83 /////////////////////////////////////////////////////////////////////////// | |
84 template <typename Elements, typename Modifiers> | |
85 struct make_composite<proto::tag::negate, Elements, Modifiers> | |
86 : make_unary_composite<Elements, optional> {}; | |
87 | |
88 }}} | |
89 | |
90 namespace boost { namespace spirit { namespace traits | |
91 { | |
92 /////////////////////////////////////////////////////////////////////////// | |
93 template <typename Subject> | |
94 struct has_semantic_action<karma::optional<Subject> > | |
95 : unary_has_semantic_action<Subject> {}; | |
96 | |
97 /////////////////////////////////////////////////////////////////////////// | |
98 template <typename Subject, typename Attribute, typename Context | |
99 , typename Iterator> | |
100 struct handles_container<karma::optional<Subject>, Attribute, Context | |
101 , Iterator> | |
102 : mpl::true_ {}; | |
103 }}} | |
104 | |
105 #endif |