Boost logo

Boost-Commit :

From: jefffaust_at_[hidden]
Date: 2007-06-04 00:20:19


Author: jefffaust
Date: 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
New Revision: 4432
URL: http://svn.boost.org/trac/boost/changeset/4432

Log:
Break up stream_container.hpp into different headers.

Added:
   sandbox/explore/boost/explore/container_stream_state.hpp
   sandbox/explore/boost/explore/iterator_range.hpp
   sandbox/explore/boost/explore/stream_value.hpp
Text files modified:
   sandbox/explore/boost/explore.hpp | 1
   sandbox/explore/boost/explore/stream_container.hpp | 169 ---------------------------------------
   sandbox/explore/libs/explore/test/boost_array.cpp | 1
   sandbox/explore/libs/explore/test/boost_range.cpp | 1
   sandbox/explore/libs/explore/test/custom_format_simple.cpp | 1
   sandbox/explore/libs/explore/test/std_deque.cpp | 1
   sandbox/explore/libs/explore/test/std_list.cpp | 1
   sandbox/explore/libs/explore/test/std_map.cpp | 1
   sandbox/explore/libs/explore/test/std_pair.cpp | 1
   sandbox/explore/libs/explore/test/std_set.cpp | 1
   sandbox/explore/libs/explore/test/std_vector.cpp | 1
   11 files changed, 12 insertions(+), 167 deletions(-)

Modified: sandbox/explore/boost/explore.hpp
==============================================================================
--- sandbox/explore/boost/explore.hpp (original)
+++ sandbox/explore/boost/explore.hpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -10,3 +10,4 @@
 
 #include <explore/explore.hpp>
 #include <explore/stream_container.hpp>
+#include <explore/iterator_range.hpp>

Added: sandbox/explore/boost/explore/container_stream_state.hpp
==============================================================================
--- (empty file)
+++ sandbox/explore/boost/explore/container_stream_state.hpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -0,0 +1,125 @@
+//
+// container_stream_state.hpp - stream state for containers
+//
+// Copyright (C) 2007, Jeffrey Faust
+//
+// 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)
+//
+
+#ifndef BOOST_EXPLORE_CONTAINER_STREAM_STATE_H
+#define BOOST_EXPLORE_CONTAINER_STREAM_STATE_H
+
+#include <string>
+#include <vector>
+
+// generate string init functions for both char and wchar_t types
+#define BOOST_EXPLORE_INIT_STRING(name, str) \
+template<typename charType> std::basic_string<charType> init_##name(); \
+template<> std::basic_string<char> init_##name<char>() { return (str); } \
+template<> std::basic_string<wchar_t> init_##name<wchar_t>() { return L##str; }
+
+namespace explore
+{
+ namespace detail
+ {
+ BOOST_EXPLORE_INIT_STRING(separator, ", ")
+ BOOST_EXPLORE_INIT_STRING(start, "[")
+ BOOST_EXPLORE_INIT_STRING(end, "]")
+ BOOST_EXPLORE_INIT_STRING(assoc_separator, ":")
+ BOOST_EXPLORE_INIT_STRING(assoc_start, "")
+ BOOST_EXPLORE_INIT_STRING(assoc_end, "")
+
+ template<typename Elem>
+ struct depth_guard;
+ }
+
+ // A simple collection of additional stream state
+ template<typename Elem>
+ struct container_stream_state
+ {
+ typedef std::basic_string<Elem> str_typ;
+ typedef std::vector<str_typ, std::allocator<str_typ> > cont_typ;
+
+ container_stream_state()
+ : m_depth(0), m_itemw(0)
+ {
+ init<Elem>();
+ }
+
+ // Concern: this is only specialized for char and wchar_t streams.
+ template<typename El>
+ void init()
+ {
+ init(m_separator, detail::init_separator<El>());
+ init(m_start, detail::init_start<El>());
+ init(m_end, detail::init_end<El>());
+ init(m_assoc_separator, detail::init_assoc_separator<El>());
+ init(m_assoc_start, detail::init_assoc_start<El>());
+ init(m_assoc_end, detail::init_assoc_end<El>());
+ }
+
+ // read
+ const str_typ& separator(std::size_t index = 0) const { return at(m_separator, index); }
+ const str_typ& start(std::size_t index = 0) const { return at(m_start, index); }
+ const str_typ& end(std::size_t index = 0) const { return at(m_end, index); }
+ const str_typ& assoc_separator(std::size_t index = 0) const { return at(m_assoc_separator, index); }
+ 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::streamsize itemw() const { return m_itemw; }
+
+ // write
+ void set_separator(const str_typ& str, std::size_t index = 0) { at(m_separator, index) = str; }
+ void set_start(const str_typ& str, std::size_t index = 0) { at(m_start, index) = str; }
+ void set_end(const str_typ& str, std::size_t index = 0) { at(m_end, index) = str; }
+ void set_assoc_separator(const str_typ& str, std::size_t index = 0) { at(m_assoc_separator, index) = str; }
+ 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_itemw(std::streamsize itemw, std::size_t index = 0) { m_itemw = itemw; }
+
+ std::size_t depth() const
+ {
+ // we start at 0, increment before use, so we must decrement upon query.
+ return m_depth - 1;
+ }
+
+ private:
+ friend struct detail::depth_guard<Elem>;
+
+ cont_typ m_separator;
+ cont_typ m_start;
+ cont_typ m_end;
+ cont_typ m_assoc_separator;
+ cont_typ m_assoc_start;
+ cont_typ m_assoc_end;
+ std::size_t m_depth;
+
+ std::streamsize m_itemw;
+
+ void init(cont_typ& c, str_typ val)
+ {
+ c.resize(1);
+ c[0] = val;
+ }
+
+ // read
+ const str_typ& at(const cont_typ& c, std::size_t index) const
+ {
+ // return the highest item if it does not exist at the given index
+ return c[std::min(index, c.size() - 1)];
+ }
+
+ // write
+ str_typ& at(cont_typ& c, std::size_t index)
+ {
+ if( c.size() <= index )
+ {
+ c.resize(index+1);
+ }
+
+ return c[index];
+ }
+ };
+}
+
+#endif

Added: sandbox/explore/boost/explore/iterator_range.hpp
==============================================================================
--- (empty file)
+++ sandbox/explore/boost/explore/iterator_range.hpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -0,0 +1,60 @@
+//
+// iterator_range.hpp - container-like streaming for iterator_range
+//
+// Copyright (C) 2007, Jeffrey Faust
+//
+// 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)
+//
+
+#ifndef BOOST_EXPLORE_ITERATOR_RANGE_H
+#define BOOST_EXPLORE_ITERATOR_RANGE_H
+
+#include "is_assoc_iter.hpp"
+#include "stream_value.hpp"
+
+#include <boost/range/iterator_range.hpp>
+#include <boost/mpl/if.hpp>
+
+namespace explore
+{
+ // To work around some problems with overriding for operator<< for boost::iterator_range
+ // there already exists such an operator that does not do what we want.
+ template<typename T>
+ struct iterator_range_wrapper
+ {
+ iterator_range_wrapper(const boost::iterator_range<T>& ir) : t(ir) {}
+ boost::iterator_range<T> t;
+ typedef typename boost::mpl::if_<typename is_assoc_iter<T>::type, stream_map_value, stream_normal_value>::type stream_type;
+ };
+
+ template<typename T>
+ iterator_range_wrapper<T> as_container(const boost::iterator_range<T>& ir)
+ {
+ return iterator_range_wrapper<T>(ir);
+ }
+
+ template< typename IteratorT >
+ inline iterator_range_wrapper<IteratorT>
+ make_iterator_range(IteratorT Begin, IteratorT End)
+ {
+ return iterator_range_wrapper<IteratorT>(boost::make_iterator_range(Begin, End));
+ }
+
+ template< class ForwardRange >
+ iterator_range_wrapper<BOOST_DEDUCED_TYPENAME boost::range_const_iterator<ForwardRange>::type>
+ make_iterator_range(const ForwardRange& r)
+ {
+ return as_container(boost::make_iterator_range(r));
+ }
+
+ // stream boost::iterator_range
+ template<typename Elem, typename Tr, typename T>
+ std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr,
+ const iterator_range_wrapper<T>& r)
+ {
+ return stream_container(ostr, r.t.begin(), r.t.end(), typename iterator_range_wrapper<T>::stream_type());
+ }
+}
+
+#endif

Modified: sandbox/explore/boost/explore/stream_container.hpp
==============================================================================
--- sandbox/explore/boost/explore/stream_container.hpp (original)
+++ sandbox/explore/boost/explore/stream_container.hpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -11,125 +11,17 @@
 #define STREAM_CONTAINER_INCLUDED
 
 #include "stream_state.hpp"
-#include "is_assoc_iter.hpp"
+#include "stream_value.hpp"
+#include "container_stream_state.hpp"
 
 #include <ostream>
-#include <vector>
 #include <boost/functional/detail/container_fwd.hpp>
 #include <boost/array.hpp>
-#include <boost/range/iterator_range.hpp>
-
-// generate string init functions for both char and wchar_t types
-#define BOOST_EXPLORE_INIT_STRING(name, str) \
-template<typename charType> std::basic_string<charType> init_##name(); \
-template<> std::basic_string<char> init_##name<char>() { return (str); } \
-template<> std::basic_string<wchar_t> init_##name<wchar_t>() { return L##str; }
 
 namespace explore
 {
     namespace detail
     {
- BOOST_EXPLORE_INIT_STRING(separator, ", ")
- BOOST_EXPLORE_INIT_STRING(start, "[")
- BOOST_EXPLORE_INIT_STRING(end, "]")
- BOOST_EXPLORE_INIT_STRING(assoc_separator, ":")
- BOOST_EXPLORE_INIT_STRING(assoc_start, "")
- BOOST_EXPLORE_INIT_STRING(assoc_end, "")
-
- template<typename Elem>
- struct depth_guard;
- }
-
-
- // A simple collection of additional stream state
- template<typename Elem>
- struct container_stream_state
- {
- typedef std::basic_string<Elem> str_typ;
- typedef std::vector<str_typ, std::allocator<str_typ> > cont_typ;
-
- container_stream_state()
- : m_depth(0), m_itemw(0)
- {
- init<Elem>();
- }
-
- // Concern: this is only specialized for char and wchar_t streams.
- template<typename El>
- void init()
- {
- init(m_separator, detail::init_separator<El>());
- init(m_start, detail::init_start<El>());
- init(m_end, detail::init_end<El>());
- init(m_assoc_separator, detail::init_assoc_separator<El>());
- init(m_assoc_start, detail::init_assoc_start<El>());
- init(m_assoc_end, detail::init_assoc_end<El>());
- }
-
- // read
- const str_typ& separator(std::size_t index = 0) const { return at(m_separator, index); }
- const str_typ& start(std::size_t index = 0) const { return at(m_start, index); }
- const str_typ& end(std::size_t index = 0) const { return at(m_end, index); }
- const str_typ& assoc_separator(std::size_t index = 0) const { return at(m_assoc_separator, index); }
- 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::streamsize itemw() const { return m_itemw; }
-
- // write
- void set_separator(const str_typ& str, std::size_t index = 0) { at(m_separator, index) = str; }
- void set_start(const str_typ& str, std::size_t index = 0) { at(m_start, index) = str; }
- void set_end(const str_typ& str, std::size_t index = 0) { at(m_end, index) = str; }
- void set_assoc_separator(const str_typ& str, std::size_t index = 0) { at(m_assoc_separator, index) = str; }
- 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_itemw(std::streamsize itemw, std::size_t index = 0) { m_itemw = itemw; }
-
- std::size_t depth() const
- {
- // we start at 0, increment before use, so we must decrement upon query.
- return m_depth - 1;
- }
-
- private:
- friend struct detail::depth_guard<Elem>;
-
- cont_typ m_separator;
- cont_typ m_start;
- cont_typ m_end;
- cont_typ m_assoc_separator;
- cont_typ m_assoc_start;
- cont_typ m_assoc_end;
- std::size_t m_depth;
-
- std::streamsize m_itemw;
-
- void init(cont_typ& c, str_typ val)
- {
- c.resize(1);
- c[0] = val;
- }
-
- // read
- const str_typ& at(const cont_typ& c, std::size_t index) const
- {
- // return the highest item if it does not exist at the given index
- return c[std::min(index, c.size() - 1)];
- }
-
- // write
- str_typ& at(cont_typ& c, std::size_t index)
- {
- if( c.size() <= index )
- {
- c.resize(index+1);
- }
-
- return c[index];
- }
- };
-
- namespace detail
- {
         template<typename Elem>
         struct depth_guard
         {
@@ -221,25 +113,6 @@
         }
     }
 
- 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>*)
- {
- ostr << val;
- }
- };
-
- // stream value from associative container
- struct stream_map_value
- {
- template<typename Elem, typename Tr, typename T>
- void operator()(std::basic_ostream<Elem, Tr>& ostr, const T& val, container_stream_state<Elem>* state)
- {
- ostr << state->assoc_start() << val.first << state->assoc_separator() << val.second << state->assoc_end();
- }
- };
-
     template<typename Elem, typename Tr, typename FwdIter, typename F>
     std::basic_ostream<Elem, Tr>& stream_container(std::basic_ostream<Elem, Tr>& ostr, FwdIter first, FwdIter last, F f)
     {
@@ -272,36 +145,6 @@
         // redirect with "normal" streaming.
         return stream_container(ostr, first, last, stream_normal_value());
     }
-
- // used to work around some problems with overriding for operator<< for boost::iterator_range
- // there already exists such an operator that does not do what we want.
- template<typename T>
- struct iterator_range_wrapper
- {
- iterator_range_wrapper(const boost::iterator_range<T>& ir) : t(ir) {}
- boost::iterator_range<T> t;
- typedef typename boost::mpl::if_<typename is_assoc_iter<T>::type, stream_map_value, stream_normal_value>::type stream_type;
- };
-
- template<typename T>
- iterator_range_wrapper<T> as_container(const boost::iterator_range<T>& ir)
- {
- return iterator_range_wrapper<T>(ir);
- }
-
- template< typename IteratorT >
- inline iterator_range_wrapper<IteratorT>
- make_iterator_range(IteratorT Begin, IteratorT End)
- {
- return iterator_range_wrapper<IteratorT>(boost::make_iterator_range(Begin, End));
- }
-
- template< class ForwardRange >
- iterator_range_wrapper<BOOST_DEDUCED_TYPENAME boost::range_const_iterator<ForwardRange>::type>
- make_iterator_range(const ForwardRange& r)
- {
- return as_container(boost::make_iterator_range(r));
- }
 }
 
 namespace std
@@ -385,14 +228,6 @@
     }
 # endif
 
- // stream boost::iterator_range
- template<typename Elem, typename Tr, typename T>
- std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr,
- const iterator_range_wrapper<T>& r)
- {
- return stream_container(ostr, r.t.begin(), r.t.end(), typename iterator_range_wrapper<T>::stream_type());
- }
-
     // manipulator
     template<typename Elem>
     detail::manipfunc<const Elem*> separator(const Elem* sep, std::size_t depth = 0)

Added: sandbox/explore/boost/explore/stream_value.hpp
==============================================================================
--- (empty file)
+++ sandbox/explore/boost/explore/stream_value.hpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -0,0 +1,39 @@
+//
+// stream_value.hpp - streaming function objects for different value types
+//
+// Copyright (C) 2007, Jeffrey Faust
+//
+// 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)
+//
+
+#ifndef BOOST_EXPLORE_STREAM_VALUE_H
+#define BOOST_EXPLORE_STREAM_VALUE_H
+
+#include "container_stream_state.hpp"
+
+#include <ostream>
+
+namespace explore
+{
+ 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>*)
+ {
+ ostr << val;
+ }
+ };
+
+ // stream value from associative container
+ struct stream_map_value
+ {
+ template<typename Elem, typename Tr, typename T>
+ void operator()(std::basic_ostream<Elem, Tr>& ostr, const T& val, container_stream_state<Elem>* state)
+ {
+ ostr << state->assoc_start() << val.first << state->assoc_separator() << val.second << state->assoc_end();
+ }
+ };
+}
+
+#endif

Modified: sandbox/explore/libs/explore/test/boost_array.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/boost_array.cpp (original)
+++ sandbox/explore/libs/explore/test/boost_array.cpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -14,6 +14,7 @@
 #include <boost/array.hpp>
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 
 BOOST_AUTO_TEST_CASE( basic_array_print_test )
 {

Modified: sandbox/explore/libs/explore/test/boost_range.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/boost_range.cpp (original)
+++ sandbox/explore/libs/explore/test/boost_range.cpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -14,6 +14,7 @@
 #include <boost/range/iterator_range.hpp>
 #include "../../../boost/explore/stream_container.hpp"
 #include "../../../boost/explore/explore.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 
 BOOST_AUTO_TEST_CASE( boost_range_print_test )
 {

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 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -15,6 +15,7 @@
 #include <vector>
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 #include "basic_lg_format.hpp"
 
 BOOST_AUTO_TEST_CASE( basic_vector_custom_format_print_test )

Modified: sandbox/explore/libs/explore/test/std_deque.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/std_deque.cpp (original)
+++ sandbox/explore/libs/explore/test/std_deque.cpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -14,6 +14,7 @@
 #include <deque>
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 
 BOOST_AUTO_TEST_CASE( basic_deque_print_test )
 {

Modified: sandbox/explore/libs/explore/test/std_list.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/std_list.cpp (original)
+++ sandbox/explore/libs/explore/test/std_list.cpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -15,6 +15,7 @@
 #include <complex>
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 
 BOOST_AUTO_TEST_CASE( basic_list_print_test )
 {

Modified: sandbox/explore/libs/explore/test/std_map.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/std_map.cpp (original)
+++ sandbox/explore/libs/explore/test/std_map.cpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -15,6 +15,7 @@
 #include <map>
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 
 BOOST_AUTO_TEST_CASE( basic_map_print_test )
 {

Modified: sandbox/explore/libs/explore/test/std_pair.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/std_pair.cpp (original)
+++ sandbox/explore/libs/explore/test/std_pair.cpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -13,6 +13,7 @@
 #include <vector>
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 
 BOOST_AUTO_TEST_CASE( basic_pair_print_test )
 {

Modified: sandbox/explore/libs/explore/test/std_set.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/std_set.cpp (original)
+++ sandbox/explore/libs/explore/test/std_set.cpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -14,6 +14,7 @@
 #include <set>
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 
 BOOST_AUTO_TEST_CASE( basic_set_print_test )
 {

Modified: sandbox/explore/libs/explore/test/std_vector.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/std_vector.cpp (original)
+++ sandbox/explore/libs/explore/test/std_vector.cpp 2007-06-04 00:20:18 EDT (Mon, 04 Jun 2007)
@@ -15,6 +15,7 @@
 #include <vector>
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
+#include "../../../boost/explore/iterator_range.hpp"
 
 BOOST_AUTO_TEST_CASE( vector_custom_format_print_test )
 {


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