|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71305 - in trunk: boost/spirit/home/support boost/spirit/home/support/detail libs/spirit/example/qi libs/spirit/test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2011-04-15 22:10:12
Author: hkaiser
Date: 2011-04-15 22:10:11 EDT (Fri, 15 Apr 2011)
New Revision: 71305
URL: http://svn.boost.org/trac/boost/changeset/71305
Log:
Spirit: fixing more problems with using adapted ADTs in Kamra
Text files modified:
trunk/boost/spirit/home/support/adapt_adt_attributes.hpp | 100 ++++++++++++++++++++++++++++++++++++++-
trunk/boost/spirit/home/support/detail/what_function.hpp | 3
trunk/libs/spirit/example/qi/german_floating_point.cpp | 16 +++---
trunk/libs/spirit/test/karma/regression_numerics_adapt_adt.cpp | 58 ++++++++++++++++++-----
4 files changed, 152 insertions(+), 25 deletions(-)
Modified: trunk/boost/spirit/home/support/adapt_adt_attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/adapt_adt_attributes.hpp (original)
+++ trunk/boost/spirit/home/support/adapt_adt_attributes.hpp 2011-04-15 22:10:11 EDT (Fri, 15 Apr 2011)
@@ -31,12 +31,28 @@
template <typename T, int N, bool Const>
struct container_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
: container_value<
- typename fusion::extension::adt_attribute_proxy<
- T, N, Const
+ typename remove_reference<
+ typename fusion::extension::adt_attribute_proxy<
+ T, N, Const
+ >::type
>::type
>
{};
+ template <typename T, int N, bool Const>
+ struct container_value<
+ fusion::extension::adt_attribute_proxy<T, N, Const> const>
+ : container_value<
+ typename add_const<
+ typename remove_reference<
+ typename fusion::extension::adt_attribute_proxy<
+ T, N, Const
+ >::type
+ >::type
+ >::type
+ >
+ {};
+
template <typename T, int N, typename Val>
struct push_back_container<
fusion::extension::adt_attribute_proxy<T, N, false>
@@ -59,10 +75,88 @@
template <typename T, int N, bool Const>
struct container_iterator<fusion::extension::adt_attribute_proxy<T, N, Const> >
: container_iterator<
- typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
+ typename remove_reference<
+ typename fusion::extension::adt_attribute_proxy<
+ T, N, Const
+ >::type
+ >::type
>
{};
+ template <typename T, int N, bool Const>
+ struct container_iterator<
+ fusion::extension::adt_attribute_proxy<T, N, Const> const>
+ : container_iterator<
+ typename add_const<
+ typename remove_reference<
+ typename fusion::extension::adt_attribute_proxy<
+ T, N, Const
+ >::type
+ >::type
+ >::type
+ >
+ {};
+
+ template <typename T, int N, bool Const>
+ struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
+ {
+ typedef typename remove_reference<
+ typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
+ >::type container_type;
+
+ static typename container_iterator<container_type>::type
+ call(fusion::extension::adt_attribute_proxy<T, N, Const>& c)
+ {
+ return c.get().begin();
+ }
+ };
+
+ template <typename T, int N, bool Const>
+ struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const> const>
+ {
+ typedef typename add_const<
+ typename remove_reference<
+ typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
+ >::type
+ >::type container_type;
+
+ static typename container_iterator<container_type>::type
+ call(fusion::extension::adt_attribute_proxy<T, N, Const> const& c)
+ {
+ return c.get().begin();
+ }
+ };
+
+ template <typename T, int N, bool Const>
+ struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
+ {
+ typedef typename remove_reference<
+ typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
+ >::type container_type;
+
+ static typename container_iterator<container_type>::type
+ call(fusion::extension::adt_attribute_proxy<T, N, Const>& c)
+ {
+ return c.get().end();
+ }
+ };
+
+ template <typename T, int N, bool Const>
+ struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const> const>
+ {
+ typedef typename add_const<
+ typename remove_reference<
+ typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
+ >::type
+ >::type container_type;
+
+ static typename container_iterator<container_type>::type
+ call(fusion::extension::adt_attribute_proxy<T, N, Const> const& c)
+ {
+ return c.get().end();
+ }
+ };
+
///////////////////////////////////////////////////////////////////////////
template <typename T, int N, typename Val>
struct assign_to_attribute_from_value<
Modified: trunk/boost/spirit/home/support/detail/what_function.hpp
==============================================================================
--- trunk/boost/spirit/home/support/detail/what_function.hpp (original)
+++ trunk/boost/spirit/home/support/detail/what_function.hpp 2011-04-15 22:10:11 EDT (Fri, 15 Apr 2011)
@@ -32,7 +32,8 @@
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
component; // suppresses warning: C4100: 'component' : unreferenced formal parameter
#endif
- get<std::list<info> >(what.value).push_back(component.what(context));
+ boost::get<std::list<info> >(what.value).
+ push_back(component.what(context));
}
info& what;
Modified: trunk/libs/spirit/example/qi/german_floating_point.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/german_floating_point.cpp (original)
+++ trunk/libs/spirit/example/qi/german_floating_point.cpp 2011-04-15 22:10:11 EDT (Fri, 15 Apr 2011)
@@ -11,14 +11,14 @@
template <typename T>
struct german_real_policies : qi::real_policies<T>
{
- template <typename Iterator>
- static bool parse_dot(Iterator& first, Iterator const& last)
- {
- if (first == last || *first != ',')
- return false;
- ++first;
- return true;
- }
+ template <typename Iterator>
+ static bool parse_dot(Iterator& first, Iterator const& last)
+ {
+ if (first == last || *first != ',')
+ return false;
+ ++first;
+ return true;
+ }
};
qi::real_parser<double, german_real_policies<double> > const german_double;
Modified: trunk/libs/spirit/test/karma/regression_numerics_adapt_adt.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/regression_numerics_adapt_adt.cpp (original)
+++ trunk/libs/spirit/test/karma/regression_numerics_adapt_adt.cpp 2011-04-15 22:10:11 EDT (Fri, 15 Apr 2011)
@@ -15,21 +15,20 @@
#include "test.hpp"
///////////////////////////////////////////////////////////////////////////////
-class box
+class data1
{
private:
int width_;
int height_;
public:
-
- box()
- : width_(400),
- height_(400) {}
-
- box(int width, int height)
- : width_(width),
- height_(height) {}
+ data1()
+ : width_(400), height_(400)
+ {}
+
+ data1(int width, int height)
+ : width_(width), height_(height)
+ {}
int width() const { return width_;}
int height() const { return height_;}
@@ -39,9 +38,33 @@
};
BOOST_FUSION_ADAPT_ADT(
- box,
- (int, int, obj.width(), obj.set_width(val) )
- (int, int, obj.height(), obj.set_height(val) )
+ data1,
+ (int, int, obj.width(), obj.set_width(val))
+ (int, int, obj.height(), obj.set_height(val))
+);
+
+///////////////////////////////////////////////////////////////////////////////
+class data2
+{
+private:
+ std::string data_;
+
+public:
+ data2()
+ : data_("test")
+ {}
+
+ data2(std::string const& data)
+ : data_(data)
+ {}
+
+ std::string const& data() const { return data_;}
+ void set_data(std::string const& data) { data_ = data;}
+};
+
+BOOST_FUSION_ADAPT_ADT(
+ data2,
+ (std::string, std::string const&, obj.data(), obj.set_data(val))
);
///////////////////////////////////////////////////////////////////////////////
@@ -52,10 +75,19 @@
{
using boost::spirit::karma::int_;
- box b(800, 600);
+ data1 b(800, 600);
BOOST_TEST(test("width: 800\nheight: 600\n",
"width: " << int_ << "\n" << "height: " << int_ << "\n", b));
}
+ {
+ using boost::spirit::karma::char_;
+ using boost::spirit::karma::string;
+
+ data2 d("test");
+ BOOST_TEST(test("data: test\n", "data: " << +char_ << "\n", d));
+ BOOST_TEST(test("data: test\n", "data: " << string << "\n", d));
+ }
+
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk