Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70562 - in trunk/tools/quickbook: src test/unit
From: dnljms_at_[hidden]
Date: 2011-03-26 07:11:59


Author: danieljames
Date: 2011-03-26 07:11:58 EDT (Sat, 26 Mar 2011)
New Revision: 70562
URL: http://svn.boost.org/trac/boost/changeset/70562

Log:
Quickbook: Release lists from list builder.
Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 8 ++++----
   trunk/tools/quickbook/src/code_snippet.cpp | 2 +-
   trunk/tools/quickbook/src/doc_info_actions.cpp | 2 +-
   trunk/tools/quickbook/src/values.cpp | 33 ++++++++++++++++++++++-----------
   trunk/tools/quickbook/src/values.hpp | 7 +++----
   trunk/tools/quickbook/src/values_parse.hpp | 2 +-
   trunk/tools/quickbook/test/unit/values_test.cpp | 24 +++++++++++++-----------
   7 files changed, 45 insertions(+), 33 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-03-26 07:11:58 EDT (Sat, 26 Mar 2011)
@@ -74,7 +74,7 @@
 
     void element_action::operator()(iterator first, iterator) const
     {
- value_consumer values = actions.values.get();
+ value_consumer values = actions.values.release();
         if(!values.check()) return;
         value v = values.consume();
         if(values.check()) return;
@@ -347,7 +347,7 @@
         assert(tag != 0);
         detail::markup markup = detail::get_markup(tag);
 
- value_consumer values = actions.values.get();
+ value_consumer values = actions.values.release();
         value content = values.consume();
         values.finish();
 
@@ -367,7 +367,7 @@
     {
         saved_suppress = actions.suppress;
     
- value_consumer values = actions.values.get();
+ value_consumer values = actions.values.release();
         bool condition = find(actions.macro,
             values.consume().get_quickbook().c_str());
     
@@ -1109,7 +1109,7 @@
         file_position const pos = first.get_position();
         
         // Get the arguments
- value_consumer values = actions.values.get();
+ value_consumer values = actions.values.release();
 
         bool template_escape = values.check(template_tags::escape);
         if(template_escape) values.consume();

Modified: trunk/tools/quickbook/src/code_snippet.cpp
==============================================================================
--- trunk/tools/quickbook/src/code_snippet.cpp (original)
+++ trunk/tools/quickbook/src/code_snippet.cpp 2011-03-26 07:11:58 EDT (Sat, 26 Mar 2011)
@@ -429,7 +429,7 @@
         append_code();
 
         boost::shared_ptr<snippet_data> snippet = pop_snippet_data();
- value callouts = snippet->callouts.get();
+ value callouts = snippet->callouts.release();
 
         std::string body;
         if(snippet->start_code) {

Modified: trunk/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_actions.cpp (original)
+++ trunk/tools/quickbook/src/doc_info_actions.cpp 2011-03-26 07:11:58 EDT (Sat, 26 Mar 2011)
@@ -73,7 +73,7 @@
         // The doc_info in the file has been parsed. Here's what we'll do
         // *before* anything else.
 
- value_consumer values = actions.values.get();
+ value_consumer values = actions.values.release();
 
         // Skip over invalid attributes
 

Modified: trunk/tools/quickbook/src/values.cpp
==============================================================================
--- trunk/tools/quickbook/src/values.cpp (original)
+++ trunk/tools/quickbook/src/values.cpp 2011-03-26 07:11:58 EDT (Sat, 26 Mar 2011)
@@ -194,7 +194,7 @@
     }
 
     stored_value::stored_value(detail::value_base const& x)
- : detail::value_counted(x.store())
+ : detail::value_counted(x.value_->store())
     {
     }
 
@@ -689,8 +689,10 @@
         struct value_list_impl : public value_node
         {
             value_list_impl(value::tag_type);
- value_list_impl(value_node*, value::tag_type);
+ value_list_impl(value_list_builder&, value::tag_type);
         private:
+ value_list_impl(value_list_impl const&);
+
             char const* type_name() const { return "list"; }
 
             virtual ~value_list_impl();
@@ -708,8 +710,14 @@
             : value_node(tag), head_(&value_nil_impl::instance)
         {}
     
- value_list_impl::value_list_impl(value_node* ptr, value::tag_type tag)
- : value_node(tag), head_(ptr)
+ value_list_impl::value_list_impl(value_list_builder& builder,
+ value::tag_type tag)
+ : value_node(tag), head_(builder.release())
+ {
+ }
+
+ value_list_impl::value_list_impl(value_list_impl const& x)
+ : value_node(x.tag_), head_(x.head_)
         {
             list_ref(head_);
         }
@@ -721,7 +729,7 @@
 
         value_node* value_list_impl::clone() const
         {
- return new value_list_impl(head_, tag_);
+ return new value_list_impl(*this);
         }
 
         value_node* value_list_impl::store()
@@ -750,7 +758,7 @@
             for(;pos2 != &value_nil_impl::instance; pos2 = pos2->next_)
                 build.append(pos2->store());
 
- return new value_list_impl(build.get(), tag_);
+ return new value_list_impl(build, tag_);
         }
 
 
@@ -799,8 +807,11 @@
             if(other.back_ == &head_) other.back_ = &other.head_;
         }
 
- value_node* value_list_builder::get() const {
- return head_;
+ value_node* value_list_builder::release() {
+ value_node* r = head_;
+ head_ = &value_nil_impl::instance;
+ back_ = &head_;
+ return r;
         }
     
         void value_list_builder::append(value_node* item)
@@ -847,8 +858,8 @@
         swap(*store);
     }
 
- value value_builder::get() {
- return value(new detail::value_list_impl(current.get(), list_tag));
+ value value_builder::release() {
+ return value(new detail::value_list_impl(current, list_tag));
     }
 
     void value_builder::reset() {
@@ -876,7 +887,7 @@
     }
 
     void value_builder::finish_list() {
- value list = get();
+ value list = release();
         restore();
         insert(list);
     }

Modified: trunk/tools/quickbook/src/values.hpp
==============================================================================
--- trunk/tools/quickbook/src/values.hpp (original)
+++ trunk/tools/quickbook/src/values.hpp 2011-03-26 07:11:58 EDT (Sat, 26 Mar 2011)
@@ -122,14 +122,13 @@
             int get_int() const
             { return value_->get_int(); }
 
- value_node* store() const { return value_->store(); }
-
         protected:
             value_node* value_;
 
             // value_builder needs to access 'value_' to get the node
             // from a value.
             friend class quickbook::value_builder;
+ friend class quickbook::stored_value;
         };
         
         ////////////////////////////////////////////////////////////////////////
@@ -206,7 +205,7 @@
             value_list_builder(value_node*);
             ~value_list_builder();
             void swap(value_list_builder& b);
- value_node* get() const;
+ value_node* release();
 
             void append(value_node*);
             void sort();
@@ -272,7 +271,7 @@
         void save();
         void restore();
 
- value get();
+ value release();
 
         void reset();
         void set_tag(value::tag_type);

Modified: trunk/tools/quickbook/src/values_parse.hpp
==============================================================================
--- trunk/tools/quickbook/src/values_parse.hpp (original)
+++ trunk/tools/quickbook/src/values_parse.hpp 2011-03-26 07:11:58 EDT (Sat, 26 Mar 2011)
@@ -123,7 +123,7 @@
             , sort(builder)
             {}
     
- value get() { return builder.get(); }
+ value release() { return builder.release(); }
 
         value_builder builder;
         scoped_parser<value_builder_save> save;

Modified: trunk/tools/quickbook/test/unit/values_test.cpp
==============================================================================
--- trunk/tools/quickbook/test/unit/values_test.cpp (original)
+++ trunk/tools/quickbook/test/unit/values_test.cpp 2011-03-26 07:11:58 EDT (Sat, 26 Mar 2011)
@@ -39,7 +39,7 @@
     b.insert(quickbook::bbk_value("d", 8));
     b.sort_list();
     
- quickbook::value_consumer c = b.get();
+ quickbook::value_consumer c = b.release();
     BOOST_TEST(c.check(2)); BOOST_TEST_EQ(c.consume(2).get_boostbook(), "b");
     BOOST_TEST(c.check(5)); c.consume(5);
     BOOST_TEST(c.check(8)); c.consume(8);
@@ -62,8 +62,8 @@
 
     list2.insert(quickbook::bbk_value("c", 3));
 
- quickbook::value_consumer l1 = list1.get(); list1.reset();
- quickbook::value_consumer l2 = list2.get(); list2.reset();
+ quickbook::value_consumer l1 = list1.release();
+ quickbook::value_consumer l2 = list2.release();
 
     BOOST_TEST(l1.check(10));
     BOOST_TEST_EQ(l1.consume(10).get_boostbook(), "b");
@@ -80,18 +80,19 @@
 
 void store_test1()
 {
- quickbook::value q;
+ quickbook::stored_value q;
     
     {
         std::string src = "Hello";
- q = quickbook::qbk_value(
+ quickbook::value q1 = quickbook::qbk_value(
             quickbook::iterator(src.begin()),
             quickbook::iterator(src.end()),
             5);
 
+ BOOST_TEST_EQ(q1.get_quickbook(), "Hello");
+ q = q1;
         BOOST_TEST_EQ(q.get_quickbook(), "Hello");
- q.store();
- BOOST_TEST_EQ(q.get_quickbook(), "Hello");
+ BOOST_TEST_EQ(q1.get_quickbook(), "Hello");
     }
 
     BOOST_TEST_EQ(q.get_quickbook(), "Hello");
@@ -109,7 +110,7 @@
 
 void store_test2()
 {
- quickbook::value q;
+ quickbook::stored_value q;
     
     {
         quickbook::value_builder list1;
@@ -120,11 +121,12 @@
             5));
         list1.insert(quickbook::bbk_value("World", 10));
         
- q = list1.get();
+ quickbook::value q2 = list1.release();
 
+ store_test2_check(q2);
+ q = q2;
         store_test2_check(q);
- q.store();
- store_test2_check(q);
+ store_test2_check(q2);
     }
     store_test2_check(q);
 }


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