|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60315 - trunk/libs/spirit/example/qi/scheme
From: joel_at_[hidden]
Date: 2010-03-07 11:27:05
Author: djowel
Date: 2010-03-07 11:27:04 EST (Sun, 07 Mar 2010)
New Revision: 60315
URL: http://svn.boost.org/trac/boost/changeset/60315
Log:
more minor tweaks
Text files modified:
trunk/libs/spirit/example/qi/scheme/utree.hpp | 6 +-
trunk/libs/spirit/example/qi/scheme/utree_test.cpp | 74 +++++++++++++++++++++++----------------
2 files changed, 46 insertions(+), 34 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:27:04 EST (Sun, 07 Mar 2010)
@@ -30,7 +30,7 @@
///////////////////////////////////////////////////////////////////////////
// Our utree can store these types. This enum tells us what type
- // of data is stored in the discriminated union.
+ // of data is stored in utree's discriminated union.
///////////////////////////////////////////////////////////////////////////
struct utree_type
{
@@ -51,8 +51,8 @@
// meant to be used stand-alone. This is the internal data representation
// of strings in our utree. This is deliberately a POD to allow it to be
// placed in a union. This POD fast string specifically utilizes
- // (sizeof(double) * 2) - 2 * sizeof(char) (14 bytes in a 32 bit system).
- // Two extra bytes are used by utree to store management info.
+ // (sizeof(double) * 2) - (2 * sizeof(char)). In a 32 bit system, this is
+ // 14 bytes. The two extra bytes are used by utree to store management info.
//
// It is a const string (i.e. immutable). It stores the characters directly
// if possible and only uses the heap if the string does not fit. Null
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:27:04 EST (Sun, 07 Mar 2010)
@@ -3,12 +3,14 @@
namespace
{
- void print(scheme::utree const& val, bool no_endl = false);
- void print(char ch, bool ignored)
- {
- std::cout << ch;
- }
+ ///////////////////////////////////////////////////////////////////////////
+ // simple utree printing facility prints the utree in a single line
+ ///////////////////////////////////////////////////////////////////////////
+ void print(char ch);
+ void print(scheme::utree const& val);
+ void println(scheme::utree const& val);
+ // simple_print visitor
struct simple_print
{
typedef void result_type;
@@ -26,7 +28,7 @@
void operator()(bool b) const
{
- std::cout << (b?"true":"false");
+ std::cout << (b ? "true" : "false");
}
template <typename Iterator>
@@ -38,25 +40,34 @@
char const start = is_string ? '"' : '(';
char const end = is_string ? '"' : ')';
- std::cout << start;
+ print(start);
for (iterator i = range.begin(); i != range.end(); ++i)
{
if (!is_string)
{
if (i != range.begin())
- std::cout << ", ";
+ print(',');
}
- print(*i, true);
+ print(*i);
}
- std::cout << end;
+ print(end);
}
};
- inline void print(scheme::utree const& val, bool no_endl)
+ inline void print(char ch)
+ {
+ std::cout << ch;
+ }
+
+ inline void print(scheme::utree const& val)
{
scheme::utree::visit(val, simple_print());
- if (!no_endl)
- std::cout << std::endl;
+ }
+
+ inline void println(scheme::utree const& val)
+ {
+ print(val);
+ std::cout << std::endl;
}
}
@@ -67,38 +78,39 @@
{
// test the size
- std::cout << sizeof(scheme::utree) << std::endl;
+ std::cout << "size of utree is: "
+ << sizeof(scheme::utree) << " bytes" << std::endl;
}
{
utree val;
- print(val);
+ println(val);
}
{
utree val(true);
- print(val);
+ println(val);
}
{
utree val(123);
- print(val);
+ println(val);
}
{
utree val(123.456);
- print(val);
+ println(val);
}
{
utree val("Hello, World");
- print(val);
+ println(val);
utree val2;
val2 = val;
- print(val2);
+ println(val2);
utree val3("Hello, World. Chuckie is back!!!");
val = val3;
- print(val);
+ println(val);
utree val4("Apple");
utree val5("Apple");
@@ -116,32 +128,32 @@
val2.push_back(123.456);
val2.push_back("Mah Doggie");
val.push_back(val2);
- print(val);
- print(val.front());
+ println(val);
+ println(val.front());
utree val3;
val3.swap(val);
- print(val);
+ println(val);
val3.swap(val);
- print(val);
+ println(val);
val.push_back("Ba Ba Black Sheep");
- print(val);
+ println(val);
val.pop_front();
- print(val);
+ println(val);
utree::iterator i = val.begin();
++++i;
val.insert(i, "Right in the middle");
BOOST_ASSERT(val.size() == 4);
- print(val);
+ println(val);
val.pop_back();
- print(val);
+ println(val);
BOOST_ASSERT(val.size() == 3);
val.erase(val.end());
- print(val);
+ println(val);
BOOST_ASSERT(val.size() == 2);
val.insert(val.begin(), val2.begin(), val2.end());
- print(val);
+ println(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