Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75157 - sandbox/variadic_templates/sandbox/stepper/boost/array_stepper
From: cppljevans_at_[hidden]
Date: 2011-10-28 13:07:05


Author: cppljevans
Date: 2011-10-28 13:07:03 EDT (Fri, 28 Oct 2011)
New Revision: 75157
URL: http://svn.boost.org/trac/boost/changeset/75157

Log:
Rm'ed array_host.hpp #include's and
refactored code to avoid code duplication
using lambda's, open_delims and close_delims.

Text files modified:
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_store_print.hpp | 142 ++++++++++-----------------------------
   1 files changed, 36 insertions(+), 106 deletions(-)

Modified: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_store_print.hpp
==============================================================================
--- sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_store_print.hpp (original)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/array_store_print.hpp 2011-10-28 13:07:03 EDT (Fri, 28 Oct 2011)
@@ -2,10 +2,6 @@
 #define BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_HPP_INCLUDED
 
 #include <boost/array_stepper/array_store.hpp>
-#if 0
-#include <boost/array_stepper/array_host.hpp>
-#include <boost/iostreams/utility/indent_scoped_ostreambuf.hpp>
-#else
 #include <boost/array_stepper/index_stack_length_stride_crtp.hpp>
 #include <iostream>
 #include <iomanip>
@@ -13,91 +9,16 @@
 #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
 #include <boost/assert.hpp>
 #endif
-#endif
-
-#ifndef BOOST_ARRAY_STEPPER_INDEX_STACK_LENGTH_STRIDE_CRTP_HPP_INCLUDED
-namespace boost
-{
-namespace array_stepper
-{
- template
- < typename T
- >
- struct
-array_store_print
-{
- std::ostream&
- my_sout
- ;
- typedef typename
- array_store<T>::index_t
- index_t
- ;
- array_store_print
- ( std::ostream& a_sout
- )
- : my_sout(a_sout)
- {}
-
- void null_array( )const
- {
- my_sout<<"(null_array)";
- }
-
- void pre_children()
- {
- my_sout<<"{ ";
- }
-
- void pre_child( index_t index)
- {
- if(0<index) my_sout<<", ";
- my_sout<<indent_buf_in;
- }
-
- void visit_child( T const& a_t)
- {
- #if 0
- ::operator<<( my_sout, a_t);
- //MAINTENANCE_NOTE:2011-06-29 with gcc4.6:
- // For some strange reason, have to use above with
- // gcc instead of what's in #else part because
- // otherwise compiler gives error saying:
- // no match for 'operator<<'
- // when T is std::vector<unsigned> even though
- // there is a:
- // std::ostream&
- // operator<<
- // ( std::ostream&
- // , std::vector<unsigned>const&
- // );
- // defined.
- #else
- my_sout<<a_t;
- #endif
- }
-
- void post_child( )
- {
- my_sout<<indent_buf_out;
- }
-
- void post_children()
- {
- my_sout<<"}\n";
- }
-
-};
-
-}//exit array_stepper namespace
-}//exit boost namespace
-#endif
 
   template
   < typename T
>
   struct
 array_iter_wrap
+ /**@brief
+ * Simple wrapper to allow printing of array_store<T>
+ * "configured" with index_stack_length_stride_crtp_indices.
+ */
 {
     typedef typename boost::array_stepper::array_store<T> arr_t;
     typedef typename arr_t::data_t::const_iterator iter_t;
@@ -118,6 +39,7 @@
       lsos_t const
     my_lsos;
 };
+
   template
   < typename T
>
@@ -131,8 +53,12 @@
     typedef typename arr_iter_t::lsos_t lsos_t;
     typedef typename arr_iter_t::iter_t iter_t;
     typedef typename lsos_t::axis_depth_t axis_depth_t;
+ char const open_delim='{';
+ char const between_delim=',';
+ char const close_delim='}';
     unsigned const margin=2;
- auto depth_indent=[]( axis_depth_t ad)->int
+ auto fmtflags0=sout.flags(std::ios_base::left);
+ auto between_close_width=[]( axis_depth_t ad)->int
       {
           return (ad-1)*margin;
       };
@@ -144,10 +70,25 @@
     axis_depth_t const axis_max=axis_now;
   #endif
     axis_depth_t axis_pre=lsos_t::axis_end;
- for(axis_depth_t l=axis_pre; l<axis_now; ++l)
- { //open 1st element for all axes.
- sout<<"{ ";
- }
+
+ auto open_delims=[ &]( axis_depth_t ax_beg, axis_depth_t ax_end)
+ {
+ for(axis_depth_t l=ax_beg; l<ax_end; ++l)
+ { //open 1st element for axes ax_beg...ax_end-1.
+ sout<<std::setw(margin)<<open_delim;
+ }
+ };
+ auto close_delims=[ &]( )
+ {
+ for(axis_depth_t l=axis_pre; axis_now<l; --l)
+ {//close axis_pre to axis_now elements.
+ if(l!=axis_pre)
+ sout<<std::setw(between_close_width(l))<<"";
+ sout<<close_delim<<"\n";
+ }
+ };
+
+ open_delims( axis_pre, axis_now);
     for
       ( int i=0
       ; i<n
@@ -158,24 +99,17 @@
     {
         if(axis_now<axis_pre)
         { //exiting one element and starting next.
- for(axis_depth_t l=axis_pre; axis_now<l; --l)
- { //close axis_pre to axis_now elements.
- if(l!=axis_pre)
- sout<<std::setw(l*margin)<<"";
- sout<<"}\n";
- }
- sout<<std::setw(depth_indent(axis_now))<<""<<", ";//put delimiter between elements
- for(axis_depth_t l=axis_pre; axis_now<l; --l)
- { //open axis_now to axis_pre elements.
- sout<<"{ ";
- }
+ close_delims();
+ sout<<std::setw(between_close_width(axis_now))<<""
+ <<std::setw(margin)<<between_delim;//put delimiter between elements
+ open_delims( axis_now, axis_pre);
           #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
             sout<<"(:axis_now="<<axis_now<<"<"<<"axis_pre="<<axis_pre<<")";
             BOOST_ASSERT(axis_pre == axis_max);
           #endif
         }
         else if(lsos_t::axis_end<axis_pre)
- { sout<<", ";//put delimiter between elements
+ { sout<<std::setw(margin)<<between_delim;//put delimiter between elements
           #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
             sout<<"(axis_end<axis_pre)";
             auto ibs=lsos_v[axis_now-1];
@@ -200,12 +134,7 @@
       #endif
         sout<<data_v[offset];
     }
- for(axis_depth_t l=axis_pre; axis_now<l; --l)
- {//close axis_pre to axis_now elements.
- if(l!=axis_pre)
- sout<<std::setw(depth_indent(l))<<"";
- sout<<"}\n";
- }
+ close_delims();
     #ifdef BOOST_ARRAY_STEPPER_ARRAY_STORE_PRINT_TRACE
     sout
       <<":axis_pre="<<axis_pre
@@ -213,6 +142,7 @@
       <<"\n"
       ;
     #endif
+ sout.flags(fmtflags0);
     return sout;
 }
   template


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