Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56970 - in branches/release/libs/spirit: . example example/karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-10-17 15:33:58


Author: hkaiser
Date: 2009-10-17 15:33:57 EDT (Sat, 17 Oct 2009)
New Revision: 56970
URL: http://svn.boost.org/trac/boost/changeset/56970

Log:
Spirit: merging from trunk
Added:
   branches/release/libs/spirit/example/karma/customize_counter.cpp
      - copied, changed from r56858, /trunk/libs/spirit/example/karma/customize_counter.cpp
   branches/release/libs/spirit/example/karma/customize_embedded_container.cpp
      - copied, changed from r56858, /trunk/libs/spirit/example/karma/customize_embedded_container.cpp
   branches/release/libs/spirit/example/karma/customize_use_as_container.cpp
      - copied, changed from r56858, /trunk/libs/spirit/example/karma/customize_use_as_container.cpp
   branches/release/libs/spirit/example/karma/generate_code.cpp
      - copied, changed from r56747, /trunk/libs/spirit/example/karma/generate_code.cpp
Properties modified:
   branches/release/libs/spirit/ (props changed)
   branches/release/libs/spirit/example/ (props changed)
Text files modified:
   branches/release/libs/spirit/example/karma/customize_counter.cpp | 28 +++++++++++++++++++++++++++-
   branches/release/libs/spirit/example/karma/customize_embedded_container.cpp | 25 +++++++++++--------------
   branches/release/libs/spirit/example/karma/customize_use_as_container.cpp | 36 +++++++++++++++++++++++++++++++-----
   branches/release/libs/spirit/example/karma/generate_code.cpp | 5 +++--
   branches/release/libs/spirit/example/karma/reference.cpp | 4 ++--
   5 files changed, 74 insertions(+), 24 deletions(-)

Copied: branches/release/libs/spirit/example/karma/customize_counter.cpp (from r56858, /trunk/libs/spirit/example/karma/customize_counter.cpp)
==============================================================================
--- /trunk/libs/spirit/example/karma/customize_counter.cpp (original)
+++ branches/release/libs/spirit/example/karma/customize_counter.cpp 2009-10-17 15:33:57 EDT (Sat, 17 Oct 2009)
@@ -10,7 +10,6 @@
 //[customize_karma_counter_includes
 #include <boost/spirit/include/karma.hpp>
 #include <iostream>
-#include <string>
 #include <vector>
 //]
 
@@ -20,7 +19,10 @@
 {
     struct counter
     {
+ // expose the current value of the counter as our iterator
         typedef int iterator;
+
+ // expose 'int' as the type of each generated element
         typedef int type;
 
         counter(int max_count)
@@ -36,19 +38,36 @@
 //[customize_karma_counter_traits
 // All specializations of attribute customization points have to be placed into
 // the namespace boost::spirit::traits.
+//
+// Note that all templates below are specialized using the 'const' type.
+// This is necessary as all attributes in Karma are 'const'.
 namespace boost { namespace spirit { namespace traits
 {
+ // The specialization of the template 'is_container<>' will tell the
+ // library to treat the type 'client::counter' as a container providing
+ // the items to generate output from.
     template <>
     struct is_container<client::counter const>
       : mpl::true_
     {};
 
+ // The specialization of the template 'container_iterator<>' will be
+ // invoked by the library to evaluate the iterator type to be used
+ // for iterating the data elements in the container.
     template <>
     struct container_iterator<client::counter const>
     {
         typedef client::counter::iterator type;
     };
 
+ // The specialization of the templates 'begin_container<>' and
+ // 'end_container<>' below will be used by the library to get the iterators
+ // pointing to the begin and the end of the data to generate output from.
+ // These specializations respectively return the initial and maximum
+ // counter values.
+ //
+ // The passed argument refers to the attribute instance passed to the list
+ // generator.
     template <>
     struct begin_container<client::counter const>
     {
@@ -72,8 +91,14 @@
 //]
 
 //[customize_karma_counter_iterator_traits
+// All specializations of attribute customization points have to be placed into
+// the namespace boost::spirit::traits.
 namespace boost { namespace spirit { namespace traits
 {
+ // The specialization of the template 'deref_iterator<>' will be used to
+ // dereference the iterator associated with our counter data structure.
+ // Since we expose the current value as the iterator we just return the
+ // current iterator as the return value.
     template <>
     struct deref_iterator<client::counter::iterator>
     {
@@ -85,6 +110,7 @@
         }
     };
 }}}
+//]
 
 ///////////////////////////////////////////////////////////////////////////////
 namespace karma = boost::spirit::karma;

Copied: branches/release/libs/spirit/example/karma/customize_embedded_container.cpp (from r56858, /trunk/libs/spirit/example/karma/customize_embedded_container.cpp)
==============================================================================
--- /trunk/libs/spirit/example/karma/customize_embedded_container.cpp (original)
+++ branches/release/libs/spirit/example/karma/customize_embedded_container.cpp 2009-10-17 15:33:57 EDT (Sat, 17 Oct 2009)
@@ -35,13 +35,14 @@
 //[customize_karma_embedded_container_traits
 // All specializations of attribute customization points have to be placed into
 // the namespace boost::spirit::traits.
+//
+// Note that all templates below are specialized using the 'const' type.
+// This is necessary as all attributes in Karma are 'const'.
 namespace boost { namespace spirit { namespace traits
 {
     // The specialization of the template 'is_container<>' will tell the
     // library to treat the type 'client::embedded_container' as a
     // container holding the items to generate output from.
- // Note that all templates below are specialized using the 'const' type.
- // This is necessary as all attributes in Karma are 'const'.
     template <>
     struct is_container<client::embedded_container const>
       : mpl::true_
@@ -57,15 +58,17 @@
         typedef client::embedded_container::iterator type;
     };
 
- // The specialization of the template 'begin_container<>' will be used
- // by the library to get the iterator pointing to the first element of
- // the data to generate output from. This specialization simply returns
- // the 'begin' iterator as exposed by the embedded 'std::vector<int>'.
+ // The specialization of the templates 'begin_container<>' and
+ // 'end_container<>' below will be used by the library to get the iterators
+ // pointing to the begin and the end of the data to generate output from.
+ // These specializations simply return the 'begin' and 'end' iterators as
+ // exposed by the embedded 'std::vector<int>'.
+ //
+ // The passed argument refers to the attribute instance passed to the list
+ // generator.
     template <>
     struct begin_container<client::embedded_container const>
     {
- // The passed argument refers to the attribute instance passed to the
- // list generator.
         static client::embedded_container::iterator
         call(client::embedded_container const& d)
         {
@@ -73,15 +76,9 @@
         }
     };
 
- // The specialization of the template 'end_container<>' will be used
- // by the library to get the iterator pointing to the end of the data
- // to generate output from. This specialization simply returns the 'end'
- // iterator as exposed by the embedded 'std::vector<int>'.
     template <>
     struct end_container<client::embedded_container const>
     {
- // The passed argument refers to the attribute instance passed to the
- // list generator.
         static client::embedded_container::iterator
         call(client::embedded_container const& d)
         {

Copied: branches/release/libs/spirit/example/karma/customize_use_as_container.cpp (from r56858, /trunk/libs/spirit/example/karma/customize_use_as_container.cpp)
==============================================================================
--- /trunk/libs/spirit/example/karma/customize_use_as_container.cpp (original)
+++ branches/release/libs/spirit/example/karma/customize_use_as_container.cpp 2009-10-17 15:33:57 EDT (Sat, 17 Oct 2009)
@@ -16,12 +16,14 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 //[customize_karma_use_as_container_data
-// All specializations of attribute customization points have to be placed into
-// the namespace boost::spirit::traits.
 namespace client
 {
     struct use_as_container
     {
+ // Expose a pair holding a pointer to the use_as_container and to the
+ // current element as our iterator.
+ // We intentionally leave out having it a 'operator==()' to demonstrate
+ // the use of the 'compare_iterators' customization point.
         struct iterator
         {
             iterator(use_as_container const* container, int const* current)
@@ -31,10 +33,12 @@
             use_as_container const* container_;
             int const* current_;
         };
+
+ // expose 'int' as the type of each generated element
         typedef int type;
 
- use_as_container()
- : value1_(1), value2_(2), value3_(3)
+ use_as_container(int value1, int value2, int value3)
+ : value1_(value1), value2_(value2), value3_(value3)
         {}
 
         int value1_;
@@ -47,19 +51,37 @@
 //]
 
 //[customize_karma_use_as_container_traits
+// All specializations of attribute customization points have to be placed into
+// the namespace boost::spirit::traits.
+//
+// Note that all templates below are specialized using the 'const' type.
+// This is necessary as all attributes in Karma are 'const'.
 namespace boost { namespace spirit { namespace traits
 {
+ // The specialization of the template 'is_container<>' will tell the
+ // library to treat the type 'client::use_as_container' as a
+ // container holding the items to generate output from.
     template <>
     struct is_container<client::use_as_container const>
       : mpl::true_
     {};
 
+ // The specialization of the template 'container_iterator<>' will be
+ // invoked by the library to evaluate the iterator type to be used
+ // for iterating the data elements in the container. We simply return
+ // the type of the iterator exposed by the embedded 'std::vector<int>'.
     template <>
     struct container_iterator<client::use_as_container const>
     {
         typedef client::use_as_container::iterator type;
     };
 
+ // The specialization of the templates 'begin_container<>' and
+ // 'end_container<>' below will be used by the library to get the iterators
+ // pointing to the begin and the end of the data to generate output from.
+ //
+ // The passed argument refers to the attribute instance passed to the list
+ // generator.
     template <>
     struct begin_container<client::use_as_container const>
     {
@@ -83,8 +105,12 @@
 //]
 
 //[customize_karma_use_as_container_iterator_traits
+// All specializations of attribute customization points have to be placed into
+// the namespace boost::spirit::traits.
 namespace boost { namespace spirit { namespace traits
 {
+ // The specialization of the template 'deref_iterator<>' will be used to
+ // dereference the iterator associated with our counter data structure.
     template <>
     struct deref_iterator<client::use_as_container::iterator>
     {
@@ -129,7 +155,7 @@
 int main()
 {
     //[customize_karma_use_as_container
- client::use_as_container d2;
+ client::use_as_container d2 (1, 2, 3);
     // use the instance of a 'client::use_as_container' instead of a STL vector
     std::cout << karma::format(karma::int_ % ", ", d2) << std::endl; // prints: '1, 2, 3'
     //]

Copied: branches/release/libs/spirit/example/karma/generate_code.cpp (from r56747, /trunk/libs/spirit/example/karma/generate_code.cpp)
==============================================================================
--- /trunk/libs/spirit/example/karma/generate_code.cpp (original)
+++ branches/release/libs/spirit/example/karma/generate_code.cpp 2009-10-17 15:33:57 EDT (Sat, 17 Oct 2009)
@@ -37,9 +37,10 @@
             using karma::_val;
             using karma::_r1;
 
- start = array_def(phoenix::size(_val)) << " = " << initializer << eol;
+ start = array_def(phoenix::size(_val)) << " = " << initializer
+ << ';' << eol;
             array_def = "int " << lit(name) << "[" << uint_(_r1) << "]";
- initializer = "{ " << -(int_ % ", ") << " };";
+ initializer = "{ " << -(int_ % ", ") << " }";
         }
 
         karma::rule<Iterator, void(unsigned)> array_def;

Modified: branches/release/libs/spirit/example/karma/reference.cpp
==============================================================================
--- branches/release/libs/spirit/example/karma/reference.cpp (original)
+++ branches/release/libs/spirit/example/karma/reference.cpp 2009-10-17 15:33:57 EDT (Sat, 17 Oct 2009)
@@ -133,7 +133,7 @@
 namespace boost { namespace spirit { namespace traits
 {
     template <>
- struct transform_attribute<int, int_data const>
+ struct transform_attribute<int_data const, int>
     {
         static int pre(int_data const& d) { return d.i; }
     };
@@ -533,7 +533,7 @@
 
         //[reference_karma_attr_cast1
         int_data d = { 1 };
- test_generator("1", karma::attr_cast<int>(karma::int_), d);
+ test_generator("1", karma::attr_cast(karma::int_), d);
         //]
     }
 


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