|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71999 - in trunk: boost/spirit/home/support/utree/detail libs/spirit/test/support
From: blelbach_at_[hidden]
Date: 2011-05-16 16:27:27
Author: wash
Date: 2011-05-16 16:27:26 EDT (Mon, 16 May 2011)
New Revision: 71999
URL: http://svn.boost.org/trac/boost/changeset/71999
Log:
Allow tags for strings.
Text files modified:
trunk/boost/spirit/home/support/utree/detail/utree_detail1.hpp | 2
trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp | 47 +++++++++++++--------------------------
trunk/libs/spirit/test/support/utree.cpp | 39 +++++++++++++++++++++++---------
3 files changed, 45 insertions(+), 43 deletions(-)
Modified: trunk/boost/spirit/home/support/utree/detail/utree_detail1.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/detail/utree_detail1.hpp (original)
+++ trunk/boost/spirit/home/support/utree/detail/utree_detail1.hpp 2011-05-16 16:27:26 EDT (Mon, 16 May 2011)
@@ -105,7 +105,7 @@
small_string_size = buff_size-sizeof(char);
static std::size_t const
- max_string_len = small_string_size - 1;
+ max_string_len = small_string_size - 3;
struct heap_store
{
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 2011-05-16 16:27:26 EDT (Mon, 16 May 2011)
@@ -43,15 +43,11 @@
inline short fast_string::tag() const
{
- // warning the tag is not allowed for fast_string!!! it's only
- // placed here to avoid excess padding.
return (int(buff[small_string_size-2]) << 8) + (unsigned char)buff[small_string_size-1];
}
inline void fast_string::tag(short tag)
{
- // warning the tag is not allowed for fast_string!!! it's only
- // placed here to avoid excess padding.
buff[small_string_size-2] = tag >> 8;
buff[small_string_size-1] = tag & 0xff;
}
@@ -66,7 +62,7 @@
if (is_heap_allocated())
return heap.size;
else
- return max_string_len - buff[small_string_size - 1];
+ return max_string_len - buff[max_string_len];
}
inline char const* fast_string::str() const
@@ -87,7 +83,7 @@
// if it fits, store it in-situ; small_string_size minus the length
// of the string is placed in buff[small_string_size - 1]
str = buff;
- buff[small_string_size - 1] = static_cast<char>(max_string_len - size);
+ buff[max_string_len] = static_cast<char>(max_string_len - size);
info() &= ~0x1;
}
else
@@ -1265,10 +1261,22 @@
if (t == type::list_type)
return l.size;
+ if (t == type::string_type)
+ return s.size();
+
+ if (t == type::symbol_type)
+ return s.size();
+
+ if (t == type::binary_type)
+ return s.size();
+
+ if (t == type::string_range_type)
+ return sr.last - sr.first;
+
if (t != type::nil_type)
BOOST_THROW_EXCEPTION(
bad_type_exception
- ("size() called on non-list utree type",
+ ("size() called on non-list and non-string utree type",
get_type()));
return 0;
@@ -1462,6 +1470,7 @@
case type::symbol_type:
case type::binary_type:
s.copy(other.s);
+ s.tag(other.s.tag());
break;
case type::list_type:
l.copy(other.l);
@@ -1549,35 +1558,11 @@
inline short utree::tag() const
{
- switch (get_type())
- {
- case type::string_type:
- case type::string_range_type:
- case type::binary_type:
- case type::symbol_type:
- BOOST_THROW_EXCEPTION(
- bad_type_exception(
- "tag() called on string utree type", get_type()));
- default:
- break;
- }
return s.tag();
}
inline void utree::tag(short tag)
{
- switch (get_type())
- {
- case type::string_type:
- case type::string_range_type:
- case type::binary_type:
- case type::symbol_type:
- BOOST_THROW_EXCEPTION(
- bad_type_exception(
- "tag() called on string utree type", get_type()));
- default:
- break;
- }
s.tag(tag);
}
Modified: trunk/libs/spirit/test/support/utree.cpp
==============================================================================
--- trunk/libs/spirit/test/support/utree.cpp (original)
+++ trunk/libs/spirit/test/support/utree.cpp 2011-05-16 16:27:26 EDT (Mon, 16 May 2011)
@@ -159,42 +159,42 @@
utree val;
val.push_back(123);
val.push_back("Chuckie");
- BOOST_TEST_EQ(val.size(), 2);
+ BOOST_TEST_EQ(val.size(), 2U);
utree val2;
val2.push_back(123.456);
val2.push_back("Mah Doggie");
val.push_back(val2);
- BOOST_TEST_EQ(val.size(), 3);
+ BOOST_TEST_EQ(val.size(), 3U);
BOOST_TEST(check(val, "( 123 \"Chuckie\" ( 123.456 \"Mah Doggie\" ) )"));
BOOST_TEST(check(val.front(), "123"));
utree val3(nil);
val3.swap(val);
- BOOST_TEST_EQ(val3.size(), 3);
+ BOOST_TEST_EQ(val3.size(), 3U);
BOOST_TEST(check(val, "<nil>"));
val3.swap(val);
BOOST_TEST(check(val, "( 123 \"Chuckie\" ( 123.456 \"Mah Doggie\" ) )"));
val.push_back("another string");
- BOOST_TEST_EQ(val.size(), 4);
+ BOOST_TEST_EQ(val.size(), 4U);
BOOST_TEST(check(val, "( 123 \"Chuckie\" ( 123.456 \"Mah Doggie\" ) \"another string\" )"));
val.pop_front();
BOOST_TEST(check(val, "( \"Chuckie\" ( 123.456 \"Mah Doggie\" ) \"another string\" )"));
utree::iterator i = val.begin();
++++i;
val.insert(i, "Right in the middle");
- BOOST_TEST_EQ(val.size(), 4);
+ BOOST_TEST_EQ(val.size(), 4U);
BOOST_TEST(check(val, "( \"Chuckie\" ( 123.456 \"Mah Doggie\" ) \"Right in the middle\" \"another string\" )"));
val.pop_back();
BOOST_TEST(check(val, "( \"Chuckie\" ( 123.456 \"Mah Doggie\" ) \"Right in the middle\" )"));
- BOOST_TEST_EQ(val.size(), 3);
+ BOOST_TEST_EQ(val.size(), 3U);
utree::iterator it = val.end(); --it;
val.erase(it);
BOOST_TEST(check(val, "( \"Chuckie\" ( 123.456 \"Mah Doggie\" ) )"));
- BOOST_TEST_EQ(val.size(), 2);
+ BOOST_TEST_EQ(val.size(), 2U);
val.insert(val.begin(), val2.begin(), val2.end());
BOOST_TEST(check(val, "( 123.456 \"Mah Doggie\" \"Chuckie\" ( 123.456 \"Mah Doggie\" ) )"));
- BOOST_TEST_EQ(val.size(), 4);
+ BOOST_TEST_EQ(val.size(), 4U);
}
{
@@ -380,11 +380,28 @@
{
// check the tag
- // TODO: test tags on all utree types (some are invalid and should
- // throw).
+ // TODO: test tags on all utree types
utree x;
x.tag(123);
BOOST_TEST_EQ(x.tag(), 123);
+
+ x = "hello world! my name is bob the builder";
+ x.tag(123);
+ BOOST_TEST_EQ(x.tag(), 123);
+
+ x.tag(456);
+ BOOST_TEST_EQ(x.tag(), 456);
+ BOOST_TEST_EQ(x.size(), 39U);
+ BOOST_TEST(check(x, "\"hello world! my name is bob the builder\""));
+
+ x = "hello";
+ x.tag(456);
+ BOOST_TEST_EQ(x.tag(), 456);
+
+ x.tag(789);
+ BOOST_TEST_EQ(x.tag(), 789);
+ BOOST_TEST_EQ(x.size(), 5U);
+ BOOST_TEST(check(x, "\"hello\""));
}
{
@@ -420,7 +437,7 @@
utree alias(utree::range(i, val.end()), shallow);
BOOST_TEST(check(alias, "( 2 3 4 )"));
- BOOST_TEST_EQ(alias.size(), 3);
+ BOOST_TEST_EQ(alias.size(), 3U);
BOOST_TEST_EQ(alias.front(), 2);
BOOST_TEST_EQ(alias.back(), 4);
BOOST_TEST(!alias.empty());
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