$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: oryol_at_[hidden]
Date: 2008-04-10 00:57:08
Author: jeremypack
Date: 2008-04-10 00:57:07 EDT (Thu, 10 Apr 2008)
New Revision: 44142
URL: http://svn.boost.org/trac/boost/changeset/44142
Log:
Break up reflection.hpp into smaller parts.
Also, clean it up to facilitate debugging. Switch to using PreProcessor file iteration.
Added:
   sandbox/boost/reflection/constructor_info.hpp   (contents, props changed)
   sandbox/boost/reflection/function_info.hpp   (contents, props changed)
   sandbox/boost/reflection/impl/
   sandbox/boost/reflection/impl/reflection.hpp   (contents, props changed)
Text files modified: 
   sandbox/boost/reflection/reflection.hpp |   159 +++++++++++++++------------------------ 
   1 files changed, 63 insertions(+), 96 deletions(-)
Added: sandbox/boost/reflection/constructor_info.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/reflection/constructor_info.hpp	2008-04-10 00:57:07 EDT (Thu, 10 Apr 2008)
@@ -0,0 +1,79 @@
+/*
+ * Boost.Reflection / main header
+ *
+ * (C) Copyright Mariano G. Consoni and 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_REFLECTION_HPP
+#define BOOST_REFLECTION_REFLECTION_HPP
+
+#include <vector>
+
+namespace boost {
+namespace reflections {
+
+// The basic_constructor_info class is used as a key in the map
+// of constructors available for the current reflection.
+// There are two types - those with ParameterInfo defined, and
+// those without.
+template<class TypeInfo, class ParameterInfo = void>
+struct basic_constructor_info {
+  // The type of the function pointer used to construct
+  // the object this constructor_info is for.
+  TypeInfo type_info_;
+
+  // A description for each parameter of the function.
+  // If ParameterInfo=void, this does not appear.
+  std::vector<ParameterInfo> parameter_info_;
+
+  // Constructors.
+  basic_constructor_info(TypeInfo t) : type_info_(t) {
+  }
+
+  basic_constructor_info(const basic_constructor_info & s) 
+    : type_info_(s.type_info_) {
+  }
+
+  basic_constructor_info & operator=(basic_constructor_info & s) {
+    type_info_ = s.type_info_;
+  }
+
+  // Less than operator - for maps.
+  friend inline bool operator<(const basic_constructor_info & t,
+                               const basic_constructor_info & s) {
+    return t.type_info_ < s.type_info_;
+  }
+};
+
+template<class TypeInfo>
+struct basic_constructor_info<TypeInfo> {
+  // The type of the function pointer used to construct
+  // the object this constructor_info is for.
+  TypeInfo type_info_;
+
+  // Constructors
+  basic_constructor_info(TypeInfo t) : type_info_(t) {
+  }
+
+  basic_constructor_info(const basic_constructor_info & s) 
+    : type_info_(s.type_info_) {
+  }
+
+  basic_constructor_info & operator=(basic_constructor_info & s) {
+    type_info_ = s.type_info_;
+  }
+
+  // Less than operator - for maps.
+  friend inline bool operator<(const basic_constructor_info & t,
+                               const basic_constructor_info & s) {
+    return t.type_info_ < s.type_info_;
+  }
+};
+}  // namespace reflections
+}  // namespace boost
+#endif // BOOST_REFLECTION_REFLECTION_HPP
Added: sandbox/boost/reflection/function_info.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/reflection/function_info.hpp	2008-04-10 00:57:07 EDT (Thu, 10 Apr 2008)
@@ -0,0 +1,89 @@
+/*
+ * Boost.Reflection / main header
+ *
+ * (C) Copyright Mariano G. Consoni and 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_REFLECTION_HPP
+#define BOOST_REFLECTION_REFLECTION_HPP
+
+#include <vector>
+
+namespace boost {
+namespace reflections {
+
+// The basic_function_info class is used as a key in the map
+// of functions available for the current reflection.
+// There are two types - those with ParameterInfo defined, and
+// those without.
+template<class Info, class TypeInfo, class ParameterInfo = void>
+struct basic_function_info {
+  // The type of the function pointer in the map.
+  TypeInfo type_info_;
+  // A description of the function pointer.
+  Info info_;
+
+  // A description for each parameter of the function.
+  // If ParameterInfo=void, this does not appear.
+  std::vector<ParameterInfo> parameter_info_;
+
+  // Constructors
+  basic_function_info(TypeInfo t, Info i) : type_info_(t), info_(i) {
+  }
+
+  basic_function_info(const basic_function_info & s) 
+    : type_info_(s.type_info_), info_(s.info_) {
+  }
+
+  basic_function_info & operator=(basic_function_info & s) {
+    type_info_ = s.type_info_;
+    info_ = s.info_;
+  }
+
+  // Less-than operator - for maps.
+  friend inline bool operator<(const basic_function_info & t,
+                               const basic_function_info & s) {
+    return t.type_info_ < s.type_info_ ||
+    (t.type_info_ == s.type_info_ &&
+     t.info_ < s.info_);
+  }
+};
+
+// Same as the above, but without ParameterInfo.
+template<class Info, class TypeInfo>
+struct basic_function_info<Info, TypeInfo> {
+  // The type of the function pointer in the map.
+  TypeInfo type_info_;
+  // A description of the function pointer.
+  Info info_;
+
+  // Constructors.
+  basic_function_info(TypeInfo t, Info i) : type_info_(t), info_(i) {
+  }
+
+  basic_function_info(const basic_function_info & s) 
+    : type_info_(s.type_info_), info_(s.info_) {
+  }
+
+  basic_function_info & operator=(basic_function_info & s) {
+    type_info_ = s.type_info_;
+    info_ = s.info_;
+  }
+
+  // Less-than operator - for maps.
+  friend inline bool operator<(const basic_function_info & t,
+                               const basic_function_info & s) {
+    return t.type_info_ < s.type_info_ ||
+    (t.type_info_ == s.type_info_ &&
+     t.info_ < s.info_);
+  }
+};
+
+}  // namespace reflections
+}  // namespace boost
+#endif // BOOST_REFLECTION_REFLECTION_HPP
Added: sandbox/boost/reflection/impl/reflection.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/reflection/impl/reflection.hpp	2008-04-10 00:57:07 EDT (Thu, 10 Apr 2008)
@@ -0,0 +1,74 @@
+/*
+ * Boost.Reflection / implementation header for Boost.PreProcessor
+ *
+ * (C) Copyright Mariano G. Consoni and 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.
+ */
+# define N BOOST_PP_ITERATION()
+// No ifndef headers - this is meant to be included multiple times.
+
+// Search for a constructor of the given type. instance_constructor
+// has a method to determine if a suitable constructor was found.
+template <class ParamFirst BOOST_PP_COMMA_IF(N)
+          BOOST_PP_ENUM_PARAMS(N, class Param)>
+instance_constructor<ParamFirst  BOOST_PP_COMMA_IF(N)
+                     BOOST_PP_ENUM_PARAMS(N, Param)> get_constructor() {
+  // Create a constructor_info structure to use for looking up
+  // a constructor in the constructor map. Initialize it with the
+  // function type requested.
+  constructor_info ctr_info(reflections::type_info_handler<TypeInfo,
+                            instance (*)(ParamFirst BOOST_PP_COMMA_IF(N)
+                                         BOOST_PP_ENUM_PARAMS(N, Param))>
+                            ::get_class_type());
+
+  // Determine whether or not such a constructor exists.
+  typename std::map<constructor_info, FunctionPtr>::iterator it =
+    constructors_.find(ctr_info);
+
+  if (it == constructors_.end()) {
+    // If none exists, return an empty instance_constructor.
+    return instance_constructor<ParamFirst  BOOST_PP_COMMA_IF(N)
+                                BOOST_PP_ENUM_PARAMS(N, Param)>();
+  } else {
+    // reinterpret_cast is safe, because we looked it up by its type.
+    return reinterpret_cast<instance (*)(ParamFirst BOOST_PP_COMMA_IF(N)
+                                         BOOST_PP_ENUM_PARAMS(N, Param))>
+      (it->second);
+  }
+}
+
+// Search for a member function matching the given signature and Info.
+template <class ReturnValue BOOST_PP_COMMA_IF(N)
+          BOOST_PP_ENUM_PARAMS(N, class Param)>
+function<ReturnValue BOOST_PP_COMMA_IF(N)
+         BOOST_PP_ENUM_PARAMS(N, Param)> get_function(Info info) {
+  // Construct a function_info structure to look up the function in the map.
+  function_info func_info(reflections::type_info_handler<TypeInfo,
+                          ReturnValue (*)(BOOST_PP_ENUM_PARAMS(N, Param))>
+                          ::get_class_type(), info);
+
+  // Look up the function.
+  typename std::map<function_info,
+    std::pair<MemberFunctionPtr, FunctionPtr> >::iterator it =
+    functions_.find(func_info);
+
+  if (it == functions_.end()) {
+    // If it does not exist, return an empty function object.
+    return function<ReturnValue BOOST_PP_COMMA_IF(N)
+                    BOOST_PP_ENUM_PARAMS(N, Param)>();
+  } else {
+    return function<ReturnValue BOOST_PP_COMMA_IF(N)
+                    BOOST_PP_ENUM_PARAMS(N, Param)>
+      // reinterpret_cast is safe, because we looked it up by its type.
+      (reinterpret_cast<ReturnValue (*)(void *, MemberFunctionPtr
+                                        BOOST_PP_COMMA_IF(N)
+                                        BOOST_PP_ENUM_PARAMS(N, Param))>
+        (it->second.second), it->second.first);
+  }
+}
+
+#undef N
\ No newline at end of file
Modified: sandbox/boost/reflection/reflection.hpp
==============================================================================
--- sandbox/boost/reflection/reflection.hpp	(original)
+++ sandbox/boost/reflection/reflection.hpp	2008-04-10 00:57:07 EDT (Thu, 10 Apr 2008)
@@ -11,110 +11,52 @@
 
 #ifndef BOOST_REFLECTION_REFLECTION_HPP
 #define BOOST_REFLECTION_REFLECTION_HPP
+
 #include <map>
 #include <vector>
 
 #include <boost/extension/impl/typeinfo.hpp>
+#include <boost/preprocessor/iteration/iterate.hpp>
 #include <boost/reflection/constructor.hpp>
+#include <boost/reflection/constructor_info.hpp>
 #include <boost/reflection/factory.hpp>
 #include <boost/reflection/function.hpp>
-// #include <boost/reflection/parameter_map.hpp>
+#include <boost/reflection/function_info.hpp>
 
-namespace boost {namespace reflections {
+namespace boost {
+namespace reflections {
 using extensions::type_info_handler;
-
-#define BOOST_REFLECTION_REFLECTION_GET_CONSTRUCTOR_FUNCTION(Z, N, _) \
-template <class ParamFirst BOOST_PP_COMMA_IF(N) \
-  BOOST_PP_ENUM_PARAMS(N, class Param)> \
-instance_constructor<ParamFirst  BOOST_PP_COMMA_IF(N) \
-            BOOST_PP_ENUM_PARAMS(N, Param)> get_constructor() { \
-  constructor_info t(reflections::type_info_handler<TypeInfo, \
-  instance (*)(ParamFirst BOOST_PP_COMMA_IF(N) \
-               BOOST_PP_ENUM_PARAMS(N, Param))>::get_class_type()); \
-  typename std::map<constructor_info, FunctionPtr>::iterator it = \
-    constructors_.find(t); \
-  if (it == constructors_.end()) { \
-    return instance_constructor<ParamFirst  BOOST_PP_COMMA_IF(N) \
-                       BOOST_PP_ENUM_PARAMS(N, Param)>(); \
-  } else { \
-    return reinterpret_cast<instance (*)(ParamFirst BOOST_PP_COMMA_IF(N) \
-                                         BOOST_PP_ENUM_PARAMS(N, Param))> \
-    (it->second); \
-  } \
-}
-
-#define BOOST_REFLECTION_REFLECTION_GET_FUNCTION_FUNCTION(Z, N, _) \
-template <class ReturnValue BOOST_PP_COMMA_IF(N) \
-          BOOST_PP_ENUM_PARAMS(N, class Param)> \
-function<ReturnValue BOOST_PP_COMMA_IF(N) \
-         BOOST_PP_ENUM_PARAMS(N, Param)> get_function(Info info) { \
-  function_info f(reflections::type_info_handler<TypeInfo, \
-                  ReturnValue (*)(BOOST_PP_ENUM_PARAMS(N, Param))> \
-                  ::get_class_type(), info); \
-  typename std::map<function_info, \
-    std::pair<MemberFunctionPtr, \
-    FunctionPtr> >::iterator it = \
-    functions_.find(f); \
-  if (it == functions_.end()) { \
-    return function<ReturnValue BOOST_PP_COMMA_IF(N) \
-                    BOOST_PP_ENUM_PARAMS(N, Param)>(); \
-  } else { \
-    return function<ReturnValue BOOST_PP_COMMA_IF(N) \
-    BOOST_PP_ENUM_PARAMS(N, Param)> \
-    (reinterpret_cast<ReturnValue (*)(void *, MemberFunctionPtr \
-                                      BOOST_PP_COMMA_IF(N) \
-                                      BOOST_PP_ENUM_PARAMS(N, Param))> \
-     (it->second.second), it->second.first); \
-  } \
-}
-  
-  
-
 typedef void (*FunctionPtr)();
-/*
-template <class Info = std::string,
-          class TypeInfo = reflections::default_type_info>
-class parameter_info {
-public:
-  virtual size_t num_parameters() = 0;
-  virtual const Info & operator[](unsigned position) = 0;
-  virtual TypeInfo type() = 0;
-  template <class T = void, class S = void>
-    class specific_parameter_info : public parameter_info {
-    public:
-      specific_parameter_info() {
-      }
-    private:
-    };
-  
-  template <class T>
-  class specific_parameter_info<T> : public parameter_info {
-  public:
-    specific_parameter_info() {
-    }
-  private:
-  };
-  specific_parameter_info<int> * create() {
-    return new specific_parameter_info<int>();
-  }
-private:
-  
-};*/
 
+// The basic_function_info class is used as a key in the map
+// of functions available for the current reflection.
+// There are two types - those with ParameterInfo defined, and
+// those without.
 template<class Info, class TypeInfo, class ParameterInfo = void>
 struct basic_function_info {
+  // The type of the function pointer in the map.
   TypeInfo type_info_;
+  // A description of the function pointer.
   Info info_;
+
+  // A description for each parameter of the function.
+  // If ParameterInfo=void, this does not appear.
   std::vector<ParameterInfo> parameter_info_;
-  basic_function_info(TypeInfo t, Info i) : type_info_(t), info_(i)
-  {
+
+  // Constructors
+  basic_function_info(TypeInfo t, Info i) : type_info_(t), info_(i) {
   }
+
   basic_function_info(const basic_function_info & s) 
-    : type_info_(s.type_info_), info_(s.info_) {}
+    : type_info_(s.type_info_), info_(s.info_) {
+  }
+
   basic_function_info & operator=(basic_function_info & s) {
     type_info_ = s.type_info_;
     info_ = s.info_;
   }
+
+  // Less-than operator - for maps.
   friend inline bool operator<(const basic_function_info & t,
                                const basic_function_info & s) {
     return t.type_info_ < s.type_info_ ||
@@ -123,19 +65,28 @@
   }
 };
 
+// Same as the above, but without ParameterInfo.
 template<class Info, class TypeInfo>
 struct basic_function_info<Info, TypeInfo> {
+  // The type of the function pointer in the map.
   TypeInfo type_info_;
+  // A description of the function pointer.
   Info info_;
-  basic_function_info(TypeInfo t, Info i) : type_info_(t), info_(i)
-  {
+
+  // Constructors.
+  basic_function_info(TypeInfo t, Info i) : type_info_(t), info_(i) {
   }
+
   basic_function_info(const basic_function_info & s) 
-    : type_info_(s.type_info_), info_(s.info_) {}
+    : type_info_(s.type_info_), info_(s.info_) {
+  }
+
   basic_function_info & operator=(basic_function_info & s) {
     type_info_ = s.type_info_;
     info_ = s.info_;
   }
+
+  // Less-than operator - for maps.
   friend inline bool operator<(const basic_function_info & t,
                                const basic_function_info & s) {
     return t.type_info_ < s.type_info_ ||
@@ -144,24 +95,40 @@
   }
 };
 
+// The basic_constructor_info class is used as a key in the map
+// of constructors available for the current reflection.
+// There are two types - those with ParameterInfo defined, and
+// those without.
 template<class TypeInfo, class ParameterInfo = void>
 struct basic_constructor_info {
+  // The type of the function pointer used to construct
+  // the object this constructor_info is for.
   TypeInfo type_info_;
+
+  // A description for each parameter of the function.
+  // If ParameterInfo=void, this does not appear.
   std::vector<ParameterInfo> parameter_info_;
-  basic_constructor_info(TypeInfo t) : type_info_(t)
-  {
+
+  // Constructors.
+  basic_constructor_info(TypeInfo t) : type_info_(t) {
   }
+
   basic_constructor_info(const basic_constructor_info & s) 
-    : type_info_(s.type_info_) {}
+    : type_info_(s.type_info_) {
+  }
+
   basic_constructor_info & operator=(basic_constructor_info & s) {
     type_info_ = s.type_info_;
   }
+
+  // Less than operator - for maps.
   friend inline bool operator<(const basic_constructor_info & t,
                                const basic_constructor_info & s) {
     return t.type_info_ < s.type_info_;
   }
 };
 
+
 template<class TypeInfo>
 struct basic_constructor_info<TypeInfo> {
   TypeInfo type_info_;
@@ -186,8 +153,10 @@
 public:
   template <class Q, class R, class S, class T>
   friend class reflector;
-  BOOST_PP_REPEAT(BOOST_REFLECTION_MAX_FUNCTOR_PARAMS, \
-                  BOOST_REFLECTION_REFLECTION_GET_CONSTRUCTOR_FUNCTION, _)
+#define BOOST_PP_ITERATION_LIMITS (0, \
+    BOOST_PP_INC(BOOST_REFLECTION_MAX_FUNCTOR_PARAMS) - 1)
+#define BOOST_PP_FILENAME_1 <boost/reflection/impl/reflection.hpp>
+#include BOOST_PP_ITERATE()
   instance_constructor<> get_constructor() {
     constructor_info t(reflections::type_info_handler<TypeInfo,
     instance (*)()>::get_class_type());
@@ -199,8 +168,6 @@
       return reinterpret_cast<instance (*)()>(it->second);
     }
   }
-  BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_REFLECTION_MAX_FUNCTOR_PARAMS), \
-                  BOOST_REFLECTION_REFLECTION_GET_FUNCTION_FUNCTION, _)
 private:
   typedef basic_function_info<Info, TypeInfo, ParameterInfo> function_info;
   typedef basic_constructor_info<TypeInfo, ParameterInfo> constructor_info;
@@ -214,8 +181,10 @@
 public:
   template <class Q, class R, class S, class T>
   friend class reflector;
-  BOOST_PP_REPEAT(BOOST_REFLECTION_MAX_FUNCTOR_PARAMS, \
-                  BOOST_REFLECTION_REFLECTION_GET_CONSTRUCTOR_FUNCTION, _)
+#define BOOST_PP_ITERATION_LIMITS (0, \
+    BOOST_PP_INC(BOOST_REFLECTION_MAX_FUNCTOR_PARAMS) - 1)
+#define BOOST_PP_FILENAME_1 <boost/reflection/impl/reflection.hpp>
+#include BOOST_PP_ITERATE()
     instance_constructor<> get_constructor() {
       constructor_info t(reflections::type_info_handler<TypeInfo,
       instance (*)()>::get_class_type());
@@ -227,8 +196,6 @@
         return reinterpret_cast<instance (*)()>(it->second);
       }
     }
-  BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_REFLECTION_MAX_FUNCTOR_PARAMS), \
-                  BOOST_REFLECTION_REFLECTION_GET_FUNCTION_FUNCTION, _)
 private:
   typedef basic_function_info<Info, TypeInfo> function_info;
   typedef basic_constructor_info<TypeInfo> constructor_info;