Boost logo

Boost-Commit :

From: oryol_at_[hidden]
Date: 2008-02-12 22:06:05


Author: jeremypack
Date: 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
New Revision: 43233
URL: http://svn.boost.org/trac/boost/changeset/43233

Log:
Doc updates + 1 tutorial for reflection

Text files modified:
   sandbox/libs/reflection/doc/html/boost_reflection/introduction.html | 35 +++++++++++++++
   sandbox/libs/reflection/doc/html/boost_reflection/tutorials.html | 3
   sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial01.html | 86 +++++++++++++++++++++++++++++++++++++--
   sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial03.html | 6 +-
   sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial05.html | 5 -
   sandbox/libs/reflection/doc/html/index.html | 15 +-----
   sandbox/libs/reflection/doc/html/standalone_HTML.manifest | 6 --
   sandbox/libs/reflection/doc/introduction.qbk | 16 +++++++
   sandbox/libs/reflection/doc/reflection.qbk | 8 +--
   sandbox/libs/reflection/doc/tutorial1.qbk | 62 ++++++++++++++++++++++++++++
   sandbox/libs/reflection/doc/tutorials.qbk | 3
   sandbox/libs/reflection/examples/Jamfile.v2 | 4 +
   12 files changed, 210 insertions(+), 39 deletions(-)

Modified: sandbox/libs/reflection/doc/html/boost_reflection/introduction.html
==============================================================================
--- sandbox/libs/reflection/doc/html/boost_reflection/introduction.html (original)
+++ sandbox/libs/reflection/doc/html/boost_reflection/introduction.html 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -22,8 +22,39 @@
 <div class="spirit-nav">
 <a accesskey="p" href="../index.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="extension.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
 </div>
-<div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both">
-<a name="boost_reflection.introduction"></a> Introduction</h2></div></div></div></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_reflection.introduction"></a> Introduction</h2></div></div></div>
+<p>
+ The goal of this library is to provide runtime reflection for C++ classes,
+ and to allow the same across shared library boundaries. It is an offshoot of
+ the Extension library, which provides dynamic class loading across shared libraries.
+ Extension Interoperability provides an example
+ of using these libraries together.
+ </p>
+<p>
+ Boost.Reflection does not provide automatic reflection of classes. Instead,
+ the class data must be manually reflected. This does offer some benefits however:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ This can result in better performance, since only the necessary functions
+ are reflected.
+ </li>
+<li>
+ Arbitrary classes can be reflected without modification.
+ </li>
+<li>
+ It is possible to make a reflected interface that is quite different from
+ the original interface.
+ </li>
+</ul></div>
+<p>
+ This library is currently in development in preparation for a review for inclusion
+ in the Boost C++ Libraries. For ongoing status updates, check <a href="http://boost-extension.blogspot.com/" target="_top">C++
+ Plugins and Reflection</a>.
+ </p>
+</div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
 <td align="left"></td>
 <td align="right"><div class="copyright-footer">Copyright © 2007 -2008 Jeremy Pack, Mariano G. Consoni<p>

Modified: sandbox/libs/reflection/doc/html/boost_reflection/tutorials.html
==============================================================================
--- sandbox/libs/reflection/doc/html/boost_reflection/tutorials.html (original)
+++ sandbox/libs/reflection/doc/html/boost_reflection/tutorials.html 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -27,13 +27,12 @@
 <a name="boost_reflection.tutorials"></a>Tutorials</h2></div></div></div>
 <div class="toc"><dl>
 <dt><span class="section"> Tutorial 1</span></dt>
-<dt><span class="section"> Tutorial 2</span></dt>
 <dt><span class="section"> Tutorial 3</span></dt>
 <dt><span class="section"> Tutorial 4</span></dt>
 <dt><span class="section"> Tutorial 5</span></dt>
 </dl></div>
 <p>
- These are placeholders.
+ ]
     </p>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>

Modified: sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial01.html
==============================================================================
--- sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial01.html (original)
+++ sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial01.html 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -7,7 +7,7 @@
 <link rel="start" href="../../index.html" title="Chapter 1. Boost.Reflection 1.0">
 <link rel="up" href="../tutorials.html" title="Tutorials">
 <link rel="prev" href="../tutorials.html" title="Tutorials">
-<link rel="next" href="tutorial02.html" title=" Tutorial 2">
+<link rel="next" href="tutorial03.html" title=" Tutorial 3">
 </head>
 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
 <table cellpadding="2" width="100%"><tr>
@@ -20,10 +20,86 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="../tutorials.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial02.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="../tutorials.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial03.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_reflection.tutorials.tutorial01"></a> Tutorial 1</h3></div></div></div>
+<p>
+ The source code for this tutorial can be found in examples<span class="emphasis"><em>tutorial_1</em></span>.
+ </p>
+<p>
+ The <code class="computeroutput"><span class="identifier">reflection</span></code> class can
+ hold information about a reflected class. For this example, begin by creating
+ a class that we can reflect:
+</p>
+<pre class="programlisting">
+<span class="keyword">class</span> <span class="identifier">HelloWorld</span> <span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">void</span> <span class="identifier">printHelloWorld</span><span class="special">()</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Hello World!"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+</pre>
+<p>
+ Reflected classes do not need to have any special markup - any normal class
+ can be reflected. Now create a function to reflect out information about
+ this class:
+</p>
+<pre class="programlisting">
+<span class="identifier">reflection</span> <span class="identifier">GetReflection</span><span class="special">()</span> <span class="special">{</span>
+ <span class="comment">// This reflection will be returned
+</span> <span class="identifier">reflection</span> <span class="identifier">r</span><span class="special">;</span>
+
+ <span class="comment">// Use a reflector&lt;HelloWorld&gt; which will only reflect out constructors
+</span> <span class="comment">// and functions for the HelloWorld class.
+</span> <span class="identifier">reflector</span><span class="special">&lt;</span><span class="identifier">HelloWorld</span><span class="special">&gt;</span> <span class="identifier">current_reflector</span><span class="special">(&amp;</span><span class="identifier">r</span><span class="special">);</span>
+
+ <span class="comment">// Reflect an argless constructor
+</span> <span class="comment">// To reflect a constructor that takes a "const string&amp;" and an int,
+</span> <span class="comment">// call current_reflector.reflect_constructor&lt;const string&amp;, int&gt;().
+</span> <span class="identifier">current_reflector</span><span class="special">.</span><span class="identifier">reflect_constructor</span><span class="special">();</span>
+
+ <span class="comment">// Reflect a member function returning void and having no parameters.
+</span> <span class="comment">// To reflect a member returning a float and taking a single int as
+</span> <span class="comment">// an argument, use: current_reflector.reflect&lt;float, int&gt;().
+</span> <span class="identifier">current_reflector</span><span class="special">.</span><span class="identifier">reflect</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;(&amp;</span><span class="identifier">HelloWorld</span><span class="special">::</span><span class="identifier">printHelloWorld</span><span class="special">,</span>
+ <span class="string">"print hello world"</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">r</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ Now, somewhere else in the program, it is possible to use this function to
+ get a generic reflection instance, which can be used to instantiate the class
+ and call its reflected function.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting">
+<span class="identifier">reflection</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">GetReflection</span><span class="special">();</span>
+
+<span class="comment">// Make sure this class supports a default constructor, and a function
+</span><span class="comment">// identified as "print hello world" that has a void return value and
+</span><span class="comment">// takes no arguments. If we wanted a constructor that took one int argument,
+</span><span class="comment">// the call would become r.has_constructor&lt;int&gt;(). If we wanted a function
+</span><span class="comment">// that took two float arguments, and returned a double, the call would be
+</span><span class="comment">// r.has_function&lt;void, float, float&gt;("print hello world").
+</span><span class="keyword">if</span> <span class="special">(</span><span class="identifier">r</span><span class="special">.</span><span class="identifier">get_constructor</span><span class="special">().</span><span class="identifier">valid</span><span class="special">()</span> <span class="keyword">and</span>
+ <span class="identifier">r</span><span class="special">.</span><span class="identifier">get_function</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;(</span><span class="string">"print hello world"</span><span class="special">).</span><span class="identifier">valid</span><span class="special">())</span> <span class="special">{</span>
+
+ <span class="comment">// Get and call the constructor to create an instance.
+</span> <span class="identifier">instance</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">get_constructor</span><span class="special">()();</span>
+
+ <span class="comment">// Get and call the function called "print hello world".
+</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">get_function</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;(</span><span class="string">"print hello world"</span><span class="special">)(</span><span class="identifier">i</span><span class="special">);</span>
+<span class="special">}</span> <span class="keyword">else</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special">&lt;&lt;</span> <span class="string">"Unable to find a required method."</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
 </div>
-<div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title">
-<a name="boost_reflection.tutorials.tutorial01"></a> Tutorial 1</h3></div></div></div></div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
 <td align="left"></td>
 <td align="right"><div class="copyright-footer">Copyright © 2007 -2008 Jeremy Pack, Mariano G. Consoni<p>
@@ -34,7 +110,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="../tutorials.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial02.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="../tutorials.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial03.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
 </div>
 </body>
 </html>

Modified: sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial03.html
==============================================================================
--- sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial03.html (original)
+++ sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial03.html 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -6,7 +6,7 @@
 <meta name="generator" content="DocBook XSL Stylesheets V1.67.2">
 <link rel="start" href="../../index.html" title="Chapter 1. Boost.Reflection 1.0">
 <link rel="up" href="../tutorials.html" title="Tutorials">
-<link rel="prev" href="tutorial02.html" title=" Tutorial 2">
+<link rel="prev" href="tutorial01.html" title=" Tutorial 1">
 <link rel="next" href="tutorial04.html" title=" Tutorial 4">
 </head>
 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -20,7 +20,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="tutorial02.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial04.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="tutorial01.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial04.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
 </div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h3 class="title">
@@ -39,7 +39,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="tutorial02.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial04.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="tutorial01.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial04.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
 </div>
 </body>
 </html>

Modified: sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial05.html
==============================================================================
--- sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial05.html (original)
+++ sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial05.html 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -7,7 +7,6 @@
 <link rel="start" href="../../index.html" title="Chapter 1. Boost.Reflection 1.0">
 <link rel="up" href="../tutorials.html" title="Tutorials">
 <link rel="prev" href="tutorial04.html" title=" Tutorial 4">
-<link rel="next" href="../performance_analysis.html" title=" Performance Analysis">
 </head>
 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
 <table cellpadding="2" width="100%"><tr>
@@ -20,7 +19,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="tutorial04.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../performance_analysis.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="tutorial04.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a>
 </div>
 <div class="section" lang="en">
 <div class="titlepage"><div><div><h3 class="title">
@@ -39,7 +38,7 @@
 </tr></table>
 <hr>
 <div class="spirit-nav">
-<a accesskey="p" href="tutorial04.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../performance_analysis.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="tutorial04.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorials.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a>
 </div>
 </body>
 </html>

Modified: sandbox/libs/reflection/doc/html/index.html
==============================================================================
--- sandbox/libs/reflection/doc/html/index.html (original)
+++ sandbox/libs/reflection/doc/html/index.html 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -38,24 +38,17 @@
 <dt><span class="section">Tutorials</span></dt>
 <dd><dl>
 <dt><span class="section"> Tutorial 1</span></dt>
-<dt><span class="section"> Tutorial 2</span></dt>
 <dt><span class="section"> Tutorial 3</span></dt>
 <dt><span class="section"> Tutorial 4</span></dt>
 <dt><span class="section"> Tutorial 5</span></dt>
 </dl></dd>
-<dt><span class="section"> Performance Analysis</span></dt>
-<dt><span class="section"> Appendices</span></dt>
-<dd><dl>
-<dt><span class="section"> Appendix A - Placeholder</span></dt>
-<dt><span class="section"> Appendix B - Placeholder</span></dt>
-<dt><span class="section"> Appendix C - Placeholder</span></dt>
-</dl></dd>
 </dl>
 </div>
+<pre class="programlisting">
+<span class="special">]</span>
+</pre>
 <p>
- Note: Only the Boost.Extension interoperability section of the documentation
- is currently complete. However, it should show enough to begin basic usage of
- the library.
+ ] ]
   </p>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>

Modified: sandbox/libs/reflection/doc/html/standalone_HTML.manifest
==============================================================================
--- sandbox/libs/reflection/doc/html/standalone_HTML.manifest (original)
+++ sandbox/libs/reflection/doc/html/standalone_HTML.manifest 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -3,12 +3,6 @@
 boost_reflection/extension.html
 boost_reflection/tutorials.html
 boost_reflection/tutorials/tutorial01.html
-boost_reflection/tutorials/tutorial02.html
 boost_reflection/tutorials/tutorial03.html
 boost_reflection/tutorials/tutorial04.html
 boost_reflection/tutorials/tutorial05.html
-boost_reflection/performance_analysis.html
-boost_reflection/appendices.html
-boost_reflection/appendices/appendix_a.html
-boost_reflection/appendices/appendix_b.html
-boost_reflection/appendices/appendix_c.html

Modified: sandbox/libs/reflection/doc/introduction.qbk
==============================================================================
--- sandbox/libs/reflection/doc/introduction.qbk (original)
+++ sandbox/libs/reflection/doc/introduction.qbk 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -7,4 +7,20 @@
 
 [section:introduction Introduction]
 
+The goal of this library is to provide runtime reflection for C++ classes, and to allow the
+same across shared library boundaries. It is an offshoot of the Extension library, which
+provides dynamic class loading across shared libraries. [link extension Extension Interoperability]
+provides an example of using these libraries together.
+
+Boost.Reflection does not provide automatic reflection of classes. Instead, the class data must
+be manually reflected. This does offer some benefits however:
+
+* This can result in better performance, since only the necessary functions are reflected.
+* Arbitrary classes can be reflected without modification.
+* It is possible to make a reflected interface that is quite different from the original interface.
+
+This library is currently in development in preparation for a review for inclusion in the
+Boost C++ Libraries. For ongoing status updates, check
+[@http://boost-extension.blogspot.com/ C++ Plugins and Reflection].
+
 [endsect]

Modified: sandbox/libs/reflection/doc/reflection.qbk
==============================================================================
--- sandbox/libs/reflection/doc/reflection.qbk (original)
+++ sandbox/libs/reflection/doc/reflection.qbk 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -18,11 +18,9 @@
     [category Programming Interfaces]
     [last-revision $Date: 2008/2/9 18:05:00 $]
 ]
-Note: Only the Boost.Extension interoperability section
-of the documentation is currently complete. However,
-it should show enough to begin basic usage of the library.
 [include introduction.qbk]
 [include extension.qbk]
 [include tutorials.qbk]
-[include performance_analysis.qbk]
-[include appendices.qbk]
+[/ [include performance_analysis.qbk] ]
+[/ [include appendices.qbk] ]
+

Modified: sandbox/libs/reflection/doc/tutorial1.qbk
==============================================================================
--- sandbox/libs/reflection/doc/tutorial1.qbk (original)
+++ sandbox/libs/reflection/doc/tutorial1.qbk 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -7,4 +7,66 @@
 
 
 [section:tutorial01 Tutorial 1]
+
+The source code for this tutorial can be found in examples/tutorial_1/.
+
+The `reflection` class can hold information about a reflected class. For this example,
+begin by creating a class that we can reflect:
+``
+class HelloWorld {
+public:
+ void printHelloWorld() {
+ std::cout << "Hello World!" << std::endl;
+ }
+};
+``
+Reflected classes do not need to have any special markup - any normal class can be reflected.
+Now create a function to reflect out information about this class:
+``
+reflection GetReflection() {
+ // This reflection will be returned
+ reflection r;
+
+ // Use a reflector<HelloWorld> which will only reflect out constructors
+ // and functions for the HelloWorld class.
+ reflector<HelloWorld> current_reflector(&r);
+
+ // Reflect an argless constructor
+ // To reflect a constructor that takes a "const string&" and an int,
+ // call current_reflector.reflect_constructor<const string&, int>().
+ current_reflector.reflect_constructor();
+
+ // Reflect a member function returning void and having no parameters.
+ // To reflect a member returning a float and taking a single int as
+ // an argument, use: current_reflector.reflect<float, int>().
+ current_reflector.reflect<void>(&HelloWorld::printHelloWorld,
+ "print hello world");
+ return r;
+}
+``
+Now, somewhere else in the program, it is possible to use this function to get a generic
+reflection instance, which can be used to instantiate the class and call its reflected
+function.
+
+``
+reflection r = GetReflection();
+
+// Make sure this class supports a default constructor, and a function
+// identified as "print hello world" that has a void return value and
+// takes no arguments. If we wanted a constructor that took one int argument,
+// the call would become r.has_constructor<int>(). If we wanted a function
+// that took two float arguments, and returned a double, the call would be
+// r.has_function<void, float, float>("print hello world").
+if (r.get_constructor().valid() and
+ r.get_function<void>("print hello world").valid()) {
+
+ // Get and call the constructor to create an instance.
+ instance i = r.get_constructor()();
+
+ // Get and call the function called "print hello world".
+ r.get_function<void>("print hello world")(i);
+} else {
+ std::cerr << "Unable to find a required method.";
+}
+``
 [endsect]
\ No newline at end of file

Modified: sandbox/libs/reflection/doc/tutorials.qbk
==============================================================================
--- sandbox/libs/reflection/doc/tutorials.qbk (original)
+++ sandbox/libs/reflection/doc/tutorials.qbk 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -7,11 +7,12 @@
 
 [section Tutorials]
 [include tutorial1.qbk]
+[/
 [include tutorial2.qbk]
 [include tutorial3.qbk]
 [include tutorial4.qbk]
 [include tutorial5.qbk]
+]
 
-These are placeholders.
 
 [endsect]
\ No newline at end of file

Modified: sandbox/libs/reflection/examples/Jamfile.v2
==============================================================================
--- sandbox/libs/reflection/examples/Jamfile.v2 (original)
+++ sandbox/libs/reflection/examples/Jamfile.v2 2008-02-12 22:06:04 EST (Tue, 12 Feb 2008)
@@ -19,7 +19,6 @@
     : requirements
       <include>../../../
       <include>$(BOOST_ROOT)
- <include>../../../../src/sandbox/
       <toolset>gcc:<find-shared-library>dl
       <toolset>gcc:<linkflags>"-Wl,-rpath,'$ORIGIN'"
       <toolset>darwin:<define>DYLD_LIBRARY_PATH=./
@@ -31,3 +30,6 @@
 lib car_lib : extension/car_lib.cpp : <link>shared ;
 
 install ../test/ : car_lib extension-reflection ;
+
+# Tutorial 1: Hello World
+exe hello_world : tutorial_1/hello_world.cpp ;


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