|
Boost-Commit : |
From: oryol_at_[hidden]
Date: 2008-02-09 23:16:16
Author: jeremypack
Date: 2008-02-09 23:16:14 EST (Sat, 09 Feb 2008)
New Revision: 43202
URL: http://svn.boost.org/trac/boost/changeset/43202
Log:
Doc fixes
Text files modified:
sandbox/libs/extension/doc/extension.qbk | 2
sandbox/libs/reflection/doc/extension.qbk | 134 ++++++++++++++++++++++++++++++++++++++++
sandbox/libs/reflection/doc/html/boost_reflection/introduction.html | 6
sandbox/libs/reflection/doc/html/boost_reflection/tutorials.html | 6
sandbox/libs/reflection/doc/html/boost_reflection/tutorials/tutorial01.html | 9 --
sandbox/libs/reflection/doc/html/index.html | 6 +
sandbox/libs/reflection/doc/html/standalone_HTML.manifest | 1
sandbox/libs/reflection/doc/reflection.qbk | 5 +
sandbox/libs/reflection/doc/tutorial1.qbk | 3
sandbox/libs/reflection/examples/Jamfile.v2 | 6 -
sandbox/libs/reflection/examples/extension/car_lib.cpp | 14 +++
sandbox/libs/reflection/examples/extension/extension.cpp | 29 +++++++-
sandbox/libs/reflection/examples/main.cpp | 14 ---
13 files changed, 191 insertions(+), 44 deletions(-)
Modified: sandbox/libs/extension/doc/extension.qbk
==============================================================================
--- sandbox/libs/extension/doc/extension.qbk (original)
+++ sandbox/libs/extension/doc/extension.qbk 2008-02-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -1,5 +1,5 @@
[/ Boost.Extension - main doc ]
-[/ Copyright 2007 Jeremy Pack ]
+[/ Copyright 2007-2008 Jeremy Pack and Mariano Consoni ]
[/ 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) ]
Modified: sandbox/libs/reflection/doc/extension.qbk
==============================================================================
--- sandbox/libs/reflection/doc/extension.qbk (original)
+++ sandbox/libs/reflection/doc/extension.qbk 2008-02-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -6,5 +6,139 @@
[/ See http://www.boost.org/ for latest version. ]
[section:extension Boost.Extension Interoperability]
+Reflections are designed to work with Boost.Extension, or with
+shared libraries in general. A simple example is included in
+examples/extension/.
+Declaring the reflected class itself is similar to the
+process for doing the same in Boost.Extension.
+
+Here's how the Jamfile for these libraries is defined. Note
+that, like in Boost.Extension, one can rename the shared library
+extensions, for consistency across platforms. Here, we use the
+.reflection suffix for each shared library.
+``
+import type : change-generated-target-suffix ;
+import type : change-generated-target-prefix ;
+type.change-generated-target-suffix SHARED_LIB : : reflection ;
+type.change-generated-target-prefix SHARED_LIB : : lib ;
+exe extension-reflection : extension/extension.cpp ;
+lib car_lib : extension/car_lib.cpp : <link>shared ;
+``
+
+The code in the shared library is defined in car_lib.cpp.
+
+We define two classes to export as reflections.
+Although both of these classes are derived from a common
+base, this is certainly not necessary. If we were using
+Boost.Extension factories, this would be required.
+``
+class suv : public car
+{
+public:
+ suv(const char * name) : car(name) {}
+ virtual const char * get_type(void) { return "It's an SUV."; }
+ virtual ~suv(void) {}
+};
+
+class compact : public car
+{
+public:
+ compact(const char * name) : car(name) {}
+ virtual const char * get_type(void) { return "It's a compact."; }
+ virtual ~compact(void) {}
+};
+``
+
+Just like Boost.Extension, an external function needs to be
+defined that will be called by the main module.
+
+extern "C"
+void BOOST_EXTENSION_EXPORT_DECL
+extension_export_car(std::map<std::string, reflection> reflection_map) {
+ reflection & first = reflection_map["suv"];
+ reflection & second = reflection_map["compact"];
+
+ // Create a reflector for each type that is being reflected.
+ reflector<suv> suv_reflector(&first);
+ reflector<compact> compact_reflector(&second);
+
+ // Reflect the constructor with a `const char*` arg
+ suv_reflector.reflect_constructor<const char *>();
+ compact_reflector.reflect_constructor<const char *>();
+
+ // Reflect a function for each
+ suv_reflector.reflect<const char *>(&suv::get_type, "get_type");
+ compact_reflector.reflect<const char *>(&compact::get_type, "get_type");
+}
+
+This is all that is necessary to export one constructor and one
+function for each class.
+
+Now, in extension.cpp, we combine Boost.Extension and
+Boost.Reflection code to load and use the reflections declared
+in the shared library.
+
+Create a mapping of reflections to strings that
+will be populated inside the shared library.
+``
+std::map<std::string, reflection> reflection_map;
+``
+Load the shared library using Boost.Extension.
+``
+boost::extensions::shared_library lib
+ ((std::string(BOOST_EXTENSION_DIR_START) +
+ "libcar_lib.extension").c_str());
+lib.open();
+``
+Call an exported function to populate
+reflection_map.
+``
+lib.get<void, std::map<std::string,
+ reflection> &>
+ ("extension_export_car")(reflection_map);
+if (reflection_map.size() != size_t(2)) {
+ std::cout << "Could not load reflections!";
+ return 1;
+}
+``
+Pull out two reflections that were named "suv" and
+"compact" respectively.
+``
+reflection & first_reflection =
+ reflection_map["suv"];
+reflection & second_reflection =
+ reflection_map["compact"];
+``
+Use the get_constructor function to find a constructor
+that takes one argument, a const char*.
+``
+instance_constructor<const char *> first_constructor =
+ first_reflection.get_constructor<const char *>();
+``
+Use the constructor retrieved to create an instance.
+Warning! instances should only be used with functions
+and constructors generated by a single reflection object.
+``
+instance first_instance =
+ first_constructor("First Instance");
+``
+Get a function to call on this instance.
+``
+boost::reflections::function<const char *> first_function =
+ first_reflection.get_function<const char *>("get_type");
+std::cout << "First reflection: " << first_function(first_instance)
+ << std::endl;
+ ``
+Repeat the steps for the second reflection.
+``
+instance_constructor<const char *> second_constructor =
+ second_reflection.get_constructor<const char *>();
+instance second_instance =
+ second_constructor("Second Instance");
+boost::reflections::function<const char *> second_function =
+ second_reflection.get_function<const char *>("get_type");
+std::cout << "Second reflection: " << second_function(second_instance)
+ << std::endl;
+``
[endsect]
\ No newline at end of file
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-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -7,7 +7,7 @@
<link rel="start" href="../index.html" title="Chapter 1. Boost.Reflection 1.0">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Reflection 1.0">
<link rel="prev" href="../index.html" title="Chapter 1. Boost.Reflection 1.0">
-<link rel="next" href="tutorials.html" title="Tutorials">
+<link rel="next" href="extension.html" title=" Boost.Extension Interoperability">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -20,7 +20,7 @@
</tr></table>
<hr>
<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="tutorials.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+<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>
@@ -34,7 +34,7 @@
</tr></table>
<hr>
<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="tutorials.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+<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>
</body>
</html>
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-09 23:16:14 EST (Sat, 09 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="../index.html" title="Chapter 1. Boost.Reflection 1.0">
-<link rel="prev" href="introduction.html" title=" Introduction">
+<link rel="prev" href="extension.html" title=" Boost.Extension Interoperability">
<link rel="next" href="tutorials/tutorial01.html" title=" Tutorial 1">
</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="introduction.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="tutorials/tutorial01.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="extension.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="tutorials/tutorial01.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">
@@ -46,7 +46,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="introduction.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="tutorials/tutorial01.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="extension.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="tutorials/tutorial01.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
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-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -22,13 +22,8 @@
<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>
</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>
- This is a placeholder.
- </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>
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-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -34,6 +34,7 @@
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="section"> Introduction</span></dt>
+<dt><span class="section"> Boost.Extension Interoperability</span></dt>
<dt><span class="section">Tutorials</span></dt>
<dd><dl>
<dt><span class="section"> Tutorial 1</span></dt>
@@ -51,6 +52,11 @@
</dl></dd>
</dl>
</div>
+<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>
<td align="left"><p><small>Last revised: February 9, 2008 at 18:05:00 GMT</small></p></td>
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-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -1,5 +1,6 @@
index.html
boost_reflection/introduction.html
+boost_reflection/extension.html
boost_reflection/tutorials.html
boost_reflection/tutorials/tutorial01.html
boost_reflection/tutorials/tutorial02.html
Modified: sandbox/libs/reflection/doc/reflection.qbk
==============================================================================
--- sandbox/libs/reflection/doc/reflection.qbk (original)
+++ sandbox/libs/reflection/doc/reflection.qbk 2008-02-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -18,8 +18,11 @@
[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]
Modified: sandbox/libs/reflection/doc/tutorial1.qbk
==============================================================================
--- sandbox/libs/reflection/doc/tutorial1.qbk (original)
+++ sandbox/libs/reflection/doc/tutorial1.qbk 2008-02-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -7,7 +7,4 @@
[section:tutorial01 Tutorial 1]
-
-This is a placeholder.
-
[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-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -26,12 +26,6 @@
:
;
-# basic example
-# exe reflection : main.cpp ;
-
-# interpreter prototype
-# exe interpreter : interpreter/interpreter.cpp ;
-
# extension integration example
exe extension-reflection : extension/extension.cpp ;
lib car_lib : extension/car_lib.cpp : <link>shared ;
Modified: sandbox/libs/reflection/examples/extension/car_lib.cpp
==============================================================================
--- sandbox/libs/reflection/examples/extension/car_lib.cpp (original)
+++ sandbox/libs/reflection/examples/extension/car_lib.cpp 2008-02-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -14,6 +14,10 @@
#include <boost/reflection/reflection.hpp>
#include <boost/reflection/reflector.hpp>
using namespace boost::reflections;
+
+// Although both of these classes are derived from a common
+// base, this is certainly not necessary. If we were using
+// Boost.Extension factories, this would be required.
class suv : public car
{
public:
@@ -32,16 +36,20 @@
extern "C"
-void BOOST_EXTENSION_EXPORT_DECL
+void BOOST_EXTENSION_EXPORT_DECL
extension_export_car(std::map<std::string, reflection> reflection_map) {
reflection & first = reflection_map["suv"];
reflection & second = reflection_map["compact"];
+
+ // Create a reflector for each type that is being reflected.
reflector<suv> suv_reflector(&first);
reflector<compact> compact_reflector(&second);
-
+
+ // Reflect the constructor with a `const char*` arg
suv_reflector.reflect_constructor<const char *>();
compact_reflector.reflect_constructor<const char *>();
-
+
+ // Reflect a function for each
suv_reflector.reflect<const char *>(&suv::get_type, "get_type");
compact_reflector.reflect<const char *>(&compact::get_type, "get_type");
}
Modified: sandbox/libs/reflection/examples/extension/extension.cpp
==============================================================================
--- sandbox/libs/reflection/examples/extension/extension.cpp (original)
+++ sandbox/libs/reflection/examples/extension/extension.cpp 2008-02-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -19,6 +19,8 @@
#include <boost/reflection/reflector.hpp>
#include <iostream>
+// Define directory locations for cross platform
+// directory traversal.
#if defined(MSC_VER) || defined(WIN32)
#define BOOST_EXTENSION_DIR_START "..\\bin\\"
#else
@@ -31,10 +33,18 @@
using boost::reflections::instance_constructor;
using boost::reflections::reflection;
+ // Create a mapping of reflections to strings that
+ // will be populated inside the shared library.
std::map<std::string, reflection> reflection_map;
+
+ // Load the shared library using Boost.Extension
boost::extensions::shared_library lib
- ((std::string(BOOST_EXTENSION_DIR_START) + "libcar_lib.extension").c_str());
+ ((std::string(BOOST_EXTENSION_DIR_START) +
+ "libcar_lib.extension").c_str());
lib.open();
+
+ // Call an exported function to populate
+ // reflection_map
lib.get<void, std::map<std::string,
reflection> &>
("extension_export_car")(reflection_map);
@@ -42,21 +52,32 @@
std::cout << "Could not load reflections!";
return 1;
}
- // Let's create the reflection and add the methods
+
+ // Pull out two reflections that were named "suv" and
+ // "compact" respectively.
reflection & first_reflection =
reflection_map["suv"];
reflection & second_reflection =
reflection_map["compact"];
-
+
+ // Use the get_constructor function to find a constructor
+ // that takes one argument, a const char*.
instance_constructor<const char *> first_constructor =
first_reflection.get_constructor<const char *>();
+
+ // Use the constructor retrieved to create an instance.
+ // Warning! instances should only be used with functions
+ // and constructors generated by a single reflection object.
instance first_instance =
first_constructor("First Instance");
+
+ // Get a function to call on this instance.
boost::reflections::function<const char *> first_function =
first_reflection.get_function<const char *>("get_type");
std::cout << "First reflection: " << first_function(first_instance)
<< std::endl;
-
+
+ // Repeat the steps for the second reflection.
instance_constructor<const char *> second_constructor =
second_reflection.get_constructor<const char *>();
instance second_instance =
Modified: sandbox/libs/reflection/examples/main.cpp
==============================================================================
--- sandbox/libs/reflection/examples/main.cpp (original)
+++ sandbox/libs/reflection/examples/main.cpp 2008-02-09 23:16:14 EST (Sat, 09 Feb 2008)
@@ -10,15 +10,8 @@
*/
-#include <string>
-
-#include <boost/extension/factory_map.hpp>
-#include <boost/extension/shared_library.hpp>
-#include <boost/extension/convenience.hpp>
-
#include <iostream>
-
-#define BOOST_EXTENSION_USE_PP 1
+#include <string>
#include "car.hpp"
#include <boost/reflection/reflection.hpp>
@@ -54,10 +47,5 @@
car_reflection.call<std::string, bool,
float, std::string>(&ferrari_f40, "turn", .10f);
- // prepare the parameter map for a call
- boost::extension::parameter_map pm;
- pm.add<float, std::string>(.15f, "turn_angle");
- pm.add<int, std::string>(50, "aceleration");
-
return 0;
}
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