factory_reg.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef S11N_FACREG_TYPE
00029 # error "You must define S11N_FACREG_TYPE before including this file."
00030 #endif
00031
00032 #ifndef S11N_FACREG_TYPE_NAME
00033 # error "You must define S11N_FACREG_TYPE_NAME before including this file."
00034 #endif
00035
00036 #ifndef S11N_FACREG_INTERFACE_TYPE
00037 # define S11N_FACREG_INTERFACE_TYPE S11N_FACREG_TYPE
00038 #endif
00039
00040 #include <s11n.net/s11n/export.hpp>
00041
00042 #ifdef S11N_FACREG_TYPE_IS_ABSTRACT
00043
00044
00045
00046
00047 namespace s11n { namespace fac {
00048
00049
00050
00051
00052 template <>
00053 struct S11N_EXPORT_API create_hook< S11N_FACREG_INTERFACE_TYPE , S11N_FACREG_TYPE >
00054 {
00055 typedef S11N_FACREG_INTERFACE_TYPE * result_type;
00056 typedef S11N_FACREG_TYPE actual_type;
00057
00058 static result_type create()
00059 {
00060 return 0;
00061 }
00062 };
00063 } }
00064 #endif // S11N_FACREG_TYPE_IS_ABSTRACT
00065
00066 namespace {
00067
00068 # ifndef s11n_FACTORY_REG_CONTEXT_DEFINED
00069 # define s11n_FACTORY_REG_CONTEXT_DEFINED 1
00070
00071 // we must not include this more than once per compilation unit
00072
00073
00074
00075
00076
00077
00078 template <typename Context1, typename Context2 = Context1>
00079 struct S11N_EXPORT_API s11n_factory_reg_context
00080 {
00081 s11n_factory_reg_context()
00082 {
00083 if( true == placeholder ){}
00084 }
00085
00086
00087
00088
00089 static bool placeholder;
00090 };
00091 # endif // !s11n_FACTORY_REG_CONTEXT_DEFINED
00092
00093
00094
00095
00096 template <>
00097 bool
00098 s11n_factory_reg_context< S11N_FACREG_INTERFACE_TYPE, S11N_FACREG_TYPE >::placeholder= (
00099 ::s11n::fac::register_factory< S11N_FACREG_INTERFACE_TYPE >(
00100 std::string( S11N_FACREG_TYPE_NAME ),
00101 ::s11n::fac::create_hook<
00102 S11N_FACREG_INTERFACE_TYPE,
00103 S11N_FACREG_TYPE
00104 >::create
00105 ),
00106 true);
00107
00108 }
00109
00110 #ifdef S11N_FACREG_TYPE_IS_ABSTRACT
00111 # undef S11N_FACREG_TYPE_IS_ABSTRACT
00112 #endif
00113 #undef S11N_FACREG_TYPE
00114 #undef S11N_FACREG_INTERFACE_TYPE
00115 #undef S11N_FACREG_TYPE_NAME