2
0
mirror of https://github.com/boostorg/spirit.git synced 2026-01-19 04:42:11 +00:00

Spirit: fixing more problems with using adapted ADTs in Kamra

[SVN r71305]
This commit is contained in:
Hartmut Kaiser
2011-04-16 02:10:11 +00:00
parent d4d4dc395f
commit 575df4e144
4 changed files with 151 additions and 24 deletions

View File

@@ -11,14 +11,14 @@ namespace qi = boost::spirit::qi;
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;

View File

@@ -31,12 +31,28 @@ namespace boost { namespace spirit { namespace traits
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 @@ namespace boost { namespace spirit { namespace traits
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<

View File

@@ -32,7 +32,8 @@ namespace boost { namespace spirit { namespace detail
#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;

View File

@@ -15,21 +15,20 @@
#include "test.hpp"
///////////////////////////////////////////////////////////////////////////////
class box
class data1
{
private:
int width_;
int height_;
public:
data1()
: width_(400), height_(400)
{}
box()
: width_(400),
height_(400) {}
box(int width, int height)
: width_(width),
height_(height) {}
data1(int width, int height)
: width_(width), height_(height)
{}
int width() const { return width_;}
int height() const { return height_;}
@@ -39,9 +38,33 @@ public:
};
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 @@ int main ()
{
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();
}