]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/regression_adapt_adt.cpp
1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 // Copyright (c) 2011 Colin Rundel
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)
7 #include <boost/mpl/print.hpp>
8 #include <boost/config/warning_disable.hpp>
9 #include <boost/detail/lightweight_test.hpp>
11 #include <boost/fusion/include/adapt_adt.hpp>
13 #include <boost/spirit/include/karma.hpp>
14 #include <boost/spirit/include/support_adapt_adt_attributes.hpp>
18 ///////////////////////////////////////////////////////////////////////////////
27 : width_(400), height_(400)
30 data1(int width
, int height
)
31 : width_(width
), height_(height
)
34 int const& width() const { return width_
;}
35 int const& height() const { return height_
;}
37 void set_width(int width
) { width_
= width
;}
38 void set_height(int height
) { height_
= height
;}
41 BOOST_FUSION_ADAPT_ADT(
43 (int, int const&, obj
.width(), obj
.set_width(val
))
44 (int, int const&, obj
.height(), obj
.set_height(val
))
47 ///////////////////////////////////////////////////////////////////////////////
58 data2(std::string
const& data
)
62 std::string
const& data() const { return data_
;}
63 void set_data(std::string
const& data
) { data_
= data
;}
66 BOOST_FUSION_ADAPT_ADT(
68 (std::string
, std::string
const&, obj
.data(), obj
.set_data(val
))
71 ///////////////////////////////////////////////////////////////////////////////
78 data3(double data
= 0.0)
82 double const& data() const { return data_
;}
83 void set_data(double data
) { data_
= data
;}
86 BOOST_FUSION_ADAPT_ADT(
88 (double, double const&, obj
.data(), obj
.set_data(val
))
91 ///////////////////////////////////////////////////////////////////////////////
95 boost::optional
<int> a_
;
96 boost::optional
<double> b_
;
97 boost::optional
<std::string
> c_
;
99 boost::optional
<int> const& a() const { return a_
; }
100 boost::optional
<double> const& b() const { return b_
; }
101 boost::optional
<std::string
> const& c() const { return c_
; }
105 BOOST_FUSION_ADAPT_ADT(
107 (boost::optional
<int>, boost::optional
<int> const&, obj
.a(), /**/)
108 (boost::optional
<double>, boost::optional
<double> const&, obj
.b(), /**/)
109 (boost::optional
<std::string
>, boost::optional
<std::string
> const&, obj
.c(), /**/)
112 ///////////////////////////////////////////////////////////////////////////////
115 using spirit_test::test
;
118 using boost::spirit::karma::int_
;
121 BOOST_TEST(test("width: 800\nheight: 600\n",
122 "width: " << int_
<< "\n" << "height: " << int_
<< "\n", b
));
126 using boost::spirit::karma::char_
;
127 using boost::spirit::karma::string
;
130 BOOST_TEST(test("data: test\n", "data: " << +char_
<< "\n", d
));
131 BOOST_TEST(test("data: test\n", "data: " << string
<< "\n", d
));
135 using boost::spirit::karma::double_
;
137 BOOST_TEST(test("x=0.0\n", "x=" << double_
<< "\n", data3(0)));
138 BOOST_TEST(test("x=1.1\n", "x=" << double_
<< "\n", data3(1.1)));
139 BOOST_TEST(test("x=1.0e10\n", "x=" << double_
<< "\n", data3(1e10
)));
141 BOOST_TEST(test("x=inf\n", "x=" << double_
<< "\n",
142 data3(std::numeric_limits
<double>::infinity())));
143 if (std::numeric_limits
<double>::has_quiet_NaN
) {
144 BOOST_TEST(test("x=nan\n", "x=" << double_
<< "\n",
145 data3(std::numeric_limits
<double>::quiet_NaN())));
147 if (std::numeric_limits
<double>::has_signaling_NaN
) {
148 BOOST_TEST(test("x=nan\n", "x=" << double_
<< "\n",
149 data3(std::numeric_limits
<double>::signaling_NaN())));
154 using boost::spirit::karma::double_
;
155 using boost::spirit::karma::int_
;
156 using boost::spirit::karma::string
;
162 "Testing: b: 10.0\n",
163 "Testing: " << -("a: " << int_
<< "\n")
164 << -("b: " << double_
<< "\n")
165 << -("c: " << string
<< "\n"), d
));
168 return boost::report_errors();