Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60313 - trunk/libs/spirit/example/qi/scheme
From: joel_at_[hidden]
Date: 2010-03-07 11:09:51


Author: djowel
Date: 2010-03-07 11:09:50 EST (Sun, 07 Mar 2010)
New Revision: 60313
URL: http://svn.boost.org/trac/boost/changeset/60313

Log:
removed printing from utree API. printing should be user defined.
Text files modified:
   trunk/libs/spirit/example/qi/scheme/utree.hpp | 53 ----------------------
   trunk/libs/spirit/example/qi/scheme/utree_test.cpp | 93 ++++++++++++++++++++++++++++++++-------
   2 files changed, 76 insertions(+), 70 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 11:09:50 EST (Sun, 07 Mar 2010)
@@ -276,7 +276,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);
     bool operator!=(utree const& a, utree const& b);
@@ -588,52 +587,6 @@
         return bind_impl<F, X>(f, x);
     }
 
- struct utree_print
- {
- typedef void result_type;
- std::ostream& out;
- utree_print(std::ostream& out)
- : out(out) {}
-
- void operator()(utree::nil) const
- {
- out << "nil";
- }
-
- template <typename T>
- void operator()(T val) const
- {
- out << val;
- }
-
- void operator()(bool b) const
- {
- out << (b?"true":"false");
- }
-
- template <typename Iterator>
- void operator()(boost::iterator_range<Iterator> const& range) const
- {
- // This code works for both strings and lists
- typedef typename boost::iterator_range<Iterator>::const_iterator iterator;
- bool const is_string = boost::is_pointer<Iterator>::value;
- char const start = is_string ? '"' : '[';
- char const end = is_string ? '"' : ']';
-
- out << start;
- for (iterator i = range.begin(); i != range.end(); ++i)
- {
- if (!is_string)
- {
- if (i != range.begin())
- out << ", ";
- }
- out << *i;
- }
- out << end;
- }
- };
-
     struct utree_is_equal
     {
         typedef bool result_type;
@@ -966,12 +919,6 @@
         return detail::index_impl::apply(l.first, i);
     }
 
- inline std::ostream& operator<<(std::ostream& out, utree const& val)
- {
- utree::visit(val, detail::utree_print(out));
- return out;
- }
-
     inline bool operator==(utree const& a, utree const& b)
     {
         return utree::visit(a, b, detail::utree_is_equal());

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 11:09:50 EST (Sun, 07 Mar 2010)
@@ -1,6 +1,65 @@
 #include "utree.hpp"
 #include <iostream>
 
+namespace
+{
+ void print(scheme::utree const& val, bool no_endl = false);
+ void print(char ch, bool ignored)
+ {
+ std::cout << ch;
+ }
+
+ struct simple_print
+ {
+ typedef void result_type;
+
+ void operator()(scheme::utree::nil) const
+ {
+ std::cout << "nil";
+ }
+
+ template <typename T>
+ void operator()(T val) const
+ {
+ std::cout << val;
+ }
+
+ void operator()(bool b) const
+ {
+ std::cout << (b?"true":"false");
+ }
+
+ template <typename Iterator>
+ void operator()(boost::iterator_range<Iterator> const& range) const
+ {
+ // This code works for both strings and lists
+ typedef typename boost::iterator_range<Iterator>::const_iterator iterator;
+ bool const is_string = boost::is_pointer<Iterator>::value;
+ char const start = is_string ? '"' : '(';
+ char const end = is_string ? '"' : ')';
+
+ std::cout << start;
+ for (iterator i = range.begin(); i != range.end(); ++i)
+ {
+ if (!is_string)
+ {
+ if (i != range.begin())
+ std::cout << ", ";
+ }
+ print(*i, true);
+ }
+ std::cout << end;
+ }
+ };
+
+ inline void print(scheme::utree const& val, bool no_endl)
+ {
+ scheme::utree::visit(val, simple_print());
+ if (!no_endl)
+ std::cout << std::endl;
+ }
+}
+
 int main()
 {
     using scheme::utree;
@@ -13,33 +72,33 @@
 
     {
         utree val;
- std::cout << val << std::endl;
+ print(val);
     }
 
     {
         utree val(true);
- std::cout << val << std::endl;
+ print(val);
     }
 
     {
         utree val(123);
- std::cout << val << std::endl;
+ print(val);
     }
 
     {
         utree val(123.456);
- std::cout << val << std::endl;
+ print(val);
     }
 
     {
         utree val("Hello, World");
- std::cout << val << std::endl;
+ print(val);
         utree val2;
         val2 = val;
- std::cout << val2 << std::endl;
+ print(val2);
         utree val3("Hello, World. Chuckie is back!!!");
         val = val3;
- std::cout << val << std::endl;
+ print(val);
 
         utree val4("Apple");
         utree val5("Apple");
@@ -57,32 +116,32 @@
         val2.push_back(123.456);
         val2.push_back("Mah Doggie");
         val.push_back(val2);
- std::cout << val << std::endl;
- std::cout << val.front() << std::endl;
+ print(val);
+ print(val.front());
 
         utree val3;
         val3.swap(val);
- std::cout << val << std::endl;
+ print(val);
         val3.swap(val);
- std::cout << val << std::endl;
+ print(val);
         val.push_back("Ba Ba Black Sheep");
- std::cout << val << std::endl;
+ print(val);
         val.pop_front();
- std::cout << val << std::endl;
+ print(val);
         utree::iterator i = val.begin();
         ++++i;
         val.insert(i, "Right in the middle");
         BOOST_ASSERT(val.size() == 4);
- std::cout << val << std::endl;
+ print(val);
         val.pop_back();
- std::cout << val << std::endl;
+ print(val);
         BOOST_ASSERT(val.size() == 3);
         val.erase(val.end());
- std::cout << val << std::endl;
+ print(val);
         BOOST_ASSERT(val.size() == 2);
 
         val.insert(val.begin(), val2.begin(), val2.end());
- std::cout << val << std::endl;
+ print(val);
     }
 
     {


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