Boost logo

Boost-Commit :

From: oryol_at_[hidden]
Date: 2008-02-08 23:43:47


Author: jeremypack
Date: 2008-02-08 23:43:46 EST (Fri, 08 Feb 2008)
New Revision: 43181
URL: http://svn.boost.org/trac/boost/changeset/43181

Log:
Addition of new files for reflection headers

Added:
   sandbox/boost/reflection/common.hpp (contents, props changed)
   sandbox/boost/reflection/impl/
   sandbox/boost/reflection/impl/typeinfo.hpp (contents, props changed)
Text files modified:
   sandbox/boost/reflection/parameter_map.hpp | 68 +++++++++++++++++++++++++++++++++++----
   1 files changed, 60 insertions(+), 8 deletions(-)

Added: sandbox/boost/reflection/common.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/reflection/common.hpp 2008-02-08 23:43:46 EST (Fri, 08 Feb 2008)
@@ -0,0 +1,25 @@
+/*
+ * Boost.Reflection / common:
+ * common include files
+ *
+ * (C) 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.
+ */
+
+#ifndef BOOST_REFLECTION_COMMON_HPP
+#define BOOST_REFLECTION_COMMON_HPP
+
+#include <boost/preprocessor/arithmetic/inc.hpp>
+#include <boost/preprocessor/if.hpp>
+#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <boost/preprocessor/repetition.hpp>
+
+#ifndef BOOST_REFLECTION_MAX_FUNCTOR_PARAMS
+#define BOOST_REFLECTION_MAX_FUNCTOR_PARAMS 6
+#endif // BOOST_REFLECTION_MAX_FUNCTOR_PARAMS
+
+#endif // BOOST_REFLECTION_COMMON_HPP

Added: sandbox/boost/reflection/impl/typeinfo.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/reflection/impl/typeinfo.hpp 2008-02-08 23:43:46 EST (Fri, 08 Feb 2008)
@@ -0,0 +1,78 @@
+/*
+ * Boost.Reflection / typeinfo:
+ * implementations name management with RTTI
+ *
+ * (C) 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.
+ */
+
+
+#ifndef BOOST_REFLECTION_TYPEINFO_HPP
+#define BOOST_REFLECTION_TYPEINFO_HPP
+namespace boost{namespace reflections{
+template <class TypeInfo, class ClassType>
+struct type_info_handler
+{
+ static TypeInfo get_class_type();
+};
+}}
+#ifndef BOOST_REFLECTION_USER_TYPE_INFO_CUSTOM
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+ // For DLLs
+# define BOOST_REFLECTION_EXTERNAL extern "C" __declspec(dllexport)
+#include <string>
+#include <typeinfo>
+namespace boost{namespace reflections{
+ typedef std::string default_type_info;
+ template <class ClassType>
+ struct type_info_handler<default_type_info, ClassType>
+ {
+ static default_type_info get_class_type(){return typeid(ClassType).name();}
+ };
+}}
+
+#else
+#ifdef __APPLE__
+#include <typeinfo>
+#include <string>
+/*namespace boost{namespace reflections{
+ typedef basic_factory_map<std::type_info> factory_map;
+ template <>
+ std::type_info basic_factory_map<std::string>::get_class_type()
+ {
+ return typeid(ClassType);
+ }
+}}*/
+namespace boost{namespace reflections{
+ typedef std::string default_type_info;
+ template <class ClassType>
+ struct type_info_handler<default_type_info, ClassType>
+ {
+ static default_type_info get_class_type(){return typeid(ClassType).name();}
+ };
+}}
+
+#else
+#include <string>
+#include <typeinfo>
+namespace boost{namespace reflections{
+ typedef std::string default_type_info;
+ template <class ClassType>
+ struct type_info_handler<default_type_info, ClassType>
+ {
+ static default_type_info get_class_type(){return typeid(ClassType).name();}
+ };
+}}
+
+#endif //Apple
+#endif //Windows
+#endif // BOOST_REFLECTION_USER_TYPE_INFO_CUSTOM
+#ifndef BOOST_REFLECTION_EXTERNAL
+# define BOOST_REFLECTION_EXTERNAL extern "C"
+#endif
+
+#endif

Modified: sandbox/boost/reflection/parameter_map.hpp
==============================================================================
--- sandbox/boost/reflection/parameter_map.hpp (original)
+++ sandbox/boost/reflection/parameter_map.hpp 2008-02-08 23:43:46 EST (Fri, 08 Feb 2008)
@@ -13,22 +13,62 @@
 #ifndef BOOST_REFLECTION_PARAMETER_MAP_HPP
 #define BOOST_REFLECTION_PARAMETER_MAP_HPP
 #include <boost/reflection/typeinfo.hpp>
+#include <exception>
 #include <multimap>
 #include <vector>
 namespace boost { namespace reflections {
-
+class param_not_found_exception : public std::exception {
+public:
+ virtual const char* what() {
+ return "Cannot convert types";
+ }
+};
 typedef void (*FunctionPtr)();
 template <class TypeInfo>
 class generic_parameter {
 public:
   virtual ~basic_parameter() {}
   virtual TypeInfo type() = 0;
+ template <class T>
+ bool can_cast() {
+ type_info i = type_info_handler<TypeInfo, T>::get_class_type();
+ for (vector_type::const_iterator it = converter_.begin();
+ it != converters_.end(); ++it) {
+ if (it->first == i)
+ return true;
+ }
+ }
+ template <class T>
+ T* cast() {
+ type_info i = type_info_handler<TypeInfo, T>::get_class_type();
+ for (vector_type::const_iterator it = converter_.begin();
+ it != converters_.end(); ++it) {
+ if (it->first == i)
+ return true;
+ }
+ }
+ tempate <class T>
+ T cast() {
+ type_info i = type_info_handler<TypeInfo, T>::get_class_type();
+ for (vector_type::const_iterator it = converter_.begin();
+ it != converters_.end(); ++it) {
+ if (it->first == i) {
+ T ret;
+ cast_and_store(it, &ret);
+ }
+ }
+ throw param_not_found_exception();
+ }
+protected
+ void cast_and_store(vector_type::iterator it, void* dest);
+private:
+ typedef std::vector<std::pair<TypeInfo, FunctionPtr> > vector_type;
+ vector_type converters_;
 };
 
 template <class S, class T>
-S convert(generic_parameter param) {
- T val =
- return static_cast<S>(val);
+S convert(T val) {
+ return static_cast<S>(T);
 }
 
 
@@ -38,16 +78,26 @@
 public:
   template <class A, B, C>
   friend class parameter_map;
- parameter(T value) : value_(value) {}
+
+ parameter(T value) : value_(value) {
+ // Add converter for current type.
+ converters_.push_back
+ (make_pair(reflections::type_info_handler<TypeInfo, T>::get_class_type(),
+ reinterpret_cast<FunctionPtr>(&convert<T, T&>)));
+ }
   template <class S>
   void converts_to(S (*convert_func)(T) = &convert<S, T>) {
     converters_.push_back
       (make_pair(reflections::type_info_handler<TypeInfo, S>::get_class_type(),
                  reinterpret_cast<FunctionPtr>(convert_func)));
   }
+ template <class S>
+ void ref_converts_to(S (*convert_func)(T&) = &convert<S, T>) {
+ converters_.push_back
+ (make_pair(reflections::type_info_handler<TypeInfo, S>::get_class_type(),
+ reinterpret_cast<FunctionPtr>(convert_func)));
+ }
 private:
- typedef std::vector<std::pair<TypeInfo, FunctionPtr> > vector_type;
- vector_type converters_;
   T value_;
 };
 
@@ -59,7 +109,7 @@
 };
 
 template <class Info = std::string,
- class TypeInfo = reflections::default_type_info>
+ class TypeInfo = default_type_info>
 class basic_parameter_map
   : public std::multimap<Info, basic_parameter*> {
 public:
@@ -89,6 +139,8 @@
  
 };
 typedef basic_paramter_map<> parameter_map;
+
+
 }}
 
 #endif // BOOST_REFLECTION_PARAMETER_MAP_HPP


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