|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55796 - in sandbox/explore: boost/explore libs/explore/test
From: jeff_at_[hidden]
Date: 2009-08-26 23:05:55
Author: jefffaust
Date: 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
New Revision: 55796
URL: http://svn.boost.org/trac/boost/changeset/55796
Log:
Make level sticky.
Text files modified:
sandbox/explore/boost/explore/container_stream_state.hpp | 49 ++++++++-------
sandbox/explore/boost/explore/manipulators.hpp | 118 +++++++++++++++++++++------------------
sandbox/explore/boost/explore/pair.hpp | 4
sandbox/explore/boost/explore/stream_container.hpp | 10 +-
sandbox/explore/boost/explore/stream_value.hpp | 2
sandbox/explore/libs/explore/test/boost_variant.cpp | 5 +
sandbox/explore/libs/explore/test/html_table_output.cpp | 8 +-
sandbox/explore/libs/explore/test/multi_dim_test.cpp | 16 ++--
8 files changed, 114 insertions(+), 98 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 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
@@ -43,7 +43,7 @@
typedef std::vector<std::size_t, std::allocator<std::size_t> > size_cont_typ;
container_stream_state()
- : m_depth(0)
+ : m_depth(0), m_level(0)
{
init<Elem>();
}
@@ -64,24 +64,26 @@
}
// 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::size_t rows(std::size_t index = 0) const { return at(m_rows, index); }
- std::size_t itemwidth(std::size_t index = 0) const { return at(m_itemwidth, index); }
+ const str_typ& separator() const { return at(m_separator); }
+ const str_typ& start(std::size_t index = 0) const { return at(m_start); }
+ const str_typ& end() const { return at(m_end); }
+ const str_typ& assoc_separator() const { return at(m_assoc_separator); }
+ const str_typ& assoc_start() const { return at(m_assoc_start); }
+ const str_typ& assoc_end() const { return at(m_assoc_end); }
+ std::size_t rows() const { return at(m_rows); }
+ std::size_t itemwidth() const { return at(m_itemwidth); }
// 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_rows(std::size_t rows, std::size_t index = 0) { at(m_rows, index) = rows; }
- void set_itemwidth(std::size_t iw, std::size_t index = 0) { at(m_itemwidth, index) = iw; }
+ void set_separator(const str_typ& str) { at(m_separator) = str; }
+ void set_start(const str_typ& str) { at(m_start) = str; }
+ void set_end(const str_typ& str) { at(m_end) = str; }
+ void set_assoc_separator(const str_typ& str) { at(m_assoc_separator) = str; }
+ void set_assoc_start(const str_typ& str) { at(m_assoc_start) = str; }
+ void set_assoc_end(const str_typ& str) { at(m_assoc_end) = str; }
+ void set_rows(std::size_t rows) { at(m_rows) = rows; }
+ void set_itemwidth(std::size_t iw) { at(m_itemwidth) = iw; }
+
+ void set_level(size_t l) { m_level = l; }
std::size_t depth() const
{
@@ -99,6 +101,7 @@
str_cont_typ m_assoc_start;
str_cont_typ m_assoc_end;
std::size_t m_depth;
+ std::size_t m_level;
size_cont_typ m_rows;
size_cont_typ m_itemwidth;
@@ -112,22 +115,22 @@
// read
template<typename T>
- const T& at(const std::vector<T>& c, std::size_t index) const
+ const T& at(const std::vector<T>& c) const
{
// return the highest item if it does not exist at the given index
- return c[std::min(index, c.size() - 1)];
+ return c[std::min(m_level, c.size() - 1)];
}
// write
template<typename T>
- T& at(std::vector<T>& c, std::size_t index)
+ T& at(std::vector<T>& c)
{
- if( c.size() <= index )
+ if( c.size() <= m_level )
{
- c.resize(index+1);
+ c.resize(m_level+1);
}
- return c[index];
+ return c[m_level];
}
};
}}
Modified: sandbox/explore/boost/explore/manipulators.hpp
==============================================================================
--- sandbox/explore/boost/explore/manipulators.hpp (original)
+++ sandbox/explore/boost/explore/manipulators.hpp 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
@@ -23,7 +23,7 @@
struct depth_guard
{
depth_guard(container_stream_state<Elem>* state)
- : m_state(state)
+ : m_state(state), m_prev_level(state->m_level)
{
++m_state->m_depth;
}
@@ -31,10 +31,12 @@
~depth_guard()
{
--m_state->m_depth;
+ m_state->m_level = m_prev_level;
}
private:
container_stream_state<Elem>* m_state;
+ size_t m_prev_level;
};
// manipulator function wrapper for 1 char/wchar_t argument. When streamed, will run manipulator
@@ -42,131 +44,141 @@
template<typename T>
struct manipfunc
{
- manipfunc(void (*fun)(std::ios_base&, T, std::size_t), T val, std::size_t d)
- : pfun(fun), arg(val), depth(d)
+ manipfunc(void (*fun)(std::ios_base&, T), T val)
+ : pfun(fun), arg(val)
{
}
- void (*pfun)(std::ios_base&, T, std::size_t);
+ void (*pfun)(std::ios_base&, T);
T arg;
- std::size_t depth;
};
// stream manipfunc
template<typename Elem, typename Tr, typename T>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const manipfunc<T>& manip)
{
- (*manip.pfun)(ostr, manip.arg, manip.depth);
+ (*manip.pfun)(ostr, manip.arg);
return ostr;
}
// function ptr for separator manipulator
template<typename Elem>
- void separatorFn(std::ios_base& ostr, const Elem* sep, std::size_t depth)
+ void separatorFn(std::ios_base& ostr, const Elem* sep)
{
- explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_separator(sep, depth);
+ explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_separator(sep);
}
// function ptr for start manipulator
template<typename Elem>
- void startFn(std::ios_base& ostr, const Elem* start, std::size_t depth)
+ void startFn(std::ios_base& ostr, const Elem* start)
{
- explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_start(start, depth);
+ explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_start(start);
}
// function ptr for end manipulator
template<typename Elem>
- void endFn(std::ios_base& ostr, const Elem* end, std::size_t depth)
+ void endFn(std::ios_base& ostr, const Elem* end)
{
- explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_end(end, depth);
+ explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_end(end);
}
// function ptr for associative separator manipulator
template<typename Elem>
- void assoc_separatorFn(std::ios_base& ostr, const Elem* sep, std::size_t depth)
+ void assoc_separatorFn(std::ios_base& ostr, const Elem* sep)
{
- explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_assoc_separator(sep, depth);
+ explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_assoc_separator(sep);
}
// function ptr for associative start manipulator
template<typename Elem>
- void assoc_startFn(std::ios_base& ostr, const Elem* start, std::size_t depth)
+ void assoc_startFn(std::ios_base& ostr, const Elem* start)
{
- explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_assoc_start(start, depth);
+ explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_assoc_start(start);
}
// function ptr for associative end manipulator
template<typename Elem>
- void assoc_endFn(std::ios_base& ostr, const Elem* end, std::size_t depth)
+ void assoc_endFn(std::ios_base& ostr, const Elem* end)
{
- explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_assoc_end(end, depth);
+ explore::get_stream_state<container_stream_state<Elem> >(ostr)->set_assoc_end(end);
+ }
+
+ void levelFn(std::ios_base& ostr, std::size_t l)
+ {
+ explore::get_stream_state<container_stream_state<char> >(ostr)->set_level(l);
}
// function ptr object for setrows
//template<typename Elem>
- void setrowsFn(std::ios_base& ostr, std::size_t sz, std::size_t depth)
+ void setrowsFn(std::ios_base& ostr, std::size_t sz)
{
- explore::get_stream_state<container_stream_state<char> >(ostr)->set_rows(sz, depth);
+ explore::get_stream_state<container_stream_state<char> >(ostr)->set_rows(sz);
}
// function ptr object for setrows
//template<typename Elem>
- void setitemwidthFn(std::ios_base& ostr, std::size_t sz, std::size_t depth)
+ void setitemwidthFn(std::ios_base& ostr, std::size_t sz)
{
- explore::get_stream_state<container_stream_state<char> >(ostr)->set_itemwidth(sz, depth);
+ explore::get_stream_state<container_stream_state<char> >(ostr)->set_itemwidth(sz);
}
}
// manipulator
template<typename Elem>
- detail::manipfunc<const Elem*> separator(const Elem* sep, std::size_t depth = 0)
+ detail::manipfunc<const Elem*> separator(const Elem* sep)
{
- return detail::manipfunc<const Elem*>(&detail::separatorFn, sep, depth);
+ return detail::manipfunc<const Elem*>(&detail::separatorFn, sep);
}
// manipulator
template<typename Elem>
- detail::manipfunc<const Elem*> start(const Elem* Start, std::size_t depth = 0)
+ detail::manipfunc<const Elem*> start(const Elem* s)
{
- return detail::manipfunc<const Elem*>(&detail::startFn, Start, depth);
+ return detail::manipfunc<const Elem*>(&detail::startFn, s);
}
// manipulator
template<typename Elem>
- detail::manipfunc<const Elem*> end(const Elem* end, std::size_t depth = 0)
+ detail::manipfunc<const Elem*> end(const Elem* e)
{
- return detail::manipfunc<const Elem*>(&detail::endFn, end, depth);
+ return detail::manipfunc<const Elem*>(&detail::endFn, e);
}
// manipulator
template<typename Elem>
- detail::manipfunc<const Elem*> assoc_separator(const Elem* sep, std::size_t depth = 0)
+ detail::manipfunc<const Elem*> assoc_separator(const Elem* sep)
{
- return detail::manipfunc<const Elem*>(&detail::assoc_separatorFn, sep, depth);
+ return detail::manipfunc<const Elem*>(&detail::assoc_separatorFn, sep);
}
// manipulator
template<typename Elem>
- detail::manipfunc<const Elem*> assoc_start(const Elem* start, std::size_t depth = 0)
+ detail::manipfunc<const Elem*> assoc_start(const Elem* start)
{
- return detail::manipfunc<const Elem*>(&detail::assoc_startFn, start, depth);
+ return detail::manipfunc<const Elem*>(&detail::assoc_startFn, start);
}
// manipulator
template<typename Elem>
- detail::manipfunc<const Elem*> assoc_end(const Elem* end, std::size_t depth = 0)
+ detail::manipfunc<const Elem*> assoc_end(const Elem* end)
{
- return detail::manipfunc<const Elem*>(&detail::assoc_endFn, end, depth);
+ return detail::manipfunc<const Elem*>(&detail::assoc_endFn, end);
}
-
- detail::manipfunc<std::size_t> setrows(std::size_t sz, std::size_t depth = 0)
+
+ // manipulator
+ detail::manipfunc<std::size_t> level(std::size_t l)
+ {
+ return detail::manipfunc<std::size_t>(&detail::levelFn, l);
+ }
+
+ detail::manipfunc<std::size_t> setrows(std::size_t sz)
{
- return detail::manipfunc<std::size_t>(detail::setrowsFn, sz, depth);
+ return detail::manipfunc<std::size_t>(detail::setrowsFn, sz);
}
- detail::manipfunc<std::size_t> setitemwidth(std::size_t sz, std::size_t depth = 0)
+ detail::manipfunc<std::size_t> setitemwidth(std::size_t sz)
{
- return detail::manipfunc<std::size_t>(detail::setitemwidthFn, sz, depth);
+ return detail::manipfunc<std::size_t>(detail::setitemwidthFn, sz);
}
// manipulator
@@ -193,30 +205,29 @@
template<typename T>
struct begin_end_manipulator
{
- begin_end_manipulator(T& startVal, T& endVal, std::size_t d)
- :startVal_(startVal), endVal_(endVal), depth_(d)
+ begin_end_manipulator(T& startVal, T& endVal)
+ :startVal_(startVal), endVal_(endVal)
{
}
T startVal_;
T endVal_;
- std::size_t depth_;
};
template<typename Elem, typename Tr, typename T>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const begin_end_manipulator<T>& manip)
{
- startFn(ostr, manip.startVal_, manip.depth_);
- endFn(ostr, manip.endVal_, manip.depth_);
+ startFn(ostr, manip.startVal_);
+ endFn(ostr, manip.endVal_);
return ostr;
}
}
template<typename Elem>
- detail::begin_end_manipulator<const Elem*> begin_end(const Elem* start, const Elem* end, std::size_t depth = 0)
+ detail::begin_end_manipulator<const Elem*> begin_end(const Elem* start, const Elem* end)
{
// todo: just use delimiters function and fetch seperator?
- return detail::begin_end_manipulator<const Elem*>(start, end, depth);
+ return detail::begin_end_manipulator<const Elem*>(start, end);
}
@@ -226,31 +237,30 @@
template<typename T>
struct delimiters_manipulator
{
- delimiters_manipulator(T& startVal, T& seperatorVal, T& endVal, std::size_t d)
- :startVal_(startVal), seperatorVal_(seperatorVal), endVal_(endVal), depth_(d)
+ delimiters_manipulator(T& startVal, T& seperatorVal, T& endVal)
+ :startVal_(startVal), seperatorVal_(seperatorVal), endVal_(endVal)
{
}
T startVal_;
T seperatorVal_;
T endVal_;
- std::size_t depth_;
};
template<typename Elem, typename Tr, typename T>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const delimiters_manipulator<T>& manip)
{
- startFn(ostr, manip.startVal_, manip.depth_);
- separatorFn(ostr, manip.seperatorVal_, manip.depth_);
- endFn(ostr, manip.endVal_, manip.depth_);
+ startFn(ostr, manip.startVal_);
+ separatorFn(ostr, manip.seperatorVal_);
+ endFn(ostr, manip.endVal_);
return ostr;
}
}
template<typename Elem>
- detail::delimiters_manipulator<const Elem*> delimiters(const Elem* start, const Elem* seperator, const Elem* end, std::size_t depth = 0)
+ detail::delimiters_manipulator<const Elem*> delimiters(const Elem* start, const Elem* seperator, const Elem* end)
{
- return detail::delimiters_manipulator<const Elem*>(start, seperator, end, depth);
+ return detail::delimiters_manipulator<const Elem*>(start, seperator, end);
}
}}
Modified: sandbox/explore/boost/explore/pair.hpp
==============================================================================
--- sandbox/explore/boost/explore/pair.hpp (original)
+++ sandbox/explore/boost/explore/pair.hpp 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
@@ -22,8 +22,8 @@
using namespace boost::explore;
container_stream_state<Elem>* state = get_stream_state<container_stream_state<Elem> >(ostr);
detail::depth_guard<Elem> guard(state);
- std::size_t depth = state->depth();
- return ostr << state->start(depth) << p.first << state->separator(depth) << p.second << state->end(depth);
+ state->set_level(state->depth());
+ return ostr << state->start() << p.first << state->separator() << p.second << state->end();
}
}
Modified: sandbox/explore/boost/explore/stream_container.hpp
==============================================================================
--- sandbox/explore/boost/explore/stream_container.hpp (original)
+++ sandbox/explore/boost/explore/stream_container.hpp 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
@@ -25,12 +25,12 @@
// grab the extra data embedded in the stream object.
container_stream_state<Elem>* state = explore::get_stream_state<container_stream_state<Elem> >(ostr);
detail::depth_guard<Elem> guard(state);
- std::size_t depth = state->depth();
+ state->set_level(state->depth());
// starting delimiter
- ostr << state->start(depth);
+ ostr << state->start();
- std::size_t rows = state->rows(depth);
+ std::size_t rows = state->rows();
std::size_t cur_row = 0;
while( first != last )
@@ -41,7 +41,7 @@
if( ++first != last )
{
// separation delimiter
- ostr << state->separator(depth);
+ ostr << state->separator();
if( rows && ++cur_row == rows )
{
@@ -52,7 +52,7 @@
}
// ending delimiter
- return ostr << state->end(depth);
+ return ostr << state->end();
}
template<typename Elem, typename Tr, typename FwdIter>
Modified: sandbox/explore/boost/explore/stream_value.hpp
==============================================================================
--- sandbox/explore/boost/explore/stream_value.hpp (original)
+++ sandbox/explore/boost/explore/stream_value.hpp 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
@@ -21,7 +21,7 @@
template<typename Elem, typename Tr, typename T>
void operator()(std::basic_ostream<Elem, Tr>& ostr, const T& val, container_stream_state<Elem>* state)
{
- ostr.width(state->itemwidth(state->depth()));
+ ostr.width(state->itemwidth());
ostr << val;
}
};
Modified: sandbox/explore/libs/explore/test/boost_variant.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/boost_variant.cpp (original)
+++ sandbox/explore/libs/explore/test/boost_variant.cpp 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
@@ -62,11 +62,12 @@
varVec.push_back(favoriteNumbers);
varVec.push_back(".");
- // level 0
+ str_out << level(0);
str_out << start("") << boost::explore::end("") << separator("");
// level 1 (for nested collection)
- str_out << start("[", 1) << boost::explore::end("]", 1) << separator(", ", 1);
+ str_out << level(1);
+ str_out << start("[") << boost::explore::end("]") << separator(", ");
str_out << varVec;
BOOST_CHECK_EQUAL(str_out.str(), "Hello, my name is Joe. I am 34 years old. My favorite numbers are: [22, 42, 73].");
Modified: sandbox/explore/libs/explore/test/html_table_output.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/html_table_output.cpp (original)
+++ sandbox/explore/libs/explore/test/html_table_output.cpp 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
@@ -18,13 +18,15 @@
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 << start("<tr><td>", 1)
- << separator("</td><td>", 1)
- << boost::explore::end("</td></tr>\n", 1);
+ ostr << level(1);
+ ostr << start("<tr><td>")
+ << separator("</td><td>")
+ << boost::explore::end("</td></tr>\n");
return ostr;
}
Modified: sandbox/explore/libs/explore/test/multi_dim_test.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/multi_dim_test.cpp (original)
+++ sandbox/explore/libs/explore/test/multi_dim_test.cpp 2009-08-26 23:05:54 EDT (Wed, 26 Aug 2009)
@@ -18,11 +18,11 @@
{
using namespace boost::explore;
- // level 0
+ ostr << level(0);
ostr << start("") << boost::explore::end("") << separator("\n");
- // level 1
- ostr << start("|", 1) << boost::explore::end("|", 1) << separator(" ", 1);
+ ostr << level(1);
+ ostr << start("|") << boost::explore::end("|") << separator(" ");
return ostr;
}
@@ -53,14 +53,14 @@
{
using namespace boost::explore;
- // level 0
+ ostr << level(0);
ostr << start("") << boost::explore::end("") << separator("\n\n");
- // level 1
- ostr << start("", 1) << boost::explore::end("", 1) << separator("\n", 1);
+ ostr << level(1);
+ ostr << start("") << boost::explore::end("") << separator("\n");
- // level 2
- ostr << start("|", 2) << boost::explore::end("|", 2) << separator(" ", 2);
+ ostr << level(2);
+ ostr << start("|") << boost::explore::end("|") << separator(" ");
return ostr;
}
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