Bayeux  3.4.1
Core Foundation library for SuperNEMO
factory_macros.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * : Ben Morgan <Ben.Morgan@warwick.ac.uk>
4  * Creation date : 2012-03-19
5  * Last modified : 2012-12-15
6  *
7  */
8 #ifndef DATATOOLS_FACTORY_MACROS_H
9 #define DATATOOLS_FACTORY_MACROS_H
10 
11 // Third Party:
12 #include <boost/preprocessor/stringize.hpp>
13 
14 // This project:
15 #include <datatools/factory.h>
16 
45 #define DATATOOLS_FACTORY_INTERFACE(BaseType) \
47  public: \
48  typedef ::datatools::factory_register< BaseType > factory_register_type; \
49 
50 
52 #define DATATOOLS_FACTORY_SYSTEM_REGISTER_INTERFACE(BaseType) \
53  DATATOOLS_FACTORY_INTERFACE(BaseType) \
54  public: \
55  typedef ::boost::scoped_ptr< factory_register_type > scoped_factory_register_type; \
56  static factory_register_type& grab_system_factory_register(); \
57  static const factory_register_type& get_system_factory_register(); \
58 
59 
61 #define DATATOOLS_FACTORY_SYSTEM_REGISTER_IMPLEMENTATION(BaseType, RegisterLabel) \
62  BaseType::factory_register_type& BaseType::grab_system_factory_register() \
63  { \
64  static scoped_factory_register_type _system_factory_register; \
65  if (!_system_factory_register) { \
66  _system_factory_register.reset(new BaseType::factory_register_type(RegisterLabel, 0)); \
67  } \
68  return *_system_factory_register.get(); \
69  } \
70  const BaseType::factory_register_type& BaseType::get_system_factory_register() \
71  { \
72  BaseType::factory_register_type& fr = BaseType::grab_system_factory_register(); \
73  return const_cast< BaseType::factory_register_type& >(fr); \
74  } \
75 
76 
77 // Useful macros
78 #define DATATOOLS_FACTORY_GRAB_SYSTEM_REGISTER(BaseType) \
79  BaseType::grab_system_factory_register() \
80 
81 
82 #define DATATOOLS_FACTORY_GET_SYSTEM_REGISTER(BaseType) \
83  BaseType::get_system_factory_register() \
84 
85 
87 #define DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_INTERFACE(BaseType, DerivedType) \
88  private: \
89  static ::datatools::_system_factory_registrator< BaseType , DerivedType > _g_system_factory_auto_registration_; \
90 public: \
91  static const std::string & system_factory_auto_registration_id(); \
92 
93 
95 #define DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_IMPLEMENTATION(BaseType, DerivedType, DerivedTypeId) \
96  ::datatools::_system_factory_registrator< BaseType , DerivedType > DerivedType::_g_system_factory_auto_registration_(DerivedTypeId); \
97  const std::string & DerivedType::system_factory_auto_registration_id() \
98  { \
99  static const std::string _id(DerivedTypeId); \
100  return _id; \
101  } \
102 
103 
104 #endif // DATATOOLS_FACTORY_FACTORY_MACROS_H
105 
106 // Local Variables: --
107 // mode: c++ --
108 // c-file-style: "gnu" --
109 // tab-width: 2 --
110 // End: --