|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56462 - in trunk/boost/spirit/home: karma/numeric karma/numeric/detail support
From: hartmut.kaiser_at_[hidden]
Date: 2009-09-28 19:45:53
Author: hkaiser
Date: 2009-09-28 19:45:52 EDT (Mon, 28 Sep 2009)
New Revision: 56462
URL: http://svn.boost.org/trac/boost/changeset/56462
Log:
Spirit: consolidated stateful tag support
Text files modified:
trunk/boost/spirit/home/karma/numeric/bool.hpp | 72 ++++++++++++++-----------------------
trunk/boost/spirit/home/karma/numeric/bool_policies.hpp | 1
trunk/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp | 24 ++++++++++++
trunk/boost/spirit/home/karma/numeric/detail/real_utils.hpp | 24 ------------
trunk/boost/spirit/home/karma/numeric/real.hpp | 75 ++++++++++++++-------------------------
trunk/boost/spirit/home/support/common_terminals.hpp | 51 ++-------------------------
trunk/boost/spirit/home/support/terminal.hpp | 44 +++++++++++++++++++++++
7 files changed, 128 insertions(+), 163 deletions(-)
Modified: trunk/boost/spirit/home/karma/numeric/bool.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/bool.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/bool.hpp 2009-09-28 19:45:52 EDT (Mon, 28 Sep 2009)
@@ -26,19 +26,6 @@
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit
{
- namespace tag
- {
- template <typename T, typename Policies>
- struct bool_tag
- {
- bool_tag() {}
- bool_tag(Policies const& policies)
- : policies_(policies) {}
-
- Policies policies_;
- };
- }
-
namespace karma
{
///////////////////////////////////////////////////////////////////////
@@ -51,8 +38,14 @@
// order to create a customized int generator
template <typename T = bool, typename Policies = bool_policies<T> >
struct bool_generator
- : spirit::terminal<tag::bool_tag<T, Policies> >
- {};
+ : spirit::terminal<tag::stateful_tag<Policies, tag::bool_, T> >
+ {
+ typedef tag::stateful_tag<Policies, tag::bool_, T> tag_type;
+
+ bool_generator() {}
+ bool_generator(Policies const& data)
+ : spirit::terminal<tag_type>(data) {}
+ };
}
///////////////////////////////////////////////////////////////////////////
@@ -77,19 +70,22 @@
///////////////////////////////////////////////////////////////////////////
// enables any custom bool_generator
- template <typename T, typename Policies>
- struct use_terminal<karma::domain, tag::bool_tag<T, Policies> >
+ template <typename Policies, typename T>
+ struct use_terminal<karma::domain
+ , tag::stateful_tag<Policies, tag::bool_, T> >
: mpl::true_ {};
// enables any custom bool_generator(...)
- template <typename T, typename Policies, typename A0>
+ template <typename Policies, typename T, typename A0>
struct use_terminal<karma::domain
- , terminal_ex<tag::bool_tag<T, Policies>, fusion::vector1<A0> >
- > : mpl::true_ {};
+ , terminal_ex<tag::stateful_tag<Policies, tag::bool_, T>
+ , fusion::vector1<A0> > >
+ : mpl::true_ {};
// enables *lazy* custom bool_generator
- template <typename T, typename Policies>
- struct use_lazy_terminal<karma::domain, tag::bool_tag<T, Policies>, 1>
+ template <typename Policies, typename T>
+ struct use_lazy_terminal<karma::domain
+ , tag::stateful_tag<Policies, tag::bool_, T>, 1>
: mpl::true_ {};
}}
@@ -217,22 +213,6 @@
};
///////////////////////////////////////////////////////////////////////////
- namespace detail
- {
- // extract policies if this is a bool_tag
- template <typename Policies>
- struct get_bool_policies
- {
- template <typename Tag>
- static Policies call(Tag) { return Policies(); }
-
- template <typename T>
- static Policies const& call(tag::bool_tag<T, Policies> const& p)
- { return p.policies_; }
- };
- }
-
- ///////////////////////////////////////////////////////////////////////////
// Generator generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
namespace detail
@@ -257,8 +237,9 @@
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
- using karma::detail::get_bool_policies;
- return result_type(get_bool_policies<Policies>::call(term));
+ typedef tag::stateful_tag<Policies, tag::bool_, T> tag_type;
+ using spirit::detail::get_stateful_data;
+ return result_type(get_stateful_data<tag_type>::call(term));
}
};
}
@@ -269,7 +250,8 @@
: detail::make_bool<Modifiers> {};
template <typename T, typename Policies, typename Modifiers>
- struct make_primitive<tag::bool_tag<T, Policies>, Modifiers>
+ struct make_primitive<
+ tag::stateful_tag<Policies, tag::bool_, T>, Modifiers>
: detail::make_bool<Modifiers, T, Policies> {};
///////////////////////////////////////////////////////////////////////////
@@ -295,9 +277,10 @@
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
- using karma::detail::get_bool_policies;
+ typedef tag::stateful_tag<Policies, tag::bool_, T> tag_type;
+ using spirit::detail::get_stateful_data;
return result_type(fusion::at_c<0>(term.args)
- , get_bool_policies<Policies>::call(term.term));
+ , get_stateful_data<tag_type>::call(term.term));
}
};
}
@@ -310,7 +293,8 @@
template <typename T, typename Policies, typename A0, typename Modifiers>
struct make_primitive<
- terminal_ex<tag::bool_tag<T, Policies>, fusion::vector1<A0> >
+ terminal_ex<tag::stateful_tag<Policies, tag::bool_, T>
+ , fusion::vector1<A0> >
, Modifiers>
: detail::make_bool_direct<Modifiers, T, Policies> {};
Modified: trunk/boost/spirit/home/karma/numeric/bool_policies.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/bool_policies.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/bool_policies.hpp 2009-09-28 19:45:52 EDT (Mon, 28 Sep 2009)
@@ -13,6 +13,7 @@
#include <boost/spirit/home/support/char_class.hpp>
#include <boost/spirit/home/karma/generate.hpp>
#include <boost/spirit/home/karma/char.hpp>
+#include <boost/spirit/home/karma/numeric/detail/numeric_utils.hpp>
namespace boost { namespace spirit { namespace karma
{
Modified: trunk/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp 2009-09-28 19:45:52 EDT (Mon, 28 Sep 2009)
@@ -591,6 +591,30 @@
}
};
+ ///////////////////////////////////////////////////////////////////////////
+ // These are helper functions for the real policies allowing to generate
+ // a single character and a string
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename CharEncoding = unused_type, typename Tag = unused_type>
+ struct char_inserter
+ {
+ template <typename OutputIterator, typename Char>
+ static bool call(OutputIterator& sink, Char c)
+ {
+ return detail::generate_to(sink, c, CharEncoding(), Tag());
+ }
+ };
+
+ template <typename CharEncoding = unused_type, typename Tag = unused_type>
+ struct string_inserter
+ {
+ template <typename OutputIterator, typename String>
+ static bool call(OutputIterator& sink, String str)
+ {
+ return detail::string_generate(sink, str, CharEncoding(), Tag());
+ }
+ };
+
}}}
#endif
Modified: trunk/boost/spirit/home/karma/numeric/detail/real_utils.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/detail/real_utils.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/detail/real_utils.hpp 2009-09-28 19:45:52 EDT (Mon, 28 Sep 2009)
@@ -26,30 +26,6 @@
namespace boost { namespace spirit { namespace karma
{
///////////////////////////////////////////////////////////////////////////
- // These are helper functions for the real policies allowing to generate
- // a single character and a string
- ///////////////////////////////////////////////////////////////////////////
- template <typename CharEncoding = unused_type, typename Tag = unused_type>
- struct char_inserter
- {
- template <typename OutputIterator, typename Char>
- static bool call(OutputIterator& sink, Char c)
- {
- return detail::generate_to(sink, c, CharEncoding(), Tag());
- }
- };
-
- template <typename CharEncoding = unused_type, typename Tag = unused_type>
- struct string_inserter
- {
- template <typename OutputIterator, typename String>
- static bool call(OutputIterator& sink, String str)
- {
- return detail::string_generate(sink, str, CharEncoding(), Tag());
- }
- };
-
- ///////////////////////////////////////////////////////////////////////////
//
// The real_inserter template takes care of the floating point number to
// string conversion. The Policies template parameter is used to allow
Modified: trunk/boost/spirit/home/karma/numeric/real.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/real.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/real.hpp 2009-09-28 19:45:52 EDT (Mon, 28 Sep 2009)
@@ -31,19 +31,6 @@
namespace boost { namespace spirit
{
- namespace tag
- {
- template <typename T, typename Policies>
- struct real_tag
- {
- real_tag() {}
- real_tag(Policies const& policies)
- : policies_(policies) {}
-
- Policies policies_;
- };
- }
-
namespace karma
{
///////////////////////////////////////////////////////////////////////
@@ -56,11 +43,13 @@
// order to create a customized real generator
template <typename T = double, typename Policies = real_policies<T> >
struct real_generator
- : spirit::terminal<tag::real_tag<T, Policies> >
+ : spirit::terminal<tag::stateful_tag<Policies, tag::double_, T> >
{
+ typedef tag::stateful_tag<Policies, tag::double_, T> tag_type;
+
real_generator() {}
real_generator(Policies const& p)
- : spirit::terminal<tag::real_tag<T, Policies> >(p) {}
+ : spirit::terminal<tag_type>(p) {}
};
}
@@ -123,20 +112,22 @@
///////////////////////////////////////////////////////////////////////////
// enables custom real generator
- template <typename T, typename Policy>
- struct use_terminal<karma::domain, tag::real_tag<T, Policy> >
+ template <typename T, typename Policies>
+ struct use_terminal<karma::domain
+ , tag::stateful_tag<Policies, tag::double_, T> >
: mpl::true_ {};
- template <typename T, typename Policy, typename A0>
+ template <typename T, typename Policies, typename A0>
struct use_terminal<karma::domain
- , terminal_ex<tag::real_tag<T, Policy>, fusion::vector1<A0> >
- > : mpl::true_ {};
+ , terminal_ex<tag::stateful_tag<Policies, tag::double_, T>
+ , fusion::vector1<A0> > >
+ : mpl::true_ {};
// enables *lazy* custom real generator
- template <typename T, typename Policy>
+ template <typename T, typename Policies>
struct use_lazy_terminal<
karma::domain
- , tag::real_tag<T, Policy>
+ , tag::stateful_tag<Policies, tag::double_, T>
, 1 // arity
> : mpl::true_ {};
@@ -269,22 +260,6 @@
};
///////////////////////////////////////////////////////////////////////////
- namespace detail
- {
- // extract policies if this is a real_tag
- template <typename Policies>
- struct get_real_policies
- {
- template <typename Tag>
- static Policies call(Tag) { return Policies(); }
-
- template <typename T>
- static Policies const& call(tag::real_tag<T, Policies> const& p)
- { return p.policies_; }
- };
- }
-
- ///////////////////////////////////////////////////////////////////////////
// Generator generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
namespace detail
@@ -308,8 +283,9 @@
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
- using karma::detail::get_real_policies;
- return result_type(get_real_policies<Policies>::call(term));
+ typedef tag::stateful_tag<Policies, tag::double_, T> tag_type;
+ using spirit::detail::get_stateful_data;
+ return result_type(get_stateful_data<tag_type>::call(term));
}
};
}
@@ -327,9 +303,10 @@
: detail::make_real<long double, Modifiers> {};
///////////////////////////////////////////////////////////////////////////
- template <typename T, typename Policy, typename Modifiers>
- struct make_primitive<tag::real_tag<T, Policy>, Modifiers>
- : detail::make_real<T, Modifiers, Policy> {};
+ template <typename T, typename Policies, typename Modifiers>
+ struct make_primitive<
+ tag::stateful_tag<Policies, tag::double_, T>, Modifiers>
+ : detail::make_real<T, Modifiers, Policies> {};
///////////////////////////////////////////////////////////////////////////
namespace detail
@@ -354,9 +331,10 @@
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
- using karma::detail::get_real_policies;
+ typedef tag::stateful_tag<Policies, tag::double_, T> tag_type;
+ using spirit::detail::get_stateful_data;
return result_type(T(fusion::at_c<0>(term.args))
- , get_real_policies<Policies>::call(term.term));
+ , get_stateful_data<tag_type>::call(term.term));
}
};
}
@@ -377,11 +355,12 @@
: detail::make_real_direct<long double, Modifiers> {};
///////////////////////////////////////////////////////////////////////////
- template <typename T, typename Policy, typename A0, typename Modifiers>
+ template <typename T, typename Policies, typename A0, typename Modifiers>
struct make_primitive<
- terminal_ex<tag::real_tag<T, Policy>, fusion::vector1<A0> >
+ terminal_ex<tag::stateful_tag<Policies, tag::double_, T>
+ , fusion::vector1<A0> >
, Modifiers>
- : detail::make_real_direct<T, Modifiers, Policy> {};
+ : detail::make_real_direct<T, Modifiers, Policies> {};
///////////////////////////////////////////////////////////////////////////
namespace detail
Modified: trunk/boost/spirit/home/support/common_terminals.hpp
==============================================================================
--- trunk/boost/spirit/home/support/common_terminals.hpp (original)
+++ trunk/boost/spirit/home/support/common_terminals.hpp 2009-09-28 19:45:52 EDT (Mon, 28 Sep 2009)
@@ -80,53 +80,10 @@
( attr )
)
- ///////////////////////////////////////////////////////////////////////////
- // support for attr_cast
- namespace tag
- {
- template <typename Attribute, typename Expr>
- struct attr_cast_tag
- {
- attr_cast_tag() {}
- attr_cast_tag(Expr const& expr) : expr_(expr) {}
-
- Expr expr_;
- };
- }
-
- namespace detail
- {
- // extract expression if this is a attr_cast_tag
- template <typename Expr>
- struct get_expr
- {
- template <typename Tag>
- static Expr call(Tag) { return Expr(); }
-
- template <typename Attribute>
- static Expr const&
- call(tag::attr_cast_tag<Attribute, Expr> const& t)
- { return t.expr_; }
- };
- }
-
- // thats the terminal used to identify a attr_cast<>() component
- template <typename Attribute, typename Expr>
- struct attr_cast_type
- : spirit::terminal<tag::attr_cast_tag<Attribute, Expr> >
- {
- attr_cast_type() {}
- attr_cast_type(Expr const& expr)
- : spirit::terminal<tag::attr_cast_tag<Attribute, Expr> >(expr) {}
- };
-
- // This one is the function that the user can call directly in order
- // to create a customized attr_cast component
- template <typename Attribute, typename Expr>
- attr_cast_type<Attribute, Expr>
- attr_cast(Expr const& expr)
- {
- return attr_cast_type<Attribute, Expr>(expr);
+ // special tags (used mainly for stateful tag types)
+ namespace tag
+ {
+ struct attr_cast {};
}
}}
Modified: trunk/boost/spirit/home/support/terminal.hpp
==============================================================================
--- trunk/boost/spirit/home/support/terminal.hpp (original)
+++ trunk/boost/spirit/home/support/terminal.hpp 2009-09-28 19:45:52 EDT (Mon, 28 Sep 2009)
@@ -432,6 +432,50 @@
};
}
+ ///////////////////////////////////////////////////////////////////////////
+ // support for stateful tag types
+ namespace tag
+ {
+ template <typename Data, typename Tag, typename DataTag = unused_type>
+ struct stateful_tag
+ {
+ typedef Data data_type;
+
+ stateful_tag() {}
+ stateful_tag(data_type const& data) : data_(data) {}
+
+ data_type data_;
+ };
+ }
+
+ template <typename Data, typename Tag, typename DataTag = unused_type>
+ struct stateful_tag_type
+ : spirit::terminal<tag::stateful_tag<Data, Tag, DataTag> >
+ {
+ typedef tag::stateful_tag<Data, Tag, DataTag> tag_type;
+
+ stateful_tag_type() {}
+ stateful_tag_type(Data const& data)
+ : spirit::terminal<tag_type>(data) {}
+ };
+
+ namespace detail
+ {
+ // extract expression if this is a Tag
+ template <typename StatefulTag>
+ struct get_stateful_data
+ {
+ typedef typename StatefulTag::data_type data_type;
+
+ // is invoked if given tag is != Tag
+ template <typename Tag_>
+ static data_type call(Tag_) { return data_type(); }
+
+ // this is invoked if given tag is same as'Tag'
+ static data_type const& call(StatefulTag const& t) { return t.data_; }
+ };
+ }
+
}}
// Define a spirit terminal. This macro may be placed in any namespace.
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