Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54637 - in sandbox/cloneable: boost/cloneable libs/cloneable/doc libs/cloneable/doc/html libs/cloneable/doc/html/cloneable/tutorial libs/cloneable/test
From: christian.schladetsch_at_[hidden]
Date: 2009-07-04 05:37:16


Author: cschladetsch
Date: 2009-07-04 05:37:15 EDT (Sat, 04 Jul 2009)
New Revision: 54637
URL: http://svn.boost.org/trac/boost/changeset/54637

Log:
udpated
Added:
   sandbox/cloneable/boost/cloneable/cloneable.hpp (contents, props changed)
Text files modified:
   sandbox/cloneable/libs/cloneable/doc/cloneable.qbk | 41 +++++++++++++++++++++++----
   sandbox/cloneable/libs/cloneable/doc/html/cloneable/tutorial/simple_hierarchical_cloning.html | 59 +++++++++++++++++++++++++++++++++------
   sandbox/cloneable/libs/cloneable/doc/html/index.html | 2
   sandbox/cloneable/libs/cloneable/test/cloneable.vcproj | 4 ++
   4 files changed, 88 insertions(+), 18 deletions(-)

Added: sandbox/cloneable/boost/cloneable/cloneable.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/cloneable.hpp 2009-07-04 05:37:15 EDT (Sat, 04 Jul 2009)
@@ -0,0 +1,13 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+// 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_CLONEABLE_CLONEABLE_HPP
+#define BOOST_CLONEABLE_CLONEABLE_HPP
+
+#include <boost/cloneable/base.hpp>
+
+#endif // BOOST_CLONEABLE_CLONEABLE_HPP
+
+//EOF

Modified: sandbox/cloneable/libs/cloneable/doc/cloneable.qbk
==============================================================================
--- sandbox/cloneable/libs/cloneable/doc/cloneable.qbk (original)
+++ sandbox/cloneable/libs/cloneable/doc/cloneable.qbk 2009-07-04 05:37:15 EDT (Sat, 04 Jul 2009)
@@ -121,6 +121,12 @@
     virtual ~Animal() { }
     virtual string get_name() const = 0;
 };
+``
+
+Note that `Animal` doesn't have to derive from anything, or have any special members or methods.
+Now let's use out base class to create a simple type hierarchy:
+
+``
 
 class Cat : public cloneable::base<Cat, Animal>
 {
@@ -131,7 +137,15 @@
     Cat(string n) : name(n) { }
     string get_name() const { return name; }
 };
+``
+
+We derive our `Cat` class from `cloneable::base<Cat, Animal>`. The first type argument to `base<...>` is
+the derived type to use for cloning, and the second argument is the common base type of the hierarhcy.
+Other than that, `Cat` implements the `get_name` pure virtual method derived in the base class `Animal`.
 
+Now, let's use it:
+
+``
 int main()
 {
     Cat *cat = new Cat("sam");
@@ -148,7 +162,7 @@
 };
 ``
 
-In this example, we note that the `clone()` method returns
+Note that the `clone()` method returns
 a pointer to the base class of the type hierarchy - in this case, `Animal`.
 We had to use a dynamic cast to down-cast to our derived type.
 
@@ -171,7 +185,13 @@
 class Labrador : public Dog, public cloneable::base<Labrador, Animal>
 {
 };
+``
+
+`Dog` is just like a cat, but different. `Labrador` is the first example we have seen
+that uses multiple inheritance. In this case, we are saying that a Labrador is-a Dog,
+and is Cloneable as either a Dog or a Labrador. Using these types:
 
+``
 int main()
 {
     Labrador *lab = new Labrador();
@@ -186,7 +206,7 @@
 ``
 
 Here we see that class Labrador is-a Dog, and is also cloneable as a Labrador.
-When cloning this class, we specify which sub-object we wish to duplicate. Note that
+When cloning this class, we specify which sub-object we wish to duplicate.
 when using `clone_as<T>`, we actually are making a type of T, rather than making another type and casting up.
 
 We can also use the Cloneable library to make a new instance, with no duplication:
@@ -228,12 +248,22 @@
 ``
 struct Base { virtual ~Base() {} };
 
-struct T0 : cloneable::base<T0, Base, no_default_construction>
+struct T0 : cloneable::base<T0, Base, no_default_construction_tag>
 {
     string &str;
     T0(string &s) : str(s) { }
 };
+``
 
+`T0` has a member that is a reference and as such doesn't have a default constructor.
+To avoid compile-time errors when using this type in the Cloneable libray, you must
+indicate that it is not default-constructible by passing the `no_default_construction_tag`
+type as a parameter to cloneable::base<>. The order that you give the base-type or tag-types
+to cloneable::base<> is not important and is dealt with be the library.
+
+Putting this type to use:
+
+``
 int main()
 {
     string str = "foo";
@@ -258,10 +288,7 @@
 }
 ``
 
-Note that we had to pass the `no_default_construction` tag-type to `cloneable::base<>` in
-the definition of T0. Without this, an error would occur when compiling the `create_new()` line.
-
-The `no_default_construction` tag is thrown if you attempt to default-construct a
+A `no_default_construction` exception is thrown if you attempt to default-construct a
 type that has no default constructor.
 
 [endsect]

Modified: sandbox/cloneable/libs/cloneable/doc/html/cloneable/tutorial/simple_hierarchical_cloning.html
==============================================================================
--- sandbox/cloneable/libs/cloneable/doc/html/cloneable/tutorial/simple_hierarchical_cloning.html (original)
+++ sandbox/cloneable/libs/cloneable/doc/html/cloneable/tutorial/simple_hierarchical_cloning.html 2009-07-04 05:37:15 EDT (Sat, 04 Jul 2009)
@@ -48,8 +48,18 @@
     <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">Animal</span><span class="special">()</span> <span class="special">{</span> <span class="special">}</span>
     <span class="keyword">virtual</span> <span class="identifier">string</span> <span class="identifier">get_name</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
 <span class="special">};</span>
-
-<span class="keyword">class</span> <span class="identifier">Cat</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">cloneable</span><span class="special">::</span><span class="identifier">base</span><span class="special">&lt;</span><span class="identifier">Cat</span><span class="special">,</span> <span class="identifier">Animal</span><span class="special">&gt;</span>
+</pre>
+<p>
+ </p>
+<p>
+ Note that <code class="computeroutput"><span class="identifier">Animal</span></code> doesn't
+ have to derive from anything, or have any special members or methods. Now
+ let's use out base class to create a simple type hierarchy:
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">Cat</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">cloneable</span><span class="special">::</span><span class="identifier">base</span><span class="special">&lt;</span><span class="identifier">Cat</span><span class="special">,</span> <span class="identifier">Animal</span><span class="special">&gt;</span>
 <span class="special">{</span>
     <span class="identifier">string</span> <span class="identifier">name</span><span class="special">;</span>
     
@@ -58,8 +68,24 @@
     <span class="identifier">Cat</span><span class="special">(</span><span class="identifier">string</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">name</span><span class="special">(</span><span class="identifier">n</span><span class="special">)</span> <span class="special">{</span> <span class="special">}</span>
     <span class="identifier">string</span> <span class="identifier">get_name</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">name</span><span class="special">;</span> <span class="special">}</span>
 <span class="special">};</span>
-
-<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
+</pre>
+<p>
+ </p>
+<p>
+ We derive our <code class="computeroutput"><span class="identifier">Cat</span></code> class from
+ <code class="computeroutput"><span class="identifier">cloneable</span><span class="special">::</span><span class="identifier">base</span><span class="special">&lt;</span><span class="identifier">Cat</span><span class="special">,</span> <span class="identifier">Animal</span><span class="special">&gt;</span></code>. The first type argument to <code class="computeroutput"><span class="identifier">base</span><span class="special">&lt;...&gt;</span></code>
+ is the derived type to use for cloning, and the second argument is the common
+ base type of the hierarhcy. Other than that, <code class="computeroutput"><span class="identifier">Cat</span></code>
+ implements the <code class="computeroutput"><span class="identifier">get_name</span></code> pure
+ virtual method derived in the base class <code class="computeroutput"><span class="identifier">Animal</span></code>.
+ </p>
+<p>
+ Now, let's use it:
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
 <span class="special">{</span>
     <span class="identifier">Cat</span> <span class="special">*</span><span class="identifier">cat</span> <span class="special">=</span> <span class="keyword">new</span> <span class="identifier">Cat</span><span class="special">(</span><span class="string">"sam"</span><span class="special">);</span>
 
@@ -77,9 +103,10 @@
 <p>
       </p>
 <p>
- In this example, we note that the <code class="computeroutput"><span class="identifier">clone</span><span class="special">()</span></code> method returns a pointer to the base class
- of the type hierarchy - in this case, <code class="computeroutput"><span class="identifier">Animal</span></code>.
- We had to use a dynamic cast to down-cast to our derived type.
+ Note that the <code class="computeroutput"><span class="identifier">clone</span><span class="special">()</span></code>
+ method returns a pointer to the base class of the type hierarchy - in this
+ case, <code class="computeroutput"><span class="identifier">Animal</span></code>. We had to use
+ a dynamic cast to down-cast to our derived type.
       </p>
 <p>
         If you know the derived type that you wish to be cloned, you can use the
@@ -111,8 +138,20 @@
 <span class="keyword">class</span> <span class="identifier">Labrador</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">Dog</span><span class="special">,</span> <span class="keyword">public</span> <span class="identifier">cloneable</span><span class="special">::</span><span class="identifier">base</span><span class="special">&lt;</span><span class="identifier">Labrador</span><span class="special">,</span> <span class="identifier">Animal</span><span class="special">&gt;</span>
 <span class="special">{</span>
 <span class="special">};</span>
-
-<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
+</pre>
+<p>
+ </p>
+<p>
+ <code class="computeroutput"><span class="identifier">Dog</span></code> is just like a cat, but
+ different. <code class="computeroutput"><span class="identifier">Labrador</span></code> is the
+ first example we have seen that uses multiple inheritance. In this case,
+ we are saying that a Labrador is-a Dog, and is Cloneable as either a Dog
+ or a Labrador. Using these types:
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
 <span class="special">{</span>
     <span class="identifier">Labrador</span> <span class="special">*</span><span class="identifier">lab</span> <span class="special">=</span> <span class="keyword">new</span> <span class="identifier">Labrador</span><span class="special">();</span>
     <span class="identifier">Dog</span> <span class="special">*</span><span class="identifier">dog</span> <span class="special">=</span> <span class="identifier">lab</span><span class="special">-&gt;</span><span class="identifier">clone_as</span><span class="special">&lt;</span><span class="identifier">Dog</span><span class="special">&gt;();</span>
@@ -129,7 +168,7 @@
 <p>
         Here we see that class Labrador is-a Dog, and is also cloneable as a Labrador.
         When cloning this class, we specify which sub-object we wish to duplicate.
- Note that when using <code class="computeroutput"><span class="identifier">clone_as</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>,
+ when using <code class="computeroutput"><span class="identifier">clone_as</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>,
         we actually are making a type of T, rather than making another type and casting
         up.
       </p>

Modified: sandbox/cloneable/libs/cloneable/doc/html/index.html
==============================================================================
--- sandbox/cloneable/libs/cloneable/doc/html/index.html (original)
+++ sandbox/cloneable/libs/cloneable/doc/html/index.html 2009-07-04 05:37:15 EDT (Sat, 04 Jul 2009)
@@ -74,7 +74,7 @@
 </div>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
-<td align="left"><p><small>Last revised: July 04, 2009 at 09:17:12 GMT</small></p></td>
+<td align="left"><p><small>Last revised: July 04, 2009 at 09:34:23 GMT</small></p></td>
 <td align="right"><div class="copyright-footer"></div></td>
 </tr></table>
 <hr>

Modified: sandbox/cloneable/libs/cloneable/test/cloneable.vcproj
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/cloneable.vcproj (original)
+++ sandbox/cloneable/libs/cloneable/test/cloneable.vcproj 2009-07-04 05:37:15 EDT (Sat, 04 Jul 2009)
@@ -277,6 +277,10 @@
>
                                 </File>
                                 <File
+ RelativePath="..\..\..\boost\cloneable\cloneable.hpp"
+ >
+ </File>
+ <File
                                         RelativePath="..\..\..\boost\cloneable\forward_declarations.hpp"
>
                                 </File>


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