|
Boost-Commit : |
From: oryol_at_[hidden]
Date: 2008-04-12 12:19:41
Author: jeremypack
Date: 2008-04-12 12:19:40 EDT (Sat, 12 Apr 2008)
New Revision: 44349
URL: http://svn.boost.org/trac/boost/changeset/44349
Log:
Maik Beckman - cosmetic fixes patched in.
Fixes to extension code to make it more readable. I'm doing similar things for reflection as well.
Text files modified:
sandbox/boost/extension/common.hpp | 5
sandbox/boost/extension/factory.hpp | 170 ++++++++++++++++++++-----------
sandbox/boost/extension/factory_map.hpp | 163 +++++++++++++++++++-----------
sandbox/boost/extension/functor.hpp | 216 +++++----------------------------------
4 files changed, 246 insertions(+), 308 deletions(-)
Modified: sandbox/boost/extension/common.hpp
==============================================================================
--- sandbox/boost/extension/common.hpp (original)
+++ sandbox/boost/extension/common.hpp 2008-04-12 12:19:40 EDT (Sat, 12 Apr 2008)
@@ -17,9 +17,10 @@
#include <boost/preprocessor/if.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/repetition.hpp>
+#include <boost/preprocessor/iteration/iterate.hpp>
#ifndef BOOST_EXTENSION_MAX_FUNCTOR_PARAMS
-#define BOOST_EXTENSION_MAX_FUNCTOR_PARAMS 6
-#endif // BOOST_EXTENSION_MAX_FUNCTOR_PARAMS
+# define BOOST_EXTENSION_MAX_FUNCTOR_PARAMS 6
+#endif
#endif // BOOST_EXTENSION_COMMON_HPP
Modified: sandbox/boost/extension/factory.hpp
==============================================================================
--- sandbox/boost/extension/factory.hpp (original)
+++ sandbox/boost/extension/factory.hpp 2008-04-12 12:19:40 EDT (Sat, 12 Apr 2008)
@@ -10,79 +10,125 @@
* See http://www.boost.org/ for latest version.
*/
+#ifndef BOOST_PP_IS_ITERATING
+
+
#ifndef BOOST_EXTENSION_FACTORY_HPP
#define BOOST_EXTENSION_FACTORY_HPP
#include <boost/extension/common.hpp>
namespace boost{namespace extensions{
+
+
+#define N BOOST_EXTENSION_MAX_FUNCTOR_PARAMS
+
template <class T, class D
- BOOST_PP_COMMA_IF(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS)
- BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PP_INC(\
- BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
- class Param, void) >
- class create_function;
-
-#define BOOST_EXTENSION_CREATE_FUNCTION_CLASS(Z, N, _) \
-template <class T, class D BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, \
- class Param) > \
-class create_function<T, D BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, \
- Param) > \
-{ \
-public: \
- static T * create(BOOST_PP_ENUM_BINARY_PARAMS(N, Param, p)) { \
- return new D(BOOST_PP_ENUM_PARAMS(N, p)); \
- } \
-};
+ BOOST_PP_COMMA_IF(N)
+ BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( \
+ BOOST_PP_INC(N), class Param, void) >
+struct create_function;
+
+#undef N
+
+
+#define N BOOST_EXTENSION_MAX_FUNCTOR_PARAMS
template <class T
- BOOST_PP_COMMA_IF(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS)
- BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PP_INC(\
- BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
- class Param, void) >
+ BOOST_PP_COMMA_IF(N)
+ BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
+ BOOST_PP_INC(N), class Param, void) >
class factory;
-#define BOOST_EXTENSION_FACTORY_CLASS(Z, N, _) \
-template <class T BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, \
- class Param) > \
-class factory <T BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, \
- Param) > \
-{ \
-public: \
- template <class D> \
- void set() { \
- func_ = &create_function<T, D BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, \
- Param)>::create; \
- } \
- factory() : func_(0) {} \
- factory(const factory<T> & first) : func_(first.func_) {} \
- factory & operator=(const factory<T> & first) { \
- func_ = first->func_; \
- return *this; \
- } \
- bool is_valid() {return func_ != 0;} \
- T * create(BOOST_PP_ENUM_BINARY_PARAMS(N, Param, p)) { \
- if (func_) { \
- return func_(BOOST_PP_ENUM_PARAMS(N, p)); \
- } else { \
- return 0; \
- } \
- } \
-private: \
- T * (*func_)(BOOST_PP_ENUM_PARAMS(N, Param)); \
-};
+#undef N
+
+
+// generate specializations of create_function and factory
+# define BOOST_PP_ITERATION_LIMITS (0, BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS) - 1)
+# define BOOST_PP_FILENAME_1 <boost/extension/factory.hpp> // this file
+# include BOOST_PP_ITERATE()
+
-BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
- BOOST_EXTENSION_CREATE_FUNCTION_CLASS, _)
-BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
- BOOST_EXTENSION_FACTORY_CLASS, _)
-#undef BOOST_EXTENSION_FACTORY_CLASS
-#undef BOOST_EXTENSION_CREATE_FUNCTION_CLASS
-}}
+}} // namespace boost::extension
#endif // BOOST_EXTENSION_FACTORY_HPP
+
+
+
+
+#else // BOOST_PP_IS_ITERATING
+
+
+// for convenience
+#define n BOOST_PP_ITERATION()
+
+
+
+template <
+ class T,
+ class D
+ BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class Param)
+>
+struct create_function<
+ T,
+ D
+ BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)
+>
+{
+ static T * create(BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) )
+ {
+ return new D(BOOST_PP_ENUM_PARAMS(n, p));
+ }
+};
+
+
+
+template <class T BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class Param) >
+class factory<T BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param) >
+{
+public:
+
+ template <class D>
+ void set()
+ {
+ this->func = &create_function<
+ T, D BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n,Param)
+ >::create;
+ }
+
+ factory() : func(0) {}
+
+ factory(factory<T> const& first) : func(first.func) {}
+
+ factory& operator=(factory<T> const& first)
+ {
+ this->func = first->func;
+ return *this;
+ }
+
+ bool is_valid() { return this->func != 0; }
+
+ T* create(BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p))
+ {
+ if (this->func)
+ {
+ return this->func(BOOST_PP_ENUM_PARAMS(n, p));
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+private:
+
+ typedef T* (*func_ptr_type)(BOOST_PP_ENUM_PARAMS(n, Param));
+ func_ptr_type func;
+
+};
+
+
+#undef n
+
+
+#endif // BOOST_PP_IS_ITERATING
Modified: sandbox/boost/extension/factory_map.hpp
==============================================================================
--- sandbox/boost/extension/factory_map.hpp (original)
+++ sandbox/boost/extension/factory_map.hpp 2008-04-12 12:19:40 EDT (Sat, 12 Apr 2008)
@@ -10,84 +10,127 @@
* See http://www.boost.org/ for latest version.
*/
+
+#ifndef BOOST_PP_IS_ITERATING
+
+
+
+
#ifndef BOOST_EXTENSION_FACTORY_MAP_HPP
#define BOOST_EXTENSION_FACTORY_MAP_HPP
+
#include <map>
#include <boost/extension/factory.hpp>
#include <boost/extension/impl/typeinfo.hpp>
namespace boost{namespace extensions{
-#define BOOST_EXTENSION_FACTORY_MAP_GET_FUNCTION(Z, N, _) \
-template <class Interface, class Info \
- BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, class Param) > \
-std::map<Info, \
- factory<Interface BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, Param)> > & get() { \
- TypeInfo t = type_info_handler<TypeInfo, \
- Interface *(*)(BOOST_PP_ENUM_PARAMS(N, Param))> \
- ::get_class_type(); \
- typename std::map<TypeInfo, generic_map_holder*>::iterator it = \
- maps_.find(t); \
- map_holder<std::map<Info, \
- factory<Interface BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, Param)> > > \
- * holder; \
- if (it == maps_.end()) { \
- holder = new map_holder<std::map<Info, \
- factory<Interface BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, Param)> > >; \
- it = maps_.insert(std::make_pair \
- (t, holder)).first; \
- } else { \
- holder = \
- static_cast<map_holder<std::map<Info, \
- factory<Interface BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, Param)> > > *> \
- (it->second); \
- } \
- return *static_cast<std::map<Info, \
- factory<Interface BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, Param)> > * >(holder); \
-}
-
-#define BOOST_EXTENSION_FACTORY_MAP_CONVERT_FUNCTION(Z, N, _) \
-template <class Interface, class Info \
-BOOST_PP_COMMA_IF(N) \
-BOOST_PP_ENUM_PARAMS(N, class Param) > \
-operator std::map<Info, \
-factory<Interface BOOST_PP_COMMA_IF(N) \
-BOOST_PP_ENUM_PARAMS(N, Param)> >() { \
- return get<Interface, Info BOOST_PP_COMMA_IF(N) \
- BOOST_PP_ENUM_PARAMS(N, Param)>(); \
-}
-
template <class TypeInfo>
-class basic_factory_map {
+class basic_factory_map
+{
+
public:
-BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
- BOOST_EXTENSION_FACTORY_MAP_GET_FUNCTION, _)
-BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
- BOOST_EXTENSION_FACTORY_MAP_CONVERT_FUNCTION, _)
- ~basic_factory_map() {
- for (typename std::map<TypeInfo, generic_map_holder*>
- ::iterator it =maps_.begin();
- it != maps_.end(); ++it) {
+
+ // generate get and conversion template member functions from the
+ // specification at the end of this file
+# define BOOST_PP_ITERATION_LIMITS (0, \
+ BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS) - 1)
+# define BOOST_PP_FILENAME_1 <boost/extension/factory_map.hpp> // this file
+# include BOOST_PP_ITERATE()
+
+ ~basic_factory_map()
+ {
+ for (typename std::map<TypeInfo, generic_map_holder*>::iterator
+ it =maps_.begin(); it != maps_.end(); ++it)
+ {
delete it->second;
}
}
+
private:
- class generic_map_holder {
- public:
+
+ struct generic_map_holder
+ {
virtual ~generic_map_holder() {}
};
+
template <class T>
- class map_holder : public generic_map_holder, public T{
- };
+ struct map_holder : generic_map_holder, T {};
+
std::map<TypeInfo, generic_map_holder*> maps_;
};
+
typedef basic_factory_map<default_type_info> factory_map;
-}}
-#undef BOOST_EXTENSION_FACTORY_MAP_GET_FUNCTION
-#undef BOOST_EXTENSION_FACTORY_MAP_CONVERT_FUNCTION
-#endif
+}} // namespace boost::extensions
+
+// Note! This is the end of the include guard
+#endif // BOOST_EXTENSION_FACTORY_MAP_HPP
+
+
+
+
+#else // BOOST_PP_IS_ITERATING
+
+
+
+// for convenience
+# define n BOOST_PP_ITERATION()
+
+
+template <class Interface, class Info
+ BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class Param) >
+std::map<
+ Info,
+ factory<Interface BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param) >
+ > &
+get()
+{
+ typedef Interface* (* func_ptr_type )(BOOST_PP_ENUM_PARAMS(n, Param));
+ typedef type_info_handler<TypeInfo, func_ptr_type> handler_type;
+
+ TypeInfo t = handler_type::get_class_type();
+
+ typename std::map<TypeInfo, generic_map_holder*>::iterator
+ it = maps_.find(t);
+
+ typedef factory<
+ Interface
+ BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)
+ > factory_type;
+ typedef std::map<Info, factory_type> map_type;
+
+ map_holder<map_type>* holder;
+ if (it == maps_.end())
+ {
+ holder = new map_holder<map_type>;
+ it = maps_.insert(std::make_pair(t, holder)).first;
+ }
+ else
+ {
+ holder = static_cast<map_holder<map_type>* > (it->second);
+ }
+
+ return *(static_cast<map_type* >(holder));
+}
+
+
+template <class Interface, class Info
+ BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class Param) >
+operator
+ std::map<
+ Info,
+ factory<Interface BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param) >
+ >
+ ()
+{
+ return get< Interface, Info
+ BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param)>();
+}
+
+
+# undef n
+
+
+
+#endif // BOOST_PP_IS_ITERATING
Modified: sandbox/boost/extension/functor.hpp
==============================================================================
--- sandbox/boost/extension/functor.hpp (original)
+++ sandbox/boost/extension/functor.hpp 2008-04-12 12:19:40 EDT (Sat, 12 Apr 2008)
@@ -1,6 +1,6 @@
/*
* Boost.Extension / functor:
- * functor used as the exported function of the libraries (the one that
+ * functor used as the exported function of the libraries (the one that
* registers the implementations at library loading time)
*
* (C) Copyright Jeremy Pack 2007
@@ -11,225 +11,73 @@
* See http://www.boost.org/ for latest version.
*/
+#ifndef BOOST_PP_IS_ITERATING
+
+
+
#ifndef BOOST_EXTENSION_FUNCTOR_HPP
#define BOOST_EXTENSION_FUNCTOR_HPP
+#include <boost/extension/common.hpp>
#include <boost/extension/impl/library_impl.hpp>
-#ifdef BOOST_EXTENSIONS_USE_PP
-
-#include <boost/preprocessor/arithmetic/inc.hpp>
-#include <boost/preprocessor/punctuation/comma_if.hpp>
-#include <boost/preprocessor/repetition.hpp>
-
-#ifndef BOOST_EXTENSIONS_MAX_FUNCTOR_PARAMS
-#define BOOST_EXTENSIONS_MAX_FUNCTOR_PARAMS 6
-#endif
-
-/// functor template specialization macro.
-#define BOOST_EXTENSIONS_FUNCTOR_CLASS(Z, N, _) \
- template<class ReturnValue BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, class Param) > \
- class functor<ReturnValue BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, Param) > { \
- private: \
- typedef ReturnValue (*FunctionType)(BOOST_PP_ENUM_PARAMS(N, Param)); \
- FunctionType func_; \
- public: \
- bool is_valid() const {return func_ != 0;} \
- functor(FunctionType func) \
- : func_(func) {} \
- functor(generic_function_ptr func) \
- : func_(FunctionType(func)) {} \
- ReturnValue operator()(BOOST_PP_ENUM_BINARY_PARAMS(N, Param, p)) { \
- return func_(BOOST_PP_ENUM_PARAMS(N, p)); \
- } \
- }; \
-/**/
-
-#endif // ifdef BOOST_EXTENSIONS_USE_PP
namespace boost { namespace extensions {
-//using boost::extensions::impl::generic_function_ptr;
+//using boost::extensions::detail::generic_function_ptr;
-#ifdef BOOST_EXTENSIONS_USE_PP
/// Declaration of functor class template.
template <class ReturnValue,
- BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PP_INC(BOOST_EXTENSIONS_MAX_FUNCTOR_PARAMS), class Param, void)>
+ BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( \
+ BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), class Param, void) >
class functor;
/// Functor template specializations.
-BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSIONS_MAX_FUNCTOR_PARAMS), BOOST_EXTENSIONS_FUNCTOR_CLASS, _)
+# define BOOST_PP_ITERATION_LIMITS (0, BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS) - 1)
+# define BOOST_PP_FILENAME_1 <boost/extension/functor.hpp> // this file
+# include BOOST_PP_ITERATE()
-#undef BOOST_EXTENSIONS_FUNCTOR_CLASS
-#else
-template <class ReturnValue, class Param1 = void, class Param2 = void,
- class Param3 = void, class Param4 = void, class Param5 = void,
- class Param6 = void>
-class functor {
-private:
- typedef ReturnValue (*FunctionType)(Param1, Param2, Param3, Param4,
- Param5, Param6);
- FunctionType func_;
-public:
- bool is_valid() const {return func_ != 0;}
+}} // namespace boost::extensions
- functor(FunctionType func)
- : func_(func)
- {}
-
- functor(generic_function_ptr func)
- : func_(FunctionType(func))
- {}
-
- ReturnValue operator()(Param1 p1, Param2 p2, Param3 p3, Param4 p4,
- Param5 p5, Param6 p6)
- {
- return func_(p1, p2, p3, p4, p5, p6);
- }
-};
+#endif // BOOST_EXTENSION_FUNCTOR_HPP
-template <class ReturnValue, class Param1, class Param2, class Param3,
- class Param4, class Param5>
-class functor<ReturnValue, Param1, Param2, Param3, Param4, Param5>
-{
-private:
- typedef ReturnValue (*FunctionType)(Param1, Param2, Param3, Param4,
- Param5);
- FunctionType func_;
-public:
- bool is_valid() const {return func_ != 0;}
- functor(FunctionType func)
- :func_(func)
- {}
- functor(generic_function_ptr func)
- :func_(FunctionType(func))
- {}
- ReturnValue operator()(Param1 p1, Param2 p2, Param3 p3, Param4 p4,
- Param5 p5)
- {
- return func_(p1, p2, p3, p4, p5);
- }
-};
+#else // BOOST_PP_IS_ITERATING
-template <class ReturnValue, class Param1, class Param2, class Param3,
- class Param4>
-class functor<ReturnValue, Param1, Param2, Param3, Param4>
-{
-private:
- typedef ReturnValue (*FunctionType)(Param1, Param2, Param3, Param4);
- FunctionType func_;
-public:
- bool is_valid() const {return func_ != 0;}
- functor(FunctionType func)
- :func_(func)
- {}
-
- functor(generic_function_ptr func)
- :func_(FunctionType(func))
- {}
-
- ReturnValue operator()(Param1 p1, Param2 p2, Param3 p3, Param4 p4)
- {
- return func_(p1, p2, p3, p4);
- }
-};
-template <class ReturnValue, class Param1, class Param2, class Param3>
-class functor<ReturnValue, Param1, Param2, Param3>
-{
-private:
- typedef ReturnValue (*FunctionType)(Param1, Param2, Param3);
- FunctionType func_;
-
-public:
- bool is_valid() const {return func_ != 0;}
-
- functor(FunctionType func)
- :func_(func)
- {}
- functor(generic_function_ptr func)
- :func_(FunctionType(func))
- {}
- ReturnValue operator()(Param1 p1, Param2 p2, Param3 p3)
- {
- return func_(p1, p2, p3);
- }
-};
+# define n BOOST_PP_ITERATION()
-template <class ReturnValue, class Param1, class Param2>
-class functor<ReturnValue, Param1, Param2>
+template<class ReturnValue
+ BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class Param) >
+class functor<ReturnValue
+ BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param) >
{
private:
- typedef ReturnValue (*FunctionType)(Param1, Param2);
- FunctionType func_;
+
+ typedef ReturnValue (*FunctionType)(BOOST_PP_ENUM_PARAMS(n, Param));
+ FunctionType func_;
public:
- bool is_valid() const {return func_ != 0;}
- functor(FunctionType func)
- :func_(func)
- {}
- functor(generic_function_ptr func)
- :func_(FunctionType(func))
- {}
- ReturnValue operator()(Param1 p1, Param2 p2)
- {
- return func_(p1, p2);
- }
-};
+ bool is_valid() const {return func_ != 0;}
-template <class ReturnValue, class Param1>
-class functor<ReturnValue, Param1>
-{
-private:
- typedef ReturnValue (*FunctionType)(Param1);
- FunctionType func_;
+ functor(FunctionType func) : func_(func) {}
-public:
- bool is_valid() const {return func_ != 0;}
- functor(FunctionType func)
- :func_(func)
- {}
- functor(generic_function_ptr func)
- :func_(FunctionType(func))
- {}
- ReturnValue operator()(Param1 p1)
- {
- return func_(p1);
- }
-};
-
-template <class ReturnValue>
-class functor<ReturnValue>
-{
-private:
- typedef ReturnValue (*FunctionType)();
- FunctionType func_;
+ functor(generic_function_ptr func) : func_(FunctionType(func)) {}
-public:
- bool is_valid() const {return func_ != 0;}
- functor(FunctionType func)
- :func_(func)
- {}
- functor(generic_function_ptr func)
- :func_(FunctionType(func))
- {}
- ReturnValue operator()()
- {
- return func_();
- }
+ ReturnValue operator()(BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p))
+ {
+ return func_(BOOST_PP_ENUM_PARAMS(n, p));
+ }
};
-#endif // ifdef BOOST_EXTENSIONS_USE_PP
+# undef n
-}} // ns: boost::extensions
-
-#endif // BOOST_EXTENSION_FUNCTOR_HPP
+#endif // BOOST_PP_IS_ITERATING
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