|
Boost-Commit : |
From: mconsoni_at_[hidden]
Date: 2007-07-06 18:35:02
Author: mconsoni
Date: 2007-07-06 18:35:01 EDT (Fri, 06 Jul 2007)
New Revision: 7381
URL: http://svn.boost.org/trac/boost/changeset/7381
Log:
- Added preprocessor macros for this files. In counted_factory_map add,get and std::list operator were
rewrote using boost::preprocessor. In counted_factory the counted_factory class was rewrote.
Text files modified:
sandbox/boost/extension/counted_factory.hpp | 124 ++++++++++++++++++++++++++++++++++++++++
sandbox/boost/extension/counted_factory_map.hpp | 93 ++++++++++++++++++++++++++++++
2 files changed, 217 insertions(+), 0 deletions(-)
Modified: sandbox/boost/extension/counted_factory.hpp
==============================================================================
--- sandbox/boost/extension/counted_factory.hpp (original)
+++ sandbox/boost/extension/counted_factory.hpp 2007-07-06 18:35:01 EDT (Fri, 06 Jul 2007)
@@ -14,7 +14,130 @@
#ifndef BOOST_EXTENSION_COUNTED_FACTORY_HPP
#define BOOST_EXTENSION_COUNTED_FACTORY_HPP
#include <string>
+
+#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
+
+#endif
+
namespace boost{namespace extensions{
+
+#ifdef BOOST_EXTENSION_USE_PP
+
+/// Declaration of functor class template.
+template <class Interface, class Info,
+ BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PP_INC(\
+ BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
+ class Param, void)>\
+ class counted_factory;
+/**/
+
+
+#define BOOST_EXTENSION_COUNTED_FACTORY_CLASS(Z, N, _) \
+template<class Interface, class Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, class Param) > \
+class counted_factory<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) > { \
+protected: \
+ int * counter_; \
+ std::string library_; \
+ class generic_factory_function \
+ { \
+ public: \
+ virtual ~generic_factory_function(){} \
+ virtual Interface * operator()(int * counter \
+ BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, Param) ) = 0; \
+ virtual generic_factory_function * copy() const = 0; \
+ }; \
+ template <class T> \
+ class factory_function : public generic_factory_function \
+ { \
+ public: \
+ class counted_object : public T \
+ { \
+ private: \
+ int * counter_; \
+ public: \
+ counted_object(int * counter BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_BINARY_PARAMS(N, Param, p)) \
+ : T(BOOST_PP_ENUM_PARAMS(N, p)), \
+ counter_(counter) \
+ { \
+ ++(*counter_); \
+ } \
+ ~counted_object() \
+ { \
+ --(*counter_); \
+ } \
+ }; \
+ virtual ~factory_function(){} \
+ virtual Interface * operator() \
+ (int * counter BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_BINARY_PARAMS(N, Param, p)) \
+ { \
+ return static_cast<Interface*>(new counted_object(counter \
+ BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N,p)));} \
+ virtual generic_factory_function * copy() const { \
+ return new factory_function<T>; \
+ } \
+ }; \
+ std::auto_ptr<generic_factory_function> factory_func_ptr_; \
+ Info info_; \
+public: \
+ void set_library(const char * library_name) \
+ { \
+ library_ = library_name; \
+ } \
+ void set_counter(int * counter) \
+ { \
+ counter_ = counter; \
+ } \
+ const char * library() \
+ { \
+ return library_.c_str(); \
+ } \
+ template <class Actual> \
+ void set_type_special(Actual *){ \
+ factory_func_ptr_.reset(new factory_function<Actual>());} \
+ template <class Actual> \
+ void set_type(){factory_func_ptr_ = new factory_function<Actual>();} \
+ counted_factory(Info info) \
+ :factory_func_ptr_(0), \
+ info_(info) \
+ {} \
+ counted_factory(const counted_factory & first) \
+ :counter_(first.counter_), \
+ library_(first.library_), \
+ factory_func_ptr_(first.factory_func_ptr_->copy()), \
+ info_(first.info_) \
+ {} \
+ Interface * operator()(int * counter BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_BINARY_PARAMS(N, Param, p)) \
+ {return create(counter BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, p));} \
+ Interface * create(BOOST_PP_ENUM_BINARY_PARAMS(N, Param, p)) { \
+ return (*factory_func_ptr_) (counter_ BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, p)); \
+ } \
+ Info & get_info(){return info_;} \
+};
+/**/
+
+/// Functor template specializations.
+BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
+ BOOST_EXTENSION_COUNTED_FACTORY_CLASS, _)
+
+
+#undef BOOST_EXTENSION_COUNTED_FACTORY_CLASS
+#else
template <class Interface, class Info, class Param1 = void,
class Param2 = void, class Param3 = void, class Param4 = void,
class Param5 = void, class Param6 = void>
@@ -599,5 +722,6 @@
(counter_);}
Info & get_info(){return info_;}
};
+#endif // BOOST_EXTENSION_USE_PP
}}
#endif
Modified: sandbox/boost/extension/counted_factory_map.hpp
==============================================================================
--- sandbox/boost/extension/counted_factory_map.hpp (original)
+++ sandbox/boost/extension/counted_factory_map.hpp 2007-07-06 18:35:01 EDT (Fri, 06 Jul 2007)
@@ -19,6 +19,20 @@
#include <boost/extension/extension.hpp>
#include <boost/extension/impl/typeinfo.hpp>
+#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
+
+#endif
+
+
namespace boost{namespace extensions{
@@ -79,6 +93,84 @@
delete it->second;
//TODO - test for memory leaks.
}
+
+#ifdef BOOST_EXTENSION_USE_PP
+
+#define BOOST_EXTENSION_COUNTED_FACTORY_MAP_OP_LIST(Z, N, _) \
+template<class Interface, class Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, \
+ class Param) > \
+operator std::list<counted_factory<Interface, Info \
+ BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) > > & () { \
+ return this->get<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) >(); \
+}
+/**/
+
+#define BOOST_EXTENSION_COUNTED_FACTORY_MAP_GET_METHOD(Z, N, _) \
+template <class Interface, class Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, class Param) > \
+std::list<counted_factory<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) > > & get() \
+{ \
+ TypeInfo current_type = \
+ type_info_handler<TypeInfo, counted_factory<Interface, Info \
+ BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) > >::get_class_type(); \
+ typename FactoryMap::iterator it = factories_.find(current_type); \
+ if (it == factories_.end()) \
+ { \
+ factory_container<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) > * ret = \
+ new factory_container<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) >(current_counter_); \
+ factories_[current_type] = ret; \
+ return *ret; \
+ } \
+ else \
+ { \
+ return static_cast<factory_container<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) > &>(*(it->second)); \
+ } \
+}
+/**/
+
+#define BOOST_EXTENSION_COUNTED_FACTORY_MAP_ADD_METHOD(Z, N, _) \
+template <class Actual, class Interface, class Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, class Param) > \
+void add(Info info) \
+{ \
+ typedef std::list<counted_factory<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) > > ListType; \
+ ListType & s = this->get<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) >(); \
+ counted_factory<Interface, Info BOOST_PP_COMMA_IF(N) \
+ BOOST_PP_ENUM_PARAMS(N, Param) > f(info); \
+ f.set_library(current_library_.c_str()); \
+ f.set_counter(current_counter_); \
+ f.set_type_special((Actual*)0); \
+ s.push_back(f); \
+}
+/**/
+
+
+BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
+ BOOST_EXTENSION_COUNTED_FACTORY_MAP_OP_LIST, _)
+
+
+BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
+ BOOST_EXTENSION_COUNTED_FACTORY_MAP_GET_METHOD, _)
+
+
+BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_EXTENSION_MAX_FUNCTOR_PARAMS), \
+ BOOST_EXTENSION_COUNTED_FACTORY_MAP_ADD_METHOD, _)
+
+
+#undef BOOST_EXTENSION_COUNTED_FACTORY_MAP_OP_LIST
+#undef BOOST_EXTENSION_COUNTED_FACTORY_MAP_GET_METHOD
+#undef BOOST_EXTENSION_COUNTED_FACTORY_MAP_ADD_METHOD
+#else
template <class Interface, class Info>
operator std::list<counted_factory<Interface, Info> > & ()
{return this->get<Interface, Info>();}
@@ -389,6 +481,7 @@
s.push_back(f);
//it->set_type<Actual>();
}
+#endif // BOOST_EXTENSION_USE_PP
};
typedef basic_counted_factory_map<default_type_info> counted_factory_map;
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