|
Boost-Commit : |
From: hartmut.kaiser_at_[hidden]
Date: 2008-08-23 16:37:36
Author: hkaiser
Date: 2008-08-23 16:37:36 EDT (Sat, 23 Aug 2008)
New Revision: 48327
URL: http://svn.boost.org/trac/boost/changeset/48327
Log:
Spirit.Karma: Fixed optional to accept non-optional attributes.
Text files modified:
trunk/boost/spirit/home/karma/operator/optional.hpp | 65 ++++++++++++++++++++++++++-------------
trunk/libs/spirit/test/karma/optional.cpp | 31 +++++++++++++++++++
2 files changed, 74 insertions(+), 22 deletions(-)
Modified: trunk/boost/spirit/home/karma/operator/optional.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/operator/optional.hpp (original)
+++ trunk/boost/spirit/home/karma/operator/optional.hpp 2008-08-23 16:37:36 EDT (Sat, 23 Aug 2008)
@@ -12,6 +12,7 @@
#endif
#include <boost/spirit/home/support/component.hpp>
+#include <boost/spirit/home/support/attribute_of.hpp>
#include <boost/spirit/home/support/attribute_transform.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/optional.hpp>
@@ -21,30 +22,44 @@
namespace detail
{
template <typename Parameter>
- inline bool
- optional_is_valid(boost::optional<Parameter> const& opt)
+ struct optional_attribute
{
- return opt;
- }
+ static inline bool
+ is_valid(boost::optional<Parameter> const& opt)
+ {
+ return opt;
+ }
- inline bool
- optional_is_valid(unused_type)
- {
- return true;
- }
+ static inline bool
+ is_valid(Parameter const&)
+ {
+ return true;
+ }
- template <typename Parameter>
- inline Parameter const&
- optional_get(boost::optional<Parameter> const& opt)
- {
- return get(opt) ;
- }
+ static inline bool
+ is_valid(unused_type)
+ {
+ return true;
+ }
- inline unused_type
- optional_get(unused_type)
- {
- return unused;
- }
+ static inline Parameter const&
+ get(boost::optional<Parameter> const& opt)
+ {
+ return boost::get(opt);
+ }
+
+ static inline Parameter const&
+ get(Parameter const& p)
+ {
+ return p;
+ }
+
+ static inline unused_type
+ get(unused_type)
+ {
+ return unused;
+ }
+ };
}
struct optional
@@ -71,10 +86,16 @@
result_of::subject<Component>::type::director
director;
- if (detail::optional_is_valid(param))
+ typedef typename traits::attribute_of<
+ karma::domain, typename result_of::subject<Component>::type,
+ Context, unused_type
+ >::type attribute_type;
+
+ typedef detail::optional_attribute<attribute_type> optional_type;
+ if (optional_type::is_valid(param))
{
director::generate(subject(component), sink, ctx, d,
- detail::optional_get(param));
+ optional_type::get(param));
}
return true;
}
Modified: trunk/libs/spirit/test/karma/optional.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/optional.cpp (original)
+++ trunk/libs/spirit/test/karma/optional.cpp 2008-08-23 16:37:36 EDT (Sat, 23 Aug 2008)
@@ -31,6 +31,11 @@
}
{
+ int opt = 10;
+ BOOST_TEST(test("10", -int_, opt));
+ }
+
+ {
using namespace boost::spirit::ascii;
boost::optional<int> opt;
@@ -40,6 +45,13 @@
BOOST_TEST(test_delimited("10 ", -int_, opt, space));
}
+ {
+ using namespace boost::spirit::ascii;
+
+ int opt = 10;
+ BOOST_TEST(test_delimited("10 ", -int_, opt, space));
+ }
+
{ // test action
using namespace boost::phoenix;
namespace phoenix = boost::phoenix;
@@ -56,6 +68,15 @@
using namespace boost::phoenix;
namespace phoenix = boost::phoenix;
using namespace boost::spirit::arg_names;
+
+ int n = 1234;
+ BOOST_TEST(test("1234", (-int_)[_1 = phoenix::ref(n)]));
+ }
+
+ { // test action
+ using namespace boost::phoenix;
+ namespace phoenix = boost::phoenix;
+ using namespace boost::spirit::arg_names;
using namespace boost::spirit::ascii;
boost::optional<int> n;
@@ -65,5 +86,15 @@
BOOST_TEST(test_delimited("1234 ", (-int_)[_1 = phoenix::ref(n)], space));
}
+ { // test action
+ using namespace boost::phoenix;
+ namespace phoenix = boost::phoenix;
+ using namespace boost::spirit::arg_names;
+ using namespace boost::spirit::ascii;
+
+ int n = 1234;
+ BOOST_TEST(test_delimited("1234 ", (-int_)[_1 = phoenix::ref(n)], space));
+ }
+
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