Boost logo

Boost-Commit :

From: oryol_at_[hidden]
Date: 2008-05-02 18:27:19


Author: jeremypack
Date: 2008-05-02 18:27:18 EDT (Fri, 02 May 2008)
New Revision: 45045
URL: http://svn.boost.org/trac/boost/changeset/45045

Log:
Fixes for data member handling in reflections,
as well as minor changes to shared library-related functionality.

Added:
   sandbox/boost/extension/impl/function.hpp (contents, props changed)
   sandbox/libs/reflection/examples/data_members.cpp (contents, props changed)
   sandbox/libs/reflection/test/data_test.cpp (contents, props changed)
Text files modified:
   sandbox/boost/extension/common.hpp | 2 +-
   sandbox/boost/reflection/common.hpp | 1 +
   sandbox/boost/reflection/data_info.hpp | 2 ++
   sandbox/libs/reflection/test/shared_library_test.cpp | 3 +--
   4 files changed, 5 insertions(+), 3 deletions(-)

Modified: sandbox/boost/extension/common.hpp
==============================================================================
--- sandbox/boost/extension/common.hpp (original)
+++ sandbox/boost/extension/common.hpp 2008-05-02 18:27:18 EDT (Fri, 02 May 2008)
@@ -18,7 +18,7 @@
 #include <boost/preprocessor/punctuation/comma_if.hpp>
 #include <boost/preprocessor/repetition.hpp>
 #include <boost/preprocessor/iteration/iterate.hpp>
-
+#include <boost/concept_check.hpp>
 #ifndef BOOST_EXTENSION_MAX_FUNCTOR_PARAMS
 #define BOOST_EXTENSION_MAX_FUNCTOR_PARAMS 10
 #endif

Added: sandbox/boost/extension/impl/function.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/extension/impl/function.hpp 2008-05-02 18:27:18 EDT (Fri, 02 May 2008)
@@ -0,0 +1,21 @@
+/*
+ * Copyright Jeremy Pack 2007
+ * 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)
+ *
+ * See http://www.boost.org/ for latest version.
+ * Note:
+ * The code to determine whether or not function type syntax
+ * is allowed in template declarations is based off of code
+ * written for Boost.Function.
+ */
+
+#include <boost/config.hpp>
+
+// The following is based on code from Boost.Function
+#if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
+ || defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) \
+ || !(BOOST_STRICT_CONFIG || !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540)
+# define BOOST_EXTENSION_NO_FUNCTION_TYPE_SYNTAX
+#endif

Modified: sandbox/boost/reflection/common.hpp
==============================================================================
--- sandbox/boost/reflection/common.hpp (original)
+++ sandbox/boost/reflection/common.hpp 2008-05-02 18:27:18 EDT (Fri, 02 May 2008)
@@ -17,6 +17,7 @@
 #include <boost/preprocessor/if.hpp>
 #include <boost/preprocessor/punctuation/comma_if.hpp>
 #include <boost/preprocessor/repetition.hpp>
+#include <boost/concept_check.hpp>
 
 #ifndef BOOST_REFLECTION_MAX_FUNCTOR_PARAMS
 #define BOOST_REFLECTION_MAX_FUNCTOR_PARAMS 10

Modified: sandbox/boost/reflection/data_info.hpp
==============================================================================
--- sandbox/boost/reflection/data_info.hpp (original)
+++ sandbox/boost/reflection/data_info.hpp 2008-05-02 18:27:18 EDT (Fri, 02 May 2008)
@@ -13,6 +13,7 @@
 #define BOOST_REFLECTION_DATA_INFO_HPP
 
 #include <vector>
+#include <boost/reflection/common.hpp>
 
 namespace boost {
 namespace reflections {
@@ -21,6 +22,7 @@
 // of data available for the current reflection.
 template<class Info, class TypeInfo>
 struct basic_data_info {
+ BOOST_CONCEPT_ASSERT((LessThanComparable<TypeInfo>));
   // The type of the function pointer in the map.
   TypeInfo type_info_;
   // A description of the function pointer.

Added: sandbox/libs/reflection/examples/data_members.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/reflection/examples/data_members.cpp 2008-05-02 18:27:18 EDT (Fri, 02 May 2008)
@@ -0,0 +1,53 @@
+/*
+ * Boost.Reflection / Data Members example - Tutorial 1
+ *
+ * (C) Copyright Jeremy Pack 2008
+ * 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)
+ *
+ * See http://www.boost.org/ for latest version.
+ */
+
+#include <iostream>
+
+#include <boost/reflection/reflection.hpp>
+
+using boost::reflections::reflection;
+using boost::reflections::instance;
+
+void get_reflection(reflection& r);
+
+int main(int argc, char ** argv) {
+ 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.";
+ }
+}
+
+struct data_holder {
+ std::string my_string;
+ int my_int;
+};
+
+void get_reflection(reflection& r) {
+ r.reflect<data_holder>()
+ .constructor()
+ .data(&HelloWorld::my_int, "my integer")
+ .data(&HelloWorld::my_string, "my string");
+}
\ No newline at end of file

Added: sandbox/libs/reflection/test/data_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/reflection/test/data_test.cpp 2008-05-02 18:27:18 EDT (Fri, 02 May 2008)
@@ -0,0 +1,53 @@
+/*
+ * Boost.Reflection / basic single parameter unit test
+ *
+ * (C) Copyright Jeremy Pack 2008
+ * 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)
+ *
+ * See http://www.boost.org/ for latest version.
+ */
+
+
+#include <string>
+#include <iostream>
+
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_DYN_LINK 1
+#include <boost/test/unit_test.hpp>
+
+#include <iostream>
+
+#include <boost/reflection/reflection.hpp>
+using namespace boost::reflections;
+
+struct data_holder {
+ std::string my_string;
+ int my_int;
+ std::string double_string() {
+ return my_string + my_string;
+ }
+};
+
+using namespace boost::reflections;
+
+BOOST_AUTO_TEST_CASE(argless)
+{
+ reflection r;
+ r.reflect<data_holder>()
+ .constructor()
+ .function(&data_holder::double_string, "double_string")
+ .data(&data_holder::my_string, "my string")
+ .data(&data_holder::my_int, "my integer");
+
+ instance i = r.get_constructor()();
+ data<std::string> d = r.get_data<std::string>("my string");
+ BOOST_CHECK(d.valid());
+ std::string& s = d(i);
+ BOOST_CHECK(s.empty());
+ s = "Hello!";
+ std::string result = r.get_function<std::string>("double_string")(i);
+ BOOST_CHECK_EQUAL(result,
+ std::string("Hello!Hello!"));
+}
\ No newline at end of file

Modified: sandbox/libs/reflection/test/shared_library_test.cpp
==============================================================================
--- sandbox/libs/reflection/test/shared_library_test.cpp (original)
+++ sandbox/libs/reflection/test/shared_library_test.cpp 2008-05-02 18:27:18 EDT (Fri, 02 May 2008)
@@ -30,8 +30,7 @@
   boost::extensions::shared_library lib
     ("libcar_lib.extension");
   BOOST_CHECK(lib.open());
- lib.get<void, std::map<std::string,
- boost::reflections::reflection> &>
+ lib.get<void, std::map<std::string, boost::reflections::reflection>&>
     ("extension_export_car")(reflection_map);
   BOOST_CHECK_EQUAL(reflection_map.size(), size_t(2));
   // Let's create the reflection and add the methods


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