|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r67457 - in trunk: boost/spirit/home/support/utree boost/spirit/home/support/utree/detail libs/spirit/test/support
From: hartmut.kaiser_at_[hidden]
Date: 2010-12-26 12:18:29
Author: hkaiser
Date: 2010-12-26 12:18:24 EST (Sun, 26 Dec 2010)
New Revision: 67457
URL: http://svn.boost.org/trac/boost/changeset/67457
Log:
Spirit: touching up utree
Text files modified:
trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp | 25 +++++++++++++++++++------
trunk/boost/spirit/home/support/utree/operators.hpp | 20 ++++++++++----------
trunk/boost/spirit/home/support/utree/utree.hpp | 40 ++++++++++++++++++++++++++++------------
trunk/boost/spirit/home/support/utree/utree_traits.hpp | 31 ++++++++++++++++++++-----------
trunk/libs/spirit/test/support/utree_test.cpp | 17 ++++++++++-------
5 files changed, 87 insertions(+), 46 deletions(-)
Modified: trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp (original)
+++ trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp 2010-12-26 12:18:24 EST (Sun, 26 Dec 2010)
@@ -460,10 +460,10 @@
break;
case type::uninitialized_type:
- return f(uninitialized);
+ return f(utree::uninitialized);
case type::nil_type:
- return f(nil);
+ return f(utree::nil);
case type::bool_type:
return f(x.b);
@@ -523,10 +523,10 @@
break;
case type::uninitialized_type:
- return visit_impl::apply(y, detail::bind(f, uninitialized));
+ return visit_impl::apply(y, detail::bind(f, utree::uninitialized));
case type::nil_type:
- return visit_impl::apply(y, detail::bind(f, nil));
+ return visit_impl::apply(y, detail::bind(f, utree::nil));
case type::bool_type:
return visit_impl::apply(y, detail::bind(f, x.b));
@@ -620,18 +620,24 @@
return new stored_function<F>(*this);
}
- inline utree::utree(uninitialized_type)
+ inline utree::utree(utree::uninitialized_type)
{
s.initialize();
set_type(type::uninitialized_type);
}
- inline utree::utree(nil_type)
+ inline utree::utree(utree::nil_type)
{
s.initialize();
set_type(type::nil_type);
}
+ inline utree::utree(utree::list_type)
+ {
+ s.initialize();
+ ensure_list_type();
+ }
+
inline utree::utree(bool b_)
{
s.initialize();
@@ -780,6 +786,13 @@
return *this;
}
+ inline utree& utree::operator=(list_type)
+ {
+ free();
+ ensure_list_type();
+ return *this;
+ }
+
inline utree& utree::operator=(bool b_)
{
free();
Modified: trunk/boost/spirit/home/support/utree/operators.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/operators.hpp (original)
+++ trunk/boost/spirit/home/support/utree/operators.hpp 2010-12-26 12:18:24 EST (Sun, 26 Dec 2010)
@@ -51,8 +51,8 @@
std::ostream& operator<<(std::ostream& out, utree const& x);
std::istream& operator>>(std::istream& in, utree& x);
- std::ostream& operator<<(std::ostream& out, uninitialized_type const& x);
- std::ostream& operator<<(std::ostream& out, nil_type const& x);
+ std::ostream& operator<<(std::ostream& out, utree::uninitialized_type const& x);
+ std::ostream& operator<<(std::ostream& out, utree::nil_type const& x);
// Logical operators
utree operator&&(utree const& a, utree const& b);
@@ -116,12 +116,12 @@
return static_cast<Base const&>(a) == static_cast<Base const&>(b);
}
- bool operator()(uninitialized_type, uninitialized_type) const
+ bool operator()(utree::uninitialized_type, utree::uninitialized_type) const
{
return true;
}
- bool operator()(nil_type, nil_type) const
+ bool operator()(utree::nil_type, utree::nil_type) const
{
return true;
}
@@ -172,13 +172,13 @@
return static_cast<Base const&>(a) < static_cast<Base const&>(b);
}
- bool operator()(uninitialized_type, uninitialized_type) const
+ bool operator()(utree::uninitialized_type, utree::uninitialized_type) const
{
boost::throw_exception(bad_type_exception());
return false; // no less than comparison for nil
}
- bool operator()(nil_type, nil_type) const
+ bool operator()(utree::nil_type, utree::nil_type) const
{
boost::throw_exception(bad_type_exception());
return false; // no less than comparison for nil
@@ -204,12 +204,12 @@
std::ostream& out;
utree_print(std::ostream& out) : out(out) {}
- void operator()(boost::spirit::uninitialized_type) const
+ void operator()(utree::uninitialized_type) const
{
out << "<uninitialized> ";
}
- void operator()(boost::spirit::nil_type) const
+ void operator()(utree::nil_type) const
{
out << "<nil> ";
}
@@ -493,12 +493,12 @@
return out;
}
- inline std::ostream& operator<<(std::ostream& out, uninitialized_type const& x)
+ inline std::ostream& operator<<(std::ostream& out, utree::uninitialized_type const& x)
{
return out;
}
- inline std::ostream& operator<<(std::ostream& out, nil_type const& x)
+ inline std::ostream& operator<<(std::ostream& out, utree::nil_type const& x)
{
return out;
}
Modified: trunk/boost/spirit/home/support/utree/utree.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/utree.hpp (original)
+++ trunk/boost/spirit/home/support/utree/utree.hpp 2010-12-26 12:18:24 EST (Sun, 26 Dec 2010)
@@ -90,18 +90,6 @@
//]
///////////////////////////////////////////////////////////////////////////
- // The uninitialized type
- ///////////////////////////////////////////////////////////////////////////
- struct uninitialized_type {};
- uninitialized_type const uninitialized = uninitialized_type();
-
- ///////////////////////////////////////////////////////////////////////////
- // The nil type
- ///////////////////////////////////////////////////////////////////////////
- struct nil_type {};
- nil_type const nil = nil_type();
-
- ///////////////////////////////////////////////////////////////////////////
// A typed string with parametric Base storage. The storage can be any
// range or (stl container) of chars.
///////////////////////////////////////////////////////////////////////////
@@ -260,6 +248,22 @@
//[utree
class utree {
public:
+ ///////////////////////////////////////////////////////////////////////
+ // The uninitialized type
+ struct uninitialized_type {};
+ static uninitialized_type const uninitialized;
+
+ ///////////////////////////////////////////////////////////////////////
+ // The nil type
+ struct nil_type {};
+ static nil_type const nil;
+
+ ///////////////////////////////////////////////////////////////////////
+ // The list type, this can be used to initialize an utree to hold an
+ // empty list
+ struct list_type {};
+ static list_type const list;
+
//[utree_container_types
typedef utree value_type;
typedef utree& reference;
@@ -300,6 +304,11 @@
utree(nil_type);
reference operator=(nil_type);
+ // This initializes a `list_type` node, which represents an empty
+ // but valid utree list.
+ utree(list_type);
+ reference operator=(list_type);
+
// This initializes a `boolean_type` node, which can hold 'true' or
// 'false' only.
utree(bool);
@@ -520,6 +529,13 @@
};
//]
+ ///////////////////////////////////////////////////////////////////////////
+ // predefined instances for singular types
+ utree::uninitialized_type const utree::uninitialized = {};
+ utree::nil_type const utree::nil = {};
+ utree::list_type const utree::list = {};
+
+ ///////////////////////////////////////////////////////////////////////////
//[utree_scope
class scope : public boost::iterator_range<utree*> {
public:
Modified: trunk/boost/spirit/home/support/utree/utree_traits.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/utree_traits.hpp (original)
+++ trunk/boost/spirit/home/support/utree/utree_traits.hpp 2010-12-26 12:18:24 EST (Sun, 26 Dec 2010)
@@ -153,6 +153,10 @@
typedef typename traits::container_iterator<Attribute const>::type
iterator_type;
+ // make sure the attribute is a list, at least an empty one
+ if (attr.which() != utree_type::list_type)
+ attr = utree::list;
+
iterator_type end = traits::end(val);
for (iterator_type i = traits::begin(val); i != end; traits::next(i))
push_back(attr, traits::deref(i));
@@ -176,6 +180,11 @@
attr = val;
else {
typedef utree::const_iterator iterator_type;
+
+ // make sure the attribute is a list, at least an empty one
+ if (attr.which() != utree_type::list_type)
+ attr = utree::list;
+
iterator_type end = val.end();
for (iterator_type i = val.begin(); i != end; ++i)
attr.push_back(*i);
@@ -198,7 +207,7 @@
static void post(utree& attr, utree const& val)
{
if (val.which() != utree_type::list_type) {
- utree ut;
+ utree ut (utree::list);
ut.push_back(val);
attr.swap(ut);
}
@@ -587,10 +596,10 @@
};
template <>
- struct compute_compatible_component_variant<utree, uninitialized_type>
+ struct compute_compatible_component_variant<utree, utree::uninitialized_type>
: mpl::true_
{
- typedef uninitialized_type compatible_type;
+ typedef utree::uninitialized_type compatible_type;
static bool is_compatible(int d)
{
@@ -599,10 +608,10 @@
};
template <>
- struct compute_compatible_component_variant<utree, nil_type>
+ struct compute_compatible_component_variant<utree, utree::nil_type>
: mpl::true_
{
- typedef nil_type compatible_type;
+ typedef utree::nil_type compatible_type;
static bool is_compatible(int d)
{
@@ -802,14 +811,14 @@
}
template <>
- struct extract_from_attribute<utree, spirit::nil_type>
+ struct extract_from_attribute<utree, utree::nil_type>
{
- typedef spirit::nil_type type;
+ typedef utree::nil_type type;
template <typename Context>
static type call(utree const&, Context&)
{
- return spirit::nil;
+ return utree::nil;
}
};
@@ -903,13 +912,13 @@
///////////////////////////////////////////////////////////////////////////
template <>
- struct transform_attribute<utree const, spirit::nil_type, karma::domain>
+ struct transform_attribute<utree const, utree::nil_type, karma::domain>
{
- typedef spirit::nil_type type;
+ typedef utree::nil_type type;
static type pre(utree const& t)
{
- return spirit::nil;
+ return utree::nil;
}
};
Modified: trunk/libs/spirit/test/support/utree_test.cpp
==============================================================================
--- trunk/libs/spirit/test/support/utree_test.cpp (original)
+++ trunk/libs/spirit/test/support/utree_test.cpp 2010-12-26 12:18:24 EST (Sun, 26 Dec 2010)
@@ -39,8 +39,6 @@
int main()
{
using boost::spirit::utree;
- using boost::spirit::nil;
- using boost::spirit::uninitialized;
using boost::spirit::utf8_symbol_type;
using boost::spirit::binary_string_type;
@@ -52,11 +50,16 @@
}
{
- utree val(nil);
+ utree val(utree::nil);
BOOST_TEST(check(val, "<nil>"));
}
{
+ utree val(utree::list);
+ BOOST_TEST(check(val, "( )"));
+ }
+
+ {
utree val(true);
BOOST_TEST(check(val, "true"));
}
@@ -148,7 +151,7 @@
BOOST_TEST(check(val, "( 123 \"Chuckie\" ( 123.456 \"Mah Doggie\" ) )"));
BOOST_TEST(check(val.front(), "123"));
- utree val3(nil);
+ utree val3(utree::nil);
val3.swap(val);
BOOST_TEST(val3.size() == 3);
BOOST_TEST(check(val, "<nil>"));
@@ -188,7 +191,7 @@
}
{
- utree a(nil), b(nil);
+ utree a(utree::nil), b(utree::nil);
BOOST_TEST(a == b);
a = 123;
BOOST_TEST(a != b);
@@ -197,7 +200,7 @@
a = 100.00;
BOOST_TEST(a < b);
- b = a = utree(uninitialized);
+ b = a = utree(utree::uninitialized);
BOOST_TEST(a == b);
a.push_back(1);
a.push_back("two");
@@ -212,7 +215,7 @@
}
{
- utree a(nil);
+ utree a(utree::nil);
a.push_back(1);
a.push_back(2);
a.push_back(3);
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