Boost logo

Boost-Commit :

From: oryol_at_[hidden]
Date: 2008-04-12 11:47:05


Author: jeremypack
Date: 2008-04-12 11:47:05 EDT (Sat, 12 Apr 2008)
New Revision: 44345
URL: http://svn.boost.org/trac/boost/changeset/44345

Log:
Various fixes - especially for the parameter_map.

Text files modified:
   sandbox/boost/extension/shared_library.hpp | 6 +-
   sandbox/boost/reflection/parameter_map.hpp | 22 +++++++----
   sandbox/libs/extension/examples/hello_world.cpp | 2
   sandbox/libs/extension/examples/main.cpp | 2
   sandbox/libs/reflection/test/parameter_map_test.cpp | 74 +++++++++++++++++++++++++++++++++++++++
   sandbox/libs/reflection/test/shared_library_test.cpp | 2
   6 files changed, 93 insertions(+), 15 deletions(-)

Modified: sandbox/boost/extension/shared_library.hpp
==============================================================================
--- sandbox/boost/extension/shared_library.hpp (original)
+++ sandbox/boost/extension/shared_library.hpp 2008-04-12 11:47:05 EDT (Sat, 12 Apr 2008)
@@ -20,9 +20,9 @@
 #define BOOST_EXTENSION_SHARED_LIBRARY_GET_FUNCTION(Z, N, _) \
 template <class ReturnValue BOOST_PP_COMMA_IF(N) \
           BOOST_PP_ENUM_PARAMS(N, class Param) > \
-ReturnValue (*get(const char * name))(BOOST_PP_ENUM_PARAMS(N, Param)) { \
+ReturnValue (*get(const std::string& name))(BOOST_PP_ENUM_PARAMS(N, Param)) { \
   return reinterpret_cast<ReturnValue (*)(BOOST_PP_ENUM_PARAMS(N, Param))> \
- (get_function(handle_, name)); \
+ (get_function(handle_, name.c_str())); \
 }
 
 
@@ -36,7 +36,7 @@
   bool close() {
     return close_shared_library(handle_);
   }
- shared_library(const char * location, bool auto_close = false)
+ shared_library(const std::string& location, bool auto_close = false)
   :location_(location), handle_(0), auto_close_(auto_close) {
   }
 

Modified: sandbox/boost/reflection/parameter_map.hpp
==============================================================================
--- sandbox/boost/reflection/parameter_map.hpp (original)
+++ sandbox/boost/reflection/parameter_map.hpp 2008-04-12 11:47:05 EDT (Sat, 12 Apr 2008)
@@ -51,15 +51,20 @@
     }
   }*/
   template <class S>
- void cast(S* dest) {
+ S cast() {
+ S dest;
     TypeInfo i = type_info_handler<TypeInfo, S>::get_class_type();
     typename std::map<TypeInfo, basic_converter*>::iterator it = converters_.find(i);
     if (it != converters_.end()) {
- it->second->convert(value_, reinterpret_cast<void*>(dest));
- return;
+ it->second->convert(value_, reinterpret_cast<void*>(&dest));
+ return dest;
     }
     throw conversion_not_found_exception();
   }
+ template <class S>
+ void cast(S* dest) {
+ *dest = cast<S>();
+ }
 protected:
   generic_parameter(void* value) : value_(value) {
   }
@@ -95,13 +100,13 @@
   template <class S>
   void converts_to_with_func(void (*convert_func)(T*, S*)) {
     generic_parameter<TypeInfo>::converters_.insert
- (make_pair(reflections::type_info_handler<TypeInfo, S>::get_class_type(),
+ (std::make_pair(reflections::type_info_handler<TypeInfo, S>::get_class_type(),
                  new specialized_converter<S>(convert_func)));
   }
   template <class S>
   void converts_to() {
- generic_parameter<TypeInfo>::converters_.push_back
- (make_pair(reflections::type_info_handler<TypeInfo, S>::get_class_type(),
+ generic_parameter<TypeInfo>::converters_.insert
+ (std::make_pair(reflections::type_info_handler<TypeInfo, S>::get_class_type(),
                  new default_converter<S>()));
   }
 private:
@@ -120,7 +125,7 @@
     specialized_converter(void (*convert_function)(T*, S*))
       : convert_function_(convert_function) {
     }
- virtual void convert(TypeInfo type_info, T* val, void* dest) {
+ virtual void convert(void* val, void* dest) {
       S* s = reinterpret_cast<S*>(dest);
       (*convert_function_)(reinterpret_cast<T*>(val), s);
     }
@@ -139,7 +144,7 @@
 
 template <class Info = std::string,
           class TypeInfo = extensions::default_type_info>
-class basic_parameter_map
+class basic_parameter_map
   : public std::multimap<Info, generic_parameter<TypeInfo>*> {
 public:
   ~basic_parameter_map() {
@@ -151,6 +156,7 @@
   using map_type::equal_range;
   using map_type::begin;
   using map_type::end;
+ using map_type::insert;
   template <class D>
   std::vector<generic_parameter<TypeInfo>*> get(Info info) {
     std::vector<generic_parameter<TypeInfo>*> parameters;

Modified: sandbox/libs/extension/examples/hello_world.cpp
==============================================================================
--- sandbox/libs/extension/examples/hello_world.cpp (original)
+++ sandbox/libs/extension/examples/hello_world.cpp 2008-04-12 11:47:05 EDT (Sat, 12 Apr 2008)
@@ -1,7 +1,7 @@
 /*
  * Boost.Extension / hello world implementations
  *
- * (C) Copyright Jeremy Pack 2007
+ * (C) Copyright Jeremy Pack 2007-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)

Modified: sandbox/libs/extension/examples/main.cpp
==============================================================================
--- sandbox/libs/extension/examples/main.cpp (original)
+++ sandbox/libs/extension/examples/main.cpp 2008-04-12 11:47:05 EDT (Sat, 12 Apr 2008)
@@ -25,7 +25,7 @@
   load_single_library(fm, "libHelloWorldLib.extension",
                       "extension_export_word");
   // Get a reference to the list of constructors for words.
- std::map<int, factory<word> > & factory_list = fm.get<word, int>();
+ std::map<int, factory<word> > & factory_list = fm.get<word, int>();
   if (factory_list.size() < 2)
     std::cout << "Error - the classes were not found.";
   for (std::map<int, factory<word> >::iterator current_word =

Modified: sandbox/libs/reflection/test/parameter_map_test.cpp
==============================================================================
--- sandbox/libs/reflection/test/parameter_map_test.cpp (original)
+++ sandbox/libs/reflection/test/parameter_map_test.cpp 2008-04-12 11:47:05 EDT (Sat, 12 Apr 2008)
@@ -22,6 +22,78 @@
 using boost::reflections::generic_parameter;
 using boost::reflections::parameter;
 BOOST_AUTO_TEST_CASE(construction) {
- parameter<int> i_param(5);
+ parameter<int>* p = new parameter<int>(5);
   parameter_map m;
+ m.insert(std::make_pair("some_integer", p));
+}
+
+// Verify that the parameter map deletes it's elements
+// when it is done with them.
+class counted_creation {
+public:
+ counted_creation() {
+ ++total_objects;
+ }
+ counted_creation(const counted_creation& left) {
+ ++total_objects;
+ }
+ ~counted_creation() {
+ --total_objects;
+ }
+ static int total_objects;
+};
+int counted_creation::total_objects = 0;
+BOOST_AUTO_TEST_CASE(destroy_elements) {
+ {
+ parameter<counted_creation>* p =
+ new parameter<counted_creation>(counted_creation());
+ BOOST_CHECK_EQUAL(counted_creation::total_objects, 1);
+ parameter_map m;
+ m.insert(std::make_pair("some_integer", p));
+ BOOST_CHECK_EQUAL(counted_creation::total_objects, 1);
+ }
+ BOOST_CHECK_EQUAL(counted_creation::total_objects, 0);
+}
+
+BOOST_AUTO_TEST_CASE(float_convert) {
+ parameter<int>* p = new parameter<int>(5);
+ p->converts_to<float>();
+ p->converts_to<double>();
+ generic_parameter<>* g = p;
+
+ BOOST_CHECK(g->can_cast<float>());
+ BOOST_CHECK(g->can_cast<double>());
+ BOOST_CHECK(!g->can_cast<char>());
+ BOOST_CHECK(!g->can_cast<short>());
+
+ BOOST_CHECK_EQUAL(5.0f, g->cast<float>());
+ BOOST_CHECK_EQUAL(5.0, g->cast<double>());
+ BOOST_CHECK_EQUAL(5, g->cast<int>());
+ parameter_map m;
+ m.insert(std::make_pair("some_integer", p));
+}
+
+class base {
+};
+class derived : public base {
+};
+
+void silly_convert(derived** b, float* f) {
+ *f = 86;
+}
+
+BOOST_AUTO_TEST_CASE(ptr_convert) {
+ derived d;
+ parameter<derived*>* p = new parameter<derived*>(&d);
+ p->converts_to<base*>();
+ p->converts_to_with_func<float>(&silly_convert);
+ generic_parameter<>* g = p;
+
+ BOOST_CHECK(g->can_cast<float>());
+ BOOST_CHECK(g->can_cast<base*>());
+ BOOST_CHECK(g->can_cast<derived*>());
+ BOOST_CHECK(!g->can_cast<double>());
+
+ BOOST_CHECK_EQUAL(&d, g->cast<derived*>());
+ BOOST_CHECK_EQUAL(86, g->cast<float>());
 }
\ 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-04-12 11:47:05 EDT (Sat, 12 Apr 2008)
@@ -22,7 +22,7 @@
 #include <boost/extension/shared_library.hpp>
 #include <boost/extension/convenience.hpp>
 #include <boost/reflection/reflection.hpp>
-#include <iostream>
+#include <iostream>cd
 #include <boost/function.hpp>
 
 BOOST_AUTO_TEST_CASE(shared_library_basic_test) {


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