Boost logo

Boost-Commit :

From: oryol_at_[hidden]
Date: 2007-09-16 00:09:46


Author: jeremypack
Date: 2007-09-16 00:09:45 EDT (Sun, 16 Sep 2007)
New Revision: 39306
URL: http://svn.boost.org/trac/boost/changeset/39306

Log:
Fixed syntax for shared library reflection example.

Text files modified:
   sandbox/libs/reflection/examples/extension/extension.cpp | 41 +++++++++++++++++++++++++++++----------
   1 files changed, 30 insertions(+), 11 deletions(-)

Modified: sandbox/libs/reflection/examples/extension/extension.cpp
==============================================================================
--- sandbox/libs/reflection/examples/extension/extension.cpp (original)
+++ sandbox/libs/reflection/examples/extension/extension.cpp 2007-09-16 00:09:45 EDT (Sun, 16 Sep 2007)
@@ -18,28 +18,47 @@
 #include <boost/reflection/reflection.hpp>
 #include <iostream>
 
+#if defined(MSC_VER) || defined(WIN32)
+#define BOOST_EXTENSION_DIR_START "..\bin\"
+#else
+#define BOOST_EXTENSION_DIR_START "../bin/"
+#endif
+
 int main(void)
 {
   
   std::map<std::string, boost::reflections::reflection> reflection_map;
- boost::extensions::shared_library lib("libCarLib.extension");
+ boost::extensions::shared_library lib
+ ((std::string(BOOST_EXTENSION_DIR_START) + "libcar_lib.extension").c_str());
   lib.open();
   lib.get<void, std::map<std::string,
     boost::reflections::reflection> &>
     ("extension_export_car")(reflection_map);
+ if (reflection_map.size() != size_t(2)) {
+ std::cout << "Could not load reflections!";
+ return 1;
+ }
   // Let's create the reflection and add the methods
   boost::reflections::reflection & first_reflection =
     reflection_map["suv"];
   boost::reflections::reflection & second_reflection =
     reflection_map["compact"];
- boost::reflections::instance first_instance =
- first_reflection.get_constructor<const char *>()("First Instance");
- boost::reflections::instance second_instance =
- second_reflection.get_constructor<const char *>()("Second Instance");
- std::cout <<
- first_reflection.get_function<const char *>("get_type")(first_instance)
- << std::endl;
- std::cout <<
- second_reflection.get_function<const char *>("get_type")(second_instance)
- << std::endl;
+
+ boost::reflections::constructor<const char *> first_constructor =
+ first_reflection.get_constructor<const char *>();
+ boost::reflections::instance first_instance =
+ first_constructor("First 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;
+
+ boost::reflections::constructor<const char *> second_constructor =
+ second_reflection.get_constructor<const char *>();
+ boost::reflections::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;
 }


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