Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56074 - in sandbox/explore: boost/explore libs/explore/doc libs/explore/test
From: jmcintyre_at_[hidden]
Date: 2009-09-06 19:39:05


Author: jared
Date: 2009-09-06 19:39:04 EDT (Sun, 06 Sep 2009)
New Revision: 56074
URL: http://svn.boost.org/trac/boost/changeset/56074

Log:
explore - add sticky value getters, clean up manipulator naming, and don't allow char manipulators to work with wide streams and vice-versa
Removed:
   sandbox/explore/libs/explore/test/html_table_output.cpp
Text files modified:
   sandbox/explore/boost/explore/manipulators.hpp | 98 +++++++++++++++++++++++++++++++++------
   sandbox/explore/libs/explore/doc/custom_containers.qbk | 2
   sandbox/explore/libs/explore/doc/custom_delimeters.qbk | 19 +++++++
   sandbox/explore/libs/explore/test/Jamfile.v2 | 1
   sandbox/explore/libs/explore/test/columnated.cpp | 8 +-
   sandbox/explore/libs/explore/test/custom_format_simple.cpp | 25 ++++++++++
   6 files changed, 131 insertions(+), 22 deletions(-)

Modified: sandbox/explore/boost/explore/manipulators.hpp
==============================================================================
--- sandbox/explore/boost/explore/manipulators.hpp (original)
+++ sandbox/explore/boost/explore/manipulators.hpp 2009-09-06 19:39:04 EDT (Sun, 06 Sep 2009)
@@ -14,6 +14,12 @@
 #include <boost/explore/stream_value.hpp>
 #include <boost/explore/stream_state.hpp>
 #include <boost/explore/container_stream_state.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/remove_pointer.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_const.hpp>
+#include <iostream>
 
 namespace boost { namespace explore
 {
@@ -56,6 +62,21 @@
         template<typename Elem, typename Tr, typename T>
         std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const manipfunc<T>& manip)
         {
+ typedef typename boost::remove_const<
+ typename boost::remove_reference<
+ typename boost::remove_pointer<T>::type
+ >::type
+ >::type char_type;
+
+ BOOST_STATIC_ASSERT(( boost::is_same<Elem, char_type>::value ));
+
+ (*manip.pfun)(ostr, manip.arg);
+ return ostr;
+ }
+
+ template<typename Elem, typename Tr>
+ std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const manipfunc<std::size_t>& manip)
+ {
             (*manip.pfun)(ostr, manip.arg);
             return ostr;
         }
@@ -158,6 +179,12 @@
         return detail::manipfunc<const Elem*>(&detail::separatorFn, sep);
     }
     
+ template<typename Elem, typename Tr>
+ const std::basic_string<Elem>& get_separator(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return explore::get_stream_state<container_stream_state<Elem> >(ostr)->separator();
+ }
+
     // manipulator
     template<typename Elem>
     detail::manipfunc<const Elem*> start(const Elem* s)
@@ -165,6 +192,12 @@
         return detail::manipfunc<const Elem*>(&detail::startFn, s);
     }
     
+ template<typename Elem, typename Tr>
+ const std::basic_string<Elem>& get_start(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return explore::get_stream_state<container_stream_state<Elem> >(ostr)->start();
+ }
+
     // manipulator
     template<typename Elem>
     detail::manipfunc<const Elem*> end(const Elem* e)
@@ -172,6 +205,12 @@
         return detail::manipfunc<const Elem*>(&detail::endFn, e);
     }
     
+ template<typename Elem, typename Tr>
+ const std::basic_string<Elem>& get_end(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return explore::get_stream_state<container_stream_state<Elem> >(ostr)->end();
+ }
+
     // manipulator
     template<typename Elem>
     detail::manipfunc<const Elem*> assoc_item_separator(const Elem* sep)
@@ -179,6 +218,12 @@
         return detail::manipfunc<const Elem*>(&detail::assoc_item_separatorFn, sep);
     }
     
+ template<typename Elem, typename Tr>
+ const std::basic_string<Elem>& get_assoc_item_separator(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return explore::get_stream_state<container_stream_state<Elem> >(ostr)->assoc_item_separator();
+ }
+
     // manipulator
     template<typename Elem>
     detail::manipfunc<const Elem*> assoc_item_start(const Elem* start)
@@ -186,32 +231,60 @@
         return detail::manipfunc<const Elem*>(&detail::assoc_item_startFn, start);
     }
     
+ template<typename Elem, typename Tr>
+ const std::basic_string<Elem>& get_assoc_item_start(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return explore::get_stream_state<container_stream_state<Elem> >(ostr)->assoc_item_start();
+ }
+
     // manipulator
     template<typename Elem>
     detail::manipfunc<const Elem*> assoc_item_end(const Elem* end)
     {
         return detail::manipfunc<const Elem*>(&detail::assoc_item_endFn, end);
     }
-
+
+ template<typename Elem, typename Tr>
+ const std::basic_string<Elem>& get_assoc_item_end(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return explore::get_stream_state<container_stream_state<Elem> >(ostr)->assoc_item_end();
+ }
+
+ // manipulator
     detail::manipfunc<std::size_t> level(std::size_t l)
     {
         return detail::manipfunc<std::size_t>(&detail::levelFn, l);
     }
-
- detail::handle_custom_stream custom()
+
+ template<typename Elem, typename Tr>
+ std::size_t get_level(std::basic_ostream<Elem, Tr>& ostr)
     {
- return detail::handle_custom_stream();
+ return explore::get_stream_state<container_common_stream_state>(ostr)->get_level();
     }
 
- detail::manipfunc<std::size_t> setrows(std::size_t sz)
+ // manipulator
+ detail::manipfunc<std::size_t> rows(std::size_t sz)
     {
         return detail::manipfunc<std::size_t>(detail::setrowsFn, sz);
     }
-
- detail::manipfunc<std::size_t> setitemwidth(std::size_t sz)
+
+ template<typename Elem, typename Tr>
+ std::size_t get_rows(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return explore::get_stream_state<container_common_stream_state>(ostr)->get_level();
+ }
+
+ // manipulator
+ detail::manipfunc<std::size_t> item_width(std::size_t sz)
     {
         return detail::manipfunc<std::size_t>(detail::setitemwidthFn, sz);
     }
+
+ template<typename Elem, typename Tr>
+ std::size_t get_item_width(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return explore::get_stream_state<container_common_stream_state>(ostr)->get_level();
+ }
      
     // manipulator
     template<typename Elem, typename Tr>
@@ -220,15 +293,10 @@
         get_stream_state<container_stream_state<Elem> >(ostr)->template init<Elem>();
         return ostr;
     }
-
- // manipulator
- template<typename Elem, typename Tr>
- std::basic_ostream<Elem, Tr>& format_html_list(std::basic_ostream<Elem, Tr>& ostr)
+
+ detail::handle_custom_stream custom()
     {
- return ostr
- << start("<ul>\n <li>")
- << separator("\n <li>")
- << end("\n</ul>");
+ return detail::handle_custom_stream();
     }
     
     namespace detail

Modified: sandbox/explore/libs/explore/doc/custom_containers.qbk
==============================================================================
--- sandbox/explore/libs/explore/doc/custom_containers.qbk (original)
+++ sandbox/explore/libs/explore/doc/custom_containers.qbk 2009-09-06 19:39:04 EDT (Sun, 06 Sep 2009)
@@ -1,5 +1,5 @@
 [/
- / Copyright (c) 2008 Jared McIntyre
+ / Copyright (c) 2008-2009 Jared McIntyre
  /
  / Distributed under the Boost Software License, Version 1.0. (See accompanying
  / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Modified: sandbox/explore/libs/explore/doc/custom_delimeters.qbk
==============================================================================
--- sandbox/explore/libs/explore/doc/custom_delimeters.qbk (original)
+++ sandbox/explore/libs/explore/doc/custom_delimeters.qbk 2009-09-06 19:39:04 EDT (Sun, 06 Sep 2009)
@@ -1,5 +1,5 @@
 [/
- / Copyright (c) 2008 Jared McIntyre
+ / Copyright (c) 2008-2009 Jared McIntyre
  /
  / Distributed under the Boost Software License, Version 1.0. (See accompanying
  / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -9,6 +9,9 @@
 
 Explore provides the ability to change the strings used in the container streaming process through the use of several new stream manipulators.
 
+TODO: deal with wchar_t
+TODO: deal with sticky value getters (get_start)
+
 [table Explore Stream Manipulators
     [[Manipulator] [Default][Description]]
     [[start(char*)] ['\['] [Changes the string output at the beginning of a container.]]
@@ -17,6 +20,8 @@
     [[assoc_item_start(char*)] [''] [Changes the string output at the front of an association item.]]
     [[assoc_item_end(char*)] [''] [Changes the string output at the end of an association item.]]
     [[assoc_item_seperator(char*)] [':'] [Changes the string output in between elements of an association item.]]
+ [[rows] [???] [???]]
+ [[item_wdth] [???] [???]]
 ]
 
 For example, to change the beginning and end output of a container to be the greater and less than symbols, you would do the following.
@@ -65,5 +70,17 @@
    |1 2 3|
    |1 2 3|
    |1 2 3|
+
+TODO: HTML list output example:
+
+ // manipulator
+ template<typename Elem, typename Tr>
+ std::basic_ostream<Elem, Tr>& format_html_list(std::basic_ostream<Elem, Tr>& ostr)
+ {
+ return ostr
+ << start("<ul>\n <li>")
+ << separator("\n <li>")
+ << end("\n</ul>");
+ }
 
 [endsect]

Modified: sandbox/explore/libs/explore/test/Jamfile.v2
==============================================================================
--- sandbox/explore/libs/explore/test/Jamfile.v2 (original)
+++ sandbox/explore/libs/explore/test/Jamfile.v2 2009-09-06 19:39:04 EDT (Sun, 06 Sep 2009)
@@ -36,7 +36,6 @@
   [ run boost_range.cpp ]
 
   [ run custom_format_simple.cpp ]
- [ run html_table_output.cpp ]
   [ run multi_dim_test.cpp ]
 
   [ run columnated.cpp ]

Modified: sandbox/explore/libs/explore/test/columnated.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/columnated.cpp (original)
+++ sandbox/explore/libs/explore/test/columnated.cpp 2009-09-06 19:39:04 EDT (Sun, 06 Sep 2009)
@@ -23,8 +23,8 @@
     friend std::basic_ostream<C>& operator<<(std::basic_ostream<C>& ostr, const columnated_format<C>& f)
     {
         using namespace boost::explore;
- ostr << setrows(f.m_rows) << setitemwidth(f.m_width)
- << separator(str_to<C>("")) << start(str_to<C>("")) << boost::explore::end(str_to<C>(""));
+ ostr << rows(f.m_rows) << item_width(f.m_width)
+ << separator(str_to<C>("")) << start(str_to<C>("")) << boost::explore::end(str_to<C>(""));
         return ostr;
     }
 };
@@ -40,7 +40,7 @@
         vi.push_back(i);
     }
 
- str_out << setrows(3) << start(str_to<C>("")) << boost::explore::end(str_to<C>("")) << vi;
+ str_out << rows(3) << start(str_to<C>("")) << boost::explore::end(str_to<C>("")) << vi;
 
     BOOST_CHECK_EQUAL(output(str_out),
         "0, 1, 2, \n"
@@ -50,7 +50,7 @@
 
     reset(str_out);
 
- str_out << setrows(3) << setitemwidth(5) << start(str_to<C>("")) << boost::explore::end(str_to<C>("")) << vi;
+ str_out << rows(3) << item_width(5) << start(str_to<C>("")) << boost::explore::end(str_to<C>("")) << vi;
 
     BOOST_CHECK_EQUAL(output(str_out),
         " 0, 1, 2, \n"

Modified: sandbox/explore/libs/explore/test/custom_format_simple.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/custom_format_simple.cpp (original)
+++ sandbox/explore/libs/explore/test/custom_format_simple.cpp 2009-09-06 19:39:04 EDT (Sun, 06 Sep 2009)
@@ -94,6 +94,31 @@
     BOOST_CHECK_EQUAL(output(str_out), "<=\\1**first//#\\2**second//=>");
 }
 
+BOOST_AUTO_TEST_CASE_TEMPLATE( get_sticky_values_test, C, test_types )
+{
+ using namespace boost::explore;
+ typename test_traits<C>::stream_type str_out;
+
+ BOOST_CHECK_EQUAL( get_start(str_out).c_str(), str_to<C>("[") );
+ BOOST_CHECK_EQUAL( get_separator(str_out).c_str(), str_to<C>(", ") );
+ BOOST_CHECK_EQUAL( get_end(str_out).c_str(), str_to<C>("]") );
+
+ BOOST_CHECK_EQUAL( get_assoc_item_start(str_out).c_str(), str_to<C>("") );
+ BOOST_CHECK_EQUAL( get_assoc_item_separator(str_out).c_str(), str_to<C>(":") );
+ BOOST_CHECK_EQUAL( get_assoc_item_end(str_out).c_str(), str_to<C>("") );
+
+ str_out << basic_stream_format;
+
+
+ BOOST_CHECK_EQUAL( get_start(str_out).c_str(), str_to<C>("<=") );
+ BOOST_CHECK_EQUAL( get_separator(str_out).c_str(), str_to<C>("#") );
+ BOOST_CHECK_EQUAL( get_end(str_out).c_str(), str_to<C>("=>") );
+
+ BOOST_CHECK_EQUAL( get_assoc_item_start(str_out).c_str(), str_to<C>("\\") );
+ BOOST_CHECK_EQUAL( get_assoc_item_separator(str_out).c_str(), str_to<C>("**") );
+ BOOST_CHECK_EQUAL( get_assoc_item_end(str_out).c_str(), str_to<C>("//") );
+}
+
 BOOST_AUTO_TEST_CASE_TEMPLATE( begin_end_helper_test, C, test_types )
 {
     typename test_traits<C>::stream_type str_out;

Deleted: sandbox/explore/libs/explore/test/html_table_output.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/html_table_output.cpp 2009-09-06 19:39:04 EDT (Sun, 06 Sep 2009)
+++ (empty file)
@@ -1,79 +0,0 @@
-// Boost.Explore library
-
-// Copyright Danny Havenith 2007. Use, modification and
-// distribution is subject to the Boost Software License, Version
-// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-// For more information, see http://www.boost.org
-
-#define BOOST_TEST_MODULE PrintLib
-#include <boost/test/unit_test.hpp>
-#include <boost/explore/manipulators.hpp>
-#include <vector>
-#include <boost/explore.hpp>
-#include "boost_explore_test_tools.hpp"
-
-std::ostream& html_table_stream_format(std::ostream& ostr)
-{
- using namespace boost::explore;
- ostr << level(0);
- ostr << start("<table>\n")
- << separator("")
- << boost::explore::end("</table>\n");
-
- ostr << level(1);
- ostr << start("<tr><td>")
- << separator("</td><td>")
- << boost::explore::end("</td></tr>\n");
-
- return ostr;
-}
-
-std::wostream& html_table_stream_format(std::wostream& ostr)
-{
- using namespace boost::explore;
- ostr << level(0);
- ostr << start(L"<table>\n")
- << separator(L"")
- << boost::explore::end(L"</table>\n");
-
- ostr << level(1);
- ostr << start(L"<tr><td>")
- << separator(L"</td><td>")
- << boost::explore::end(L"</td></tr>\n");
-
- return ostr;
-}
-
-BOOST_AUTO_TEST_CASE_TEMPLATE( vector_in_c_array_html_stream_test, C, test_types )
-{
- using namespace boost::explore;
- typename test_traits<C>::stream_type str_out;
- str_out << html_table_stream_format;
-
- std::vector<int> vi;
- vi.push_back(1);
- vi.push_back(2);
- vi.push_back(3);
-
- std::vector<int> arrvi1[] = {vi};
- str_out << arrvi1;
-
- BOOST_CHECK_EQUAL(output(str_out),
- "<table>\n"
- "<tr><td>1</td><td>2</td><td>3</td></tr>\n"
- "</table>\n");
-
- reset(str_out);
-
- std::vector<int> arrvi3[] = {vi,vi,vi};
- str_out << arrvi3;
- BOOST_CHECK_EQUAL(output(str_out),
- "<table>\n"
- "<tr><td>1</td><td>2</td><td>3</td></tr>\n"
- "<tr><td>1</td><td>2</td><td>3</td></tr>\n"
- "<tr><td>1</td><td>2</td><td>3</td></tr>\n"
- "</table>\n");
-}
-


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