Boost logo

Boost-Commit :

From: jmcintyre_at_[hidden]
Date: 2008-04-30 15:32:42


Author: jared
Date: 2008-04-30 15:32:41 EDT (Wed, 30 Apr 2008)
New Revision: 44944
URL: http://svn.boost.org/trac/boost/changeset/44944

Log:
Added documentation for custom formatters on different levels and output for custom containers.
Text files modified:
   sandbox/explore/libs/explore/doc/custom_containers.qbk | 42 +++++++++++++++++++++++++++++
   sandbox/explore/libs/explore/doc/custom_delimeters.qbk | 33 +++++++++++++++++++++--
   sandbox/explore/libs/explore/doc/html/boost_explore/dependencies_platforms.html | 4 +-
   sandbox/explore/libs/explore/doc/html/boost_explore/design.html | 2
   sandbox/explore/libs/explore/doc/html/boost_explore/tutorial/custom_containers.html | 56 ++++++++++++++++++++++++++++++++++++++-
   sandbox/explore/libs/explore/doc/html/boost_explore/tutorial/custom_delimeters.html | 46 +++++++++++++++++++++++++++-----
   sandbox/explore/libs/explore/doc/html/index.html | 6 ++--
   7 files changed, 170 insertions(+), 19 deletions(-)

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 2008-04-30 15:32:41 EDT (Wed, 30 Apr 2008)
@@ -9,6 +9,46 @@
 
 You can use explore with your custom containers, or third party containers. However, explore needs a little help in understanding these classes.
 
-Eventually, it would be good to write something here explaining how you can do that. 8-)
+The following is a very simple class that contains a 1, 2, and 3 along with the begin and end functions to access the iterators for the container.
+
+ class user_vector
+ {
+ public:
+ user_vector()
+ {
+ m_vec.push_back(1);
+ m_vec.push_back(2);
+ m_vec.push_back(3);
+ }
+
+ std::vector<int>::const_iterator begin() const
+ {
+ return m_vec.begin();
+ }
+
+ std::vector<int>::const_iterator end() const
+ {
+ return m_vec.end();
+ }
+
+ private:
+ std::vector<int> m_vec;
+ };
+
+To allow the user_vector to stream properly, you must create an operator<< overload that for the user_vector class that wrapps a call to the explore::stream_container helper function. The stream_container helper iterates through a range outputting the proper delimeters along with the values in the range. So, the operator<< passes into stream_container the result of the begin and end functions, and allows stream_container to process the contents for it.
+
+ std::ostream& operator<<(std::ostream& ostr, const user_vector& u)
+ {
+ return explore::stream_container(ostr, u.begin(), u.end());
+ }
+
+With our new overloaded operator<<, the following code
+
+ user_vector v;
+ str_out << v;
+
+prints
+
+ [1, 2, 3]
 
 [endsect]

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 2008-04-30 15:32:41 EDT (Wed, 30 Apr 2008)
@@ -33,10 +33,37 @@
 
 [heading Delimeters by Level]
 
-finish this
+Sometimes you need to output your code differently for nested containers. To do this, create a custom formatter and define different formatting rules for different levels. The following formatter prints all child containers on a new line, and those child containers have custom delimeters.
 
-[heading Level Breaks]
+ std::ostream& format_2d(std::ostream& ostr)
+ {
+ using namespace explore;
+
+ // level 0
+ ostr << start("") << explore::end("") << separator("\n");
+
+ // level 1
+ ostr << start("|", 1) << explore::end("|", 1) << separator(" ", 1);
+
+ return ostr;
+ }
 
-finish this
+The following example uses the above formatter against a vector containing a vector of int.
+
+ std::vector<int> vi;
+ vi.push_back(1);
+ vi.push_back(2);
+ vi.push_back(3);
+ std::vector<std::vector<int> > vvi;
+ vvi.push_back(vi);
+ vvi.push_back(vi);
+ vvi.push_back(vi);
+ str_out << format_2d << vvi;
+
+This prints
+
+ |1 2 3|
+ |1 2 3|
+ |1 2 3|
 
 [endsect]

Modified: sandbox/explore/libs/explore/doc/html/boost_explore/dependencies_platforms.html
==============================================================================
--- sandbox/explore/libs/explore/doc/html/boost_explore/dependencies_platforms.html (original)
+++ sandbox/explore/libs/explore/doc/html/boost_explore/dependencies_platforms.html 2008-04-30 15:32:41 EDT (Wed, 30 Apr 2008)
@@ -27,7 +27,7 @@
 <a name="boost_explore.dependencies_platforms"></a><a href="dependencies_platforms.html" title="Dependencies and Platforms"> Dependencies and
     Platforms</a></h2></div></div></div>
 <a name="boost_explore.dependencies_platforms.dependencies"></a><h3>
-<a name="id974523"></a>
+<a name="id975827"></a>
       <a href="dependencies_platforms.html#boost_explore.dependencies_platforms.dependencies">Dependencies</a>
     </h3>
 <p>
@@ -51,7 +51,7 @@
       </li>
 </ul></div>
 <a name="boost_explore.dependencies_platforms.supported_platforms"></a><h3>
-<a name="id974574"></a>
+<a name="id975879"></a>
       <a href="dependencies_platforms.html#boost_explore.dependencies_platforms.supported_platforms">Supported
       Platforms</a>
     </h3>

Modified: sandbox/explore/libs/explore/doc/html/boost_explore/design.html
==============================================================================
--- sandbox/explore/libs/explore/doc/html/boost_explore/design.html (original)
+++ sandbox/explore/libs/explore/doc/html/boost_explore/design.html 2008-04-30 15:32:41 EDT (Wed, 30 Apr 2008)
@@ -25,7 +25,7 @@
 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
 <a name="boost_explore.design"></a> Design Notes</h2></div></div></div>
 <a name="boost_explore.design.rationale"></a><h3>
-<a name="id974684"></a>
+<a name="id975989"></a>
       <a href="design.html#boost_explore.design.rationale">Rationale</a>
     </h3>
 <p>

Modified: sandbox/explore/libs/explore/doc/html/boost_explore/tutorial/custom_containers.html
==============================================================================
--- sandbox/explore/libs/explore/doc/html/boost_explore/tutorial/custom_containers.html (original)
+++ sandbox/explore/libs/explore/doc/html/boost_explore/tutorial/custom_containers.html 2008-04-30 15:32:41 EDT (Wed, 30 Apr 2008)
@@ -30,9 +30,61 @@
         However, explore needs a little help in understanding these classes.
       </p>
 <p>
- Eventually, it would be good to write something here explaining how you can
- do that. 8-)
+ The following is a very simple class that contains a 1, 2, and 3 along with
+ the begin and end functions to access the iterators for the container.
       </p>
+<pre class="programlisting">
+<span class="keyword">class</span> <span class="identifier">user_vector</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">user_vector</span><span class="special">()</span>
+ <span class="special">{</span>
+ <span class="identifier">m_vec</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">1</span><span class="special">);</span>
+ <span class="identifier">m_vec</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">2</span><span class="special">);</span>
+ <span class="identifier">m_vec</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">3</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;::</span><span class="identifier">const_iterator</span> <span class="identifier">begin</span><span class="special">()</span> <span class="keyword">const</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">m_vec</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;::</span><span class="identifier">const_iterator</span> <span class="identifier">end</span><span class="special">()</span> <span class="keyword">const</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">m_vec</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span>
+ <span class="special">}</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">m_vec</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ To allow the user_vector to stream properly, you must create an operator&lt;&lt;
+ overload that for the user_vector class that wrapps a call to the explore::stream_container
+ helper function. The stream_container helper iterates through a range outputting
+ the proper delimeters along with the values in the range. So, the operator&lt;&lt;
+ passes into stream_container the result of the begin and end functions, and
+ allows stream_container to process the contents for it.
+ </p>
+<pre class="programlisting">
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">&lt;&lt;(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&amp;</span> <span class="identifier">ostr</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">user_vector</span><span class="special">&amp;</span> <span class="identifier">u</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">explore</span><span class="special">::</span><span class="identifier">stream_container</span><span class="special">(</span><span class="identifier">ostr</span><span class="special">,</span> <span class="identifier">u</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">u</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
+<span class="special">}</span>
+</pre>
+<p>
+ With our new overloaded operator&lt;&lt;, the following code
+ </p>
+<pre class="programlisting">
+<span class="identifier">user_vector</span> <span class="identifier">v</span><span class="special">;</span>
+<span class="identifier">str_out</span> <span class="special">&lt;&lt;</span> <span class="identifier">v</span><span class="special">;</span>
+</pre>
+<p>
+ prints
+ </p>
+<pre class="programlisting">
+<span class="special">[</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">]</span>
+</pre>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
 <td align="left"></td>

Modified: sandbox/explore/libs/explore/doc/html/boost_explore/tutorial/custom_delimeters.html
==============================================================================
--- sandbox/explore/libs/explore/doc/html/boost_explore/tutorial/custom_delimeters.html (original)
+++ sandbox/explore/libs/explore/doc/html/boost_explore/tutorial/custom_delimeters.html 2008-04-30 15:32:41 EDT (Wed, 30 Apr 2008)
@@ -183,16 +183,48 @@
         by Level</a>
       </h5>
 <p>
- finish this
+ Sometimes you need to output your code differently for nested containers.
+ To do this, create a custom formatter and define different formatting rules
+ for different levels. The following formatter prints all child containers
+ on a new line, and those child containers have custom delimeters.
       </p>
-<a name="boost_explore.tutorial.custom_delimeters.level_breaks"></a><h5>
-<a name="id974448"></a>
- <a href="custom_delimeters.html#boost_explore.tutorial.custom_delimeters.level_breaks">Level
- Breaks</a>
- </h5>
+<pre class="programlisting">
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&amp;</span> <span class="identifier">format_2d</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&amp;</span> <span class="identifier">ostr</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">explore</span><span class="special">;</span>
+
+ <span class="comment">// level 0
+</span> <span class="identifier">ostr</span> <span class="special">&lt;&lt;</span> <span class="identifier">start</span><span class="special">(</span><span class="string">""</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">explore</span><span class="special">::</span><span class="identifier">end</span><span class="special">(</span><span class="string">""</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">separator</span><span class="special">(</span><span class="string">"\n"</span><span class="special">);</span>
+
+ <span class="comment">// level 1
+</span> <span class="identifier">ostr</span> <span class="special">&lt;&lt;</span> <span class="identifier">start</span><span class="special">(</span><span class="string">"|"</span><span class="special">,</span> <span class="number">1</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">explore</span><span class="special">::</span><span class="identifier">end</span><span class="special">(</span><span class="string">"|"</span><span class="special">,</span> <span class="number">1</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">separator</span><span class="special">(</span><span class="string">" "</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span>
+
+ <span class="keyword">return</span> <span class="identifier">ostr</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ The following example uses the above formatter against a vector containing
+ a vector of int.
+ </p>
+<pre class="programlisting">
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">vi</span><span class="special">;</span>
+<span class="identifier">vi</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">1</span><span class="special">);</span>
+<span class="identifier">vi</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">2</span><span class="special">);</span>
+<span class="identifier">vi</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="number">3</span><span class="special">);</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">vvi</span><span class="special">;</span>
+<span class="identifier">vvi</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">vi</span><span class="special">);</span>
+<span class="identifier">vvi</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">vi</span><span class="special">);</span>
+<span class="identifier">vvi</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">vi</span><span class="special">);</span>
+<span class="identifier">str_out</span> <span class="special">&lt;&lt;</span> <span class="identifier">format_2d</span> <span class="special">&lt;&lt;</span> <span class="identifier">vvi</span><span class="special">;</span>
+</pre>
 <p>
- finish this
+ This prints
       </p>
+<pre class="programlisting">
+<span class="special">|</span><span class="number">1</span> <span class="number">2</span> <span class="number">3</span><span class="special">|</span>
+<span class="special">|</span><span class="number">1</span> <span class="number">2</span> <span class="number">3</span><span class="special">|</span>
+<span class="special">|</span><span class="number">1</span> <span class="number">2</span> <span class="number">3</span><span class="special">|</span>
+</pre>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
 <td align="left"></td>

Modified: sandbox/explore/libs/explore/doc/html/index.html
==============================================================================
--- sandbox/explore/libs/explore/doc/html/index.html (original)
+++ sandbox/explore/libs/explore/doc/html/index.html 2008-04-30 15:32:41 EDT (Wed, 30 Apr 2008)
@@ -47,7 +47,7 @@
     Boost.explore is a cross-platform C++ library for printing of containers.
   </p>
 <a name="boost_explore..getting_started"></a><h3>
-<a name="id974754"></a>
+<a name="id976058"></a>
     <a href="index.html#boost_explore..getting_started">Getting Started</a>
   </h3>
 <p>
@@ -102,7 +102,7 @@
     be considered.
   </p>
 <a name="boost_explore..supported_containers"></a><h3>
-<a name="id975686"></a>
+<a name="id976990"></a>
     <a href="index.html#boost_explore..supported_containers">Supported Containers</a>
   </h3>
 <div class="itemizedlist"><ul type="disc">
@@ -148,7 +148,7 @@
     can also be made to work with explore.
   </p>
 <a name="boost_explore..acknowledgements"></a><h3>
-<a name="id975766"></a>
+<a name="id977070"></a>
     <a href="index.html#boost_explore..acknowledgements">Acknowledgements</a>
   </h3>
 <p>


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