Boost logo

Boost-Commit :

From: jeff_at_[hidden]
Date: 2007-08-02 00:13:59


Author: jefffaust
Date: 2007-08-02 00:13:58 EDT (Thu, 02 Aug 2007)
New Revision: 38392
URL: http://svn.boost.org/trac/boost/changeset/38392

Log:
add true columnation and test
Text files modified:
   sandbox/explore/boost/explore/container_stream_state.hpp | 5 +++
   sandbox/explore/boost/explore/stream_container.hpp | 12 ++++++++++
   sandbox/explore/boost/explore/stream_value.hpp | 3 +
   sandbox/explore/libs/explore/test/columnated.cpp | 46 +++++++++++++++++++++++++++++++++++----
   4 files changed, 59 insertions(+), 7 deletions(-)

Modified: sandbox/explore/boost/explore/container_stream_state.hpp
==============================================================================
--- sandbox/explore/boost/explore/container_stream_state.hpp (original)
+++ sandbox/explore/boost/explore/container_stream_state.hpp 2007-08-02 00:13:58 EDT (Thu, 02 Aug 2007)
@@ -42,7 +42,7 @@
         typedef std::vector<str_typ, std::allocator<str_typ> > cont_typ;
 
         container_stream_state()
- : m_depth(0), m_rows(0)
+ : m_depth(0), m_rows(0), m_itemwidth(0)
         {
             init<Elem>();
         }
@@ -67,6 +67,7 @@
         const str_typ& assoc_start(std::size_t index = 0) const { return at(m_assoc_start, index); }
         const str_typ& assoc_end(std::size_t index = 0) const { return at(m_assoc_end, index); }
         std::size_t rows() const { return m_rows; }
+ std::size_t itemwidth() const { return m_itemwidth; }
 
         // write
         void set_separator(const str_typ& str, std::size_t index = 0) { at(m_separator, index) = str; }
@@ -76,6 +77,7 @@
         void set_assoc_start(const str_typ& str, std::size_t index = 0) { at(m_assoc_start, index) = str; }
         void set_assoc_end(const str_typ& str, std::size_t index = 0) { at(m_assoc_end, index) = str; }
         void set_rows(std::size_t rows, std::size_t index = 0) { m_rows = rows; }
+ void set_itemwidth(std::size_t iw, std::size_t index = 0) { m_itemwidth = iw; }
 
         std::size_t depth() const
         {
@@ -95,6 +97,7 @@
         std::size_t m_depth;
 
         std::size_t m_rows;
+ std::size_t m_itemwidth;
 
         template<typename T>
         void init(cont_typ& c, const T& val)

Modified: sandbox/explore/boost/explore/stream_container.hpp
==============================================================================
--- sandbox/explore/boost/explore/stream_container.hpp (original)
+++ sandbox/explore/boost/explore/stream_container.hpp 2007-08-02 00:13:58 EDT (Thu, 02 Aug 2007)
@@ -111,6 +111,13 @@
         {
             explore::get_stream_state<container_stream_state<char> >(ostr)->set_rows(sz, depth);
         }
+
+ // function ptr object for setrows
+ //template<typename Elem>
+ void setitemwidthFn(std::ios_base& ostr, std::size_t sz, std::size_t depth)
+ {
+ explore::get_stream_state<container_stream_state<char> >(ostr)->set_itemwidth(sz, depth);
+ }
     }
 
     template<typename Elem, typename Tr, typename FwdIter, typename F>
@@ -285,6 +292,11 @@
         return detail::manipfunc<std::size_t>(detail::setrowsFn, sz, depth);
     }
 
+ detail::manipfunc<std::size_t> setitemwidth(std::size_t sz, std::size_t depth = 0)
+ {
+ return detail::manipfunc<std::size_t>(detail::setitemwidthFn, sz, depth);
+ }
+
     // manipulator
     template<typename Elem, typename Tr>
     std::basic_ostream<Elem, Tr>& format_normal(std::basic_ostream<Elem, Tr>& ostr)

Modified: sandbox/explore/boost/explore/stream_value.hpp
==============================================================================
--- sandbox/explore/boost/explore/stream_value.hpp (original)
+++ sandbox/explore/boost/explore/stream_value.hpp 2007-08-02 00:13:58 EDT (Thu, 02 Aug 2007)
@@ -19,8 +19,9 @@
     struct stream_normal_value
     {
         template<typename Elem, typename Tr, typename T>
- void operator()(std::basic_ostream<Elem, Tr>& ostr, const T& val, container_stream_state<Elem>*)
+ void operator()(std::basic_ostream<Elem, Tr>& ostr, const T& val, container_stream_state<Elem>* state)
         {
+ ostr.width(state->itemwidth());
             ostr << val;
         }
     };

Modified: sandbox/explore/libs/explore/test/columnated.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/columnated.cpp (original)
+++ sandbox/explore/libs/explore/test/columnated.cpp 2007-08-02 00:13:58 EDT (Thu, 02 Aug 2007)
@@ -14,18 +14,33 @@
 #include <vector>
 #include "../../../boost/explore.hpp"
 
-BOOST_AUTO_TEST_CASE( basic_array_print_test )
+BOOST_AUTO_TEST_CASE( basic_columnate_print_test )
 {
- BOOST_FAIL("Test not implemented");
+ //BOOST_FAIL("Test not implemented");
 }
 
-BOOST_AUTO_TEST_CASE( basic_array_stream_test )
+struct columnated_format
+{
+ columnated_format(std::size_t rows, std::size_t width) : m_rows(rows), m_width(width) {}
+ std::size_t m_rows;
+ std::size_t m_width;
+
+ friend std::ostream& operator<<(std::ostream& ostr, const columnated_format& f)
+ {
+ using namespace explore;
+ ostr << setrows(f.m_rows) << setitemwidth(f.m_width)
+ << separator("") << start("") << explore::end("");
+ return ostr;
+ }
+};
+
+BOOST_AUTO_TEST_CASE( basic_columnate_stream_test )
 {
     using namespace explore;
     std::stringstream str_out;
     std::vector<int> vi;
 
- for( int i = 0; i < 9; ++i )
+ for( int i = 0; i < 12; ++i )
     {
         vi.push_back(i);
     }
@@ -35,5 +50,26 @@
     BOOST_CHECK_EQUAL(str_out.str(),
         "0, 1, 2, \n"
         "3, 4, 5, \n"
- "6, 7, 8");
+ "6, 7, 8, \n"
+ "9, 10, 11");
+
+ str_out.str("");
+
+ str_out << setrows(3) << setitemwidth(5) << start("") << explore::end("") << vi;
+
+ BOOST_CHECK_EQUAL(str_out.str(),
+ " 0, 1, 2, \n"
+ " 3, 4, 5, \n"
+ " 6, 7, 8, \n"
+ " 9, 10, 11");
+
+ str_out.str("");
+
+ str_out << columnated_format(3, 5) << vi;
+
+ BOOST_CHECK_EQUAL(str_out.str(),
+ " 0 1 2\n"
+ " 3 4 5\n"
+ " 6 7 8\n"
+ " 9 10 11");
 }


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