Boost logo

Boost-Commit :

From: mconsoni_at_[hidden]
Date: 2007-07-05 09:05:27


Author: mconsoni
Date: 2007-07-05 09:05:26 EDT (Thu, 05 Jul 2007)
New Revision: 7362
URL: http://svn.boost.org/trac/boost/changeset/7362

Log:

- Added preprocessor macros to avoid the repetead code. Anyway it's optional (be could keep the repeated code
for debugging purposes). I have compiled and run the tests again to be sure that anything is still working.

Text files modified:
   sandbox/boost/extension/shared_library.hpp | 77 +++++++++++++++++++++++++++++++++++++++
   1 files changed, 77 insertions(+), 0 deletions(-)

Modified: sandbox/boost/extension/shared_library.hpp
==============================================================================
--- sandbox/boost/extension/shared_library.hpp (original)
+++ sandbox/boost/extension/shared_library.hpp 2007-07-05 09:05:26 EDT (Thu, 05 Jul 2007)
@@ -18,7 +18,81 @@
 #include <boost/function.hpp>
 #endif
 
+
+#ifdef BOOST_EXTENSION_USE_PP
+
+#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_EXTENSION_MAX_FUNCTOR_PARAMS
+#define BOOST_EXTENSION_MAX_FUNCTOR_PARAMS 6
+#endif
+
+/// functor template specialization macro.
+#define BOOST_EXTENSION_FUNCTOR_CLASS_PREFIX(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) > { \
+ protected:
+/**/
+
+#define BOOST_EXTENSION_FUNCTOR_CLASS_SUFFIX(Z, N, _) \
+ FunctionType func_; \
+ public: \
+ bool is_valid(){return func_ != 0;} \
+ functor(FunctionType func) \
+ : func_(func) {} \
+ functor(generic_function_ptr func) \
+ : func_(FunctionType((ReturnValue (*)(BOOST_PP_ENUM_PARAMS(N, \
+ Param))) func)) {} \
+ ReturnValue operator()(BOOST_PP_ENUM_BINARY_PARAMS(N, Param, p)) { \
+ return func_(BOOST_PP_ENUM_PARAMS(N, p)); \
+ } \
+};
+/**/
+
+
+#ifdef BOOST_EXTENSION_USE_BOOST_FUNCTION
+
+#define BOOST_EXTENSION_FUNCTOR_CLASS(Z, N, _) \
+ BOOST_EXTENSION_FUNCTOR_CLASS_PREFIX(Z, N, _) \
+ typedef BOOST_PP_CAT(boost::function, N) \
+ <ReturnValue BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, Param) > \
+ FunctionType; \
+ BOOST_EXTENSION_FUNCTOR_CLASS_SUFFIX(Z, N, _)
+/**/
+
+#else
+
+#define BOOST_EXTENSION_FUNCTOR_CLASS(Z, N, _) \
+ BOOST_EXTENSION_FUNCTOR_CLASS_PREFIX(Z, N, _) \
+ typedef ReturnValue (*FunctionType)(BOOST_PP_ENUM_PARAMS(N, Param)); \
+ BOOST_EXTENSION_FUNCTOR_CLASS_SUFFIX(Z, N, _)
+/**/
+
+#endif // ifdef BOOST_EXTENSION_USE_BOOST_FUNCTION
+#endif // ifdef BOOST_EXTENSION_USE_PP
+
+
+
 namespace boost{namespace extensions{
+
+#ifdef BOOST_EXTENSION_USE_PP
+
+/// Declaration of functor class template.
+template <class ReturnValue,
+ 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_EXTENSION_MAX_FUNCTOR_PARAMS), BOOST_EXTENSION_FUNCTOR_CLASS, _)
+
+#undef BOOST_EXTENSION_FUNCTOR_CLASS
+#else
+
 template <class ReturnValue, class Param1 = void, class Param2 = void,
           class Param3 = void, class Param4 = void, class Param5 = void,
           class Param6 = void>
@@ -200,6 +274,9 @@
   }
 };
 
+#endif // ifdef BOOST_EXTENSION_USE_PP
+
+
 class shared_library
 {
 protected:


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