|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60282 - trunk/libs/spirit/example/qi/scheme
From: joel_at_[hidden]
Date: 2010-03-07 05:06:55
Author: djowel
Date: 2010-03-07 05:06:54 EST (Sun, 07 Mar 2010)
New Revision: 60282
URL: http://svn.boost.org/trac/boost/changeset/60282
Log:
updates tweaks
Text files modified:
trunk/libs/spirit/example/qi/scheme/utree.hpp | 51 ++++++++++++++++++---------------------
trunk/libs/spirit/example/qi/scheme/utree_test.cpp | 7 +++++
2 files changed, 31 insertions(+), 27 deletions(-)
Modified: trunk/libs/spirit/example/qi/scheme/utree.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/scheme/utree.hpp (original)
+++ trunk/libs/spirit/example/qi/scheme/utree.hpp 2010-03-07 05:06:54 EST (Sun, 07 Mar 2010)
@@ -14,6 +14,7 @@
#include <boost/noncopyable.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/is_pointer.hpp>
#if defined(BOOST_MSVC)
# pragma warning(push)
@@ -111,7 +112,7 @@
template <typename Iterator>
void construct(Iterator f, Iterator l)
{
- unsigned const size = (l-f)+1;
+ unsigned const size = l-f;
char* str;
if (size <= small_string_size)
{
@@ -129,7 +130,7 @@
this->heap.size = size;
set_type(utree_type::heap_string_type);
}
- for (int i = 0; i != size; ++i)
+ for (std::size_t i = 0; i != size; ++i)
*str++ = *f++;
}
@@ -343,7 +344,6 @@
};
std::ostream& operator<<(std::ostream& out, utree const& val);
-
bool operator==(utree const& a, utree const& b);
bool operator<(utree const& a, utree const& b);
std::ostream& operator<<(std::ostream& out, utree const& val);
@@ -412,7 +412,7 @@
private:
friend class boost::iterator_core_access;
- friend class utree;
+ friend class scheme::utree;
void increment() { node = node->next; }
void decrement() { node = node->prev; }
@@ -595,23 +595,26 @@
out << (b?"true":"false");
}
- void operator()(char const* s) const
- {
- out << '"' << s << '"';
- }
-
template <typename Iterator>
void operator()(boost::iterator_range<Iterator> const& range) const
{
- out << '[';
+ // This code works for both strings and lists
+ bool const is_string = boost::is_pointer<Iterator>::value;
+ char const start = is_string ? '"' : '[';
+ char const end = is_string ? '"' : ']';
+
+ out << start;
for (typename boost::iterator_range<Iterator>::const_iterator
i = range.begin(); i != range.end(); ++i)
{
- if (i != range.begin())
- out << ',';
+ if (!is_string)
+ {
+ if (i != range.begin())
+ out << ',';
+ }
out << *i;
}
- out << ']';
+ out << end;
}
};
@@ -641,6 +644,7 @@
template <typename T>
bool operator()(const T& a, const T& b) const
{
+ // This code works for lists and strings as well
return a == b;
}
@@ -648,11 +652,6 @@
{
return true;
}
-
- bool operator()(char const* a, char const* b) const
- {
- return strcmp(a, b) == 0; // $$$ use utf8 comparison here! $$$
- }
};
struct utree_is_less_than
@@ -681,6 +680,7 @@
template <typename T>
bool operator()(const T& a, const T& b) const
{
+ // This code works for lists and strings as well
return a < b;
}
@@ -689,11 +689,6 @@
BOOST_ASSERT(false);
return false; // no less than comparison for nil
}
-
- bool operator()(char const* a, char const* b) const
- {
- return strcmp(a, b) < 0; // $$$ use utf8 comparison here! $$$
- }
};
template <typename UTreeX, typename UTreeY = UTreeX>
@@ -714,6 +709,7 @@
iterator;
typedef boost::iterator_range<iterator> list_range;
+ typedef boost::iterator_range<string_type> string_range;
typedef detail::utree_type type;
switch (x.get_type())
@@ -730,7 +726,7 @@
case type::list_type:
return f(list_range(iterator(x.l.first), iterator(0)));
default:
- return f(string_type(x.s.str()));
+ return f(string_range(x.s.str(), x.s.str() + x.s.size()));
}
}
@@ -749,6 +745,7 @@
iterator;
typedef boost::iterator_range<iterator> list_range;
+ typedef boost::iterator_range<string_type> string_range;
typedef detail::utree_type type;
switch (x.get_type())
@@ -767,7 +764,8 @@
y, detail::bind<F, list_range>(f,
list_range(iterator(x.l.first), iterator(0))));
default:
- return visit_impl::apply(y, detail::bind(f, string_type(x.s.str())));
+ return visit_impl::apply(y, detail::bind(
+ f, string_range(x.s.str(), x.s.str() + x.s.size())));
}
}
};
@@ -923,8 +921,7 @@
if (this->get_type() == type::nil_type)
{
this->set_type(type::list_type);
- this->l.first = this->l.last = 0;
- this->l.size = 0;
+ this->l.default_construct();
}
else
{
Modified: trunk/libs/spirit/example/qi/scheme/utree_test.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/scheme/utree_test.cpp (original)
+++ trunk/libs/spirit/example/qi/scheme/utree_test.cpp 2010-03-07 05:06:54 EST (Sun, 07 Mar 2010)
@@ -40,6 +40,13 @@
utree val3("Hello, World. Chuckie is back!!!");
val = val3;
std::cout << val << std::endl;
+
+ utree val4("Apple");
+ utree val5("Apple");
+ BOOST_ASSERT(val4 == val5);
+
+ utree val6("ApplePie");
+ BOOST_ASSERT(val4 < val6);
}
{
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