47 #ifndef _MIRA_FACTORYMACROS_H_ 48 #define _MIRA_FACTORYMACROS_H_ 55 class ________________________________PLEASE_USE_THE__MIRA_TEMPLATE_CLASS_REGISTER__MACRO_IN_GLOBAL_NAMESPACE_ONLY________________________________
57 virtual int FOR_CLASS();
58 virtual ~________________________________PLEASE_USE_THE__MIRA_TEMPLATE_CLASS_REGISTER__MACRO_IN_GLOBAL_NAMESPACE_ONLY________________________________() {}
63 class ________________________________PLEASE_USE_THE__MIRA_CLASS_REGISTER__MACRO_IN_GLOBAL_NAMESPACE_ONLY________________________________
65 virtual int FOR_CLASS();
66 virtual ~________________________________PLEASE_USE_THE__MIRA_CLASS_REGISTER__MACRO_IN_GLOBAL_NAMESPACE_ONLY________________________________() {}
71 class ________________________________PLEASE_USE_THE__MIRA_NO_PUBLIC_DEFAULT_CONSTRUCTOR__MACRO_IN_GLOBAL_NAMESPACE_ONLY________________________________
73 virtual int FOR_CLASS();
74 virtual ~________________________________PLEASE_USE_THE__MIRA_NO_PUBLIC_DEFAULT_CONSTRUCTOR__MACRO_IN_GLOBAL_NAMESPACE_ONLY________________________________() {}
90 size_t pos = std::string::npos;
91 if ( identifier[identifier.length()-1] ==
'>' )
92 pos = identifier.rfind(
'<');
93 std::string tReturn = ( identifier.rfind(
"::",pos) != std::string::npos ) ?
94 identifier.substr( identifier.rfind(
"::",pos) + 2 )
109 #define MIRA_OBJECT_BASE( classIdentifier ) \ 110 friend class mira::ClassFactory; \ 112 template<typename pCLASS, typename pBASECLASS> \ 113 friend struct mira::FactoryRegisterClassHelper; \ 115 template<typename pCLASS> \ 116 friend class mira::TClass; \ 120 mira::TClass<classIdentifier> const& getClass() const { \ 125 static_cast<mira::TClass<classIdentifier> const&>( internalGetClass() ); \ 129 static mira::TClass<classIdentifier> const& CLASS() { \ 135 virtual mira::Class& internalGetClass() const { \ 138 static mira::TClass<classIdentifier>& _staticClassObject( \ 139 std::string const& identifier, \ 140 std::string const& name, \ 155 #define MIRA_NAMEDOBJECT( classIdentifier, className ) \ 156 MIRA_OBJECT_BASE( MIRA_PPARAM( classIdentifier ) ) \ 159 static mira::TClass<classIdentifier>& _CLASS() { \ 160 return _staticClassObject( mira::typeName<classIdentifier>(), \ 161 #className, true ); \ 165 static void addMetaInfo( std::map<std::string, std::string>& metaMap ) \ 179 #define MIRA_OBJECT( classIdentifier ) \ 180 MIRA_OBJECT_BASE( MIRA_PPARAM( classIdentifier ) ) \ 183 static mira::TClass<classIdentifier>& _CLASS() { \ 184 return _staticClassObject( mira::typeName<classIdentifier>(), \ 185 mira::mira_stripNameFromIdentifier( \ 186 mira::typeName<classIdentifier>() ), true ); \ 190 static void addMetaInfo( std::map<std::string, std::string>& metaMap ) \ 204 #define MIRA_META_OBJECT( classIdentifier, MetaInfo ) \ 205 MIRA_OBJECT_BASE( MIRA_PPARAM( classIdentifier ) ) \ 208 static mira::TClass<classIdentifier>& _CLASS() { \ 209 return _staticClassObject( mira::typeName<classIdentifier>(), \ 210 mira::mira_stripNameFromIdentifier( \ 211 mira::typeName<classIdentifier>() ), true ); \ 215 static void addMetaInfo( std::map<std::string, std::string>& metaMap ) \ 218 boost::assign::insert( metaMap ) MetaInfo; \ 235 #define MIRA_ABSTRACT_OBJECT( classIdentifier ) \ 236 MIRA_META_OBJECT( MIRA_PPARAM( classIdentifier ), ("AbstractClass", mira::typeName<classIdentifier>()) ) 242 #define MIRA_ABSTRACT_META_OBJECT( classIdentifier, MetaInfo ) \ 243 MIRA_META_OBJECT( MIRA_PPARAM( classIdentifier ), ("AbstractClass", mira::typeName<classIdentifier>())MetaInfo ) 253 #define MIRA_CLASS_REGISTER( Class, ... ) \ 256 ________________________________PLEASE_USE_THE__MIRA_CLASS_REGISTER__MACRO_IN_GLOBAL_NAMESPACE_ONLY________________________________ \ 257 <Class>::FOR_CLASS() { return 0; } \ 258 MIRA_REGISTRAR( MIRA_PPARAM( mira::FactoryRegisterClass<Class, __VA_ARGS__> ) ) \ 259 mira::TClass<Class>& Class::_staticClassObject(std::string const& identifier, \ 260 std::string const& name, \ 262 static mira::TClass<Class> sClass(identifier, name, libLoaded); \ 270 #define MIRA_NO_PUBLIC_DEFAULT_CONSTRUCTOR(CLASS) \ 273 class HasPublicDefaultConstructor<CLASS> : public std::false_type {}; \ 277 std::string
const& specialIdent )
279 size_t tFirstOccGeneric = genericIdent.find(
'<');
280 size_t tLastOccGeneric = genericIdent.rfind(
'>');
281 size_t tFirstOccSpecial = specialIdent.find(
'<');
282 size_t tLastOccSpecial = specialIdent.rfind(
'>');
284 assert( tFirstOccGeneric != std::string::npos &&
285 tLastOccGeneric != std::string::npos );
287 assert( tFirstOccSpecial != std::string::npos &&
288 tLastOccSpecial != std::string::npos );
290 std::string tReturnValue = genericIdent;
292 return tReturnValue.replace( tFirstOccGeneric, tLastOccGeneric-tFirstOccGeneric,
293 specialIdent.substr( tFirstOccSpecial,
294 tLastOccSpecial - tFirstOccSpecial ) );
299 #define MIRA_INTERNAL_OPEN_NAMESPACE(r,data,t) \ 302 #define MIRA_INTERNAL_CLOSE_NAMESPACE(r,data,t) } 306 #define MIRA_VA_NUM_ARGS(...) MIRA_VA_NUM_ARGS_IMPL(__VA_ARGS__,5,4,3,2,1) 307 #define MIRA_VA_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,N,...) N 311 #define MIRA_MAKE_SEQ(size, rel) MIRA_MAKE_SEQ_D(size, rel) 312 #define MIRA_MAKE_SEQ_D(size, rel) \ 314 MIRA_MAKE_SEQ_A_ ## size rel, \ 320 #define MIRA_MAKE_SEQ_A_1(a) ((a)) MIRA_MAKE_SEQ_B_1 321 #define MIRA_MAKE_SEQ_B_1(a) ((a)) MIRA_MAKE_SEQ_A_1 323 #define MIRA_MAKE_SEQ_A_10X0() 324 #define MIRA_MAKE_SEQ_B_10X0() 327 #define MIRA_MAKE_SEQ_A_2(a, b) ((a, b)) MIRA_MAKE_SEQ_B_2 328 #define MIRA_MAKE_SEQ_B_2(a, b) ((a, b)) MIRA_MAKE_SEQ_A_2 330 #define MIRA_MAKE_SEQ_A_20X0() 331 #define MIRA_MAKE_SEQ_B_20X0() 334 #define MIRA_MAKE_SEQ_A_3(a, b, c) ((a, b, c)) MIRA_MAKE_SEQ_B_3 335 #define MIRA_MAKE_SEQ_B_3(a, b, c) ((a, b, c)) MIRA_MAKE_SEQ_A_3 337 #define MIRA_MAKE_SEQ_A_30X0() 338 #define MIRA_MAKE_SEQ_B_30X0() 341 #define MIRA_MAKE_SEQ_A_4(a, b, c, d) ((a, b, c, d)) MIRA_MAKE_SEQ_B_4 342 #define MIRA_MAKE_SEQ_B_4(a, b, c, d) ((a, b, c, d)) MIRA_MAKE_SEQ_A_4 344 #define MIRA_MAKE_SEQ_A_40X0() 345 #define MIRA_MAKE_SEQ_B_40X0() 348 #define MIRA_MAKE_SEQ_A_5(a, b, c, d, e) ((a, b, c, d, e)) MIRA_MAKE_SEQ_B_5 349 #define MIRA_MAKE_SEQ_B_5(a, b, c, d, e) ((a, b, c, d, e)) MIRA_MAKE_SEQ_A_5 351 #define MIRA_MAKE_SEQ_A_50X0() 352 #define MIRA_MAKE_SEQ_B_50X0() 355 #define MIRA_MAKE_SEQ_A_6(a, b, c, d, e, f) ((a, b, c, d, e, f)) MIRA_MAKE_SEQ_B_6 356 #define MIRA_MAKE_SEQ_B_6(a, b, c, d, e, f) ((a, b, c, d, e, f)) MIRA_MAKE_SEQ_A_6 358 #define MIRA_INTERNAL_PRINT_TOKEN(TOKEN) #TOKEN 360 #define MIRA_DO_NOTHING(Sequence,StartId) 362 #define MIRA_INTERNAL_NAMESPACE_FOLD(r,data,t) \ 365 #define MIRA_INTERNAL_CONC_NAMESPACE_IMPL(Sequence, StartId) \ 366 BOOST_PP_SEQ_FOLD_RIGHT(MIRA_INTERNAL_NAMESPACE_FOLD,,BOOST_PP_SEQ_REST_N(StartId,Sequence)) 368 #define MIRA_INTERNAL_CONC_NAMESPACE(Sequence,StartId) \ 370 BOOST_PP_IF( BOOST_PP_SEQ_SIZE( BOOST_PP_SEQ_REST_N( StartId, Sequence) ), \ 372 MIRA_INTERNAL_CONC_NAMESPACE_IMPL \ 374 , MIRA_DO_NOTHING )(Sequence, StartId) 376 #define MIRA_INTERNAL_TEMPLATE_CLASS_REGISTER( r, Args, TmplSpec) \ 383 MIRA_REGISTRAR( MIRA_PPARAM( mira::FactoryRegisterClass< \ 386 BOOST_PP_IF( BOOST_PP_SEQ_SIZE( BOOST_PP_SEQ_REST_N( \ 387 BOOST_PP_SEQ_ELEM(3,Args),Args) ), \ 389 MIRA_INTERNAL_CONC_NAMESPACE_IMPL \ 391 , MIRA_DO_NOTHING )( Args, BOOST_PP_SEQ_ELEM(3,Args) ) \ 392 BOOST_PP_SEQ_ELEM(0,Args)<BOOST_PP_TUPLE_REM_CTOR( BOOST_PP_SEQ_ELEM(2,Args), TmplSpec)>, \ 393 BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_SUBSEQ(Args,4,BOOST_PP_SEQ_ELEM(1,Args)))> ) ) \ 396 #define MIRA_INTERNAL_TEMPLATE_CLASS_STATIC( r, Args, TmplSpec) \ 399 template<> mira::TClass<\ 400 BOOST_PP_SEQ_ELEM(0,Args)<BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_SEQ_ELEM(1,Args), TmplSpec)> >& \ 401 BOOST_PP_SEQ_ELEM(0,Args)<BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_SEQ_ELEM(1,Args), TmplSpec)>::_staticClassObject( \ 402 std::string const& identifier, \ 403 std::string const& name, \ 405 static mira::TemplateClass<BOOST_PP_SEQ_ELEM(0,Args)<BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_SEQ_ELEM(1,Args), TmplSpec)> > \ 406 sClass(identifier, name, libLoaded); \ 411 #define MIRA_TMPL_SPEC_CONCAT(r, data, i, elem) "," BOOST_PP_STRINGIZE(elem) 413 #define TAIL_NAME( Seq ) \ 414 BOOST_PP_SEQ_FOR_EACH_I( MIRA_TMPL_SPEC_CONCAT, , Seq) 416 #define MIRA_INTERNAL_TEMPLATE_IDENTIFIER( r, Args, TmplSpec) \ 422 std::string const& TemplateClass<MIRA_INTERNAL_CONC_NAMESPACE(Args,2) \ 423 BOOST_PP_SEQ_ELEM(0,Args)<BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_SEQ_ELEM(1,Args), TmplSpec)> >::getIdentifier() const { \ 426 static std::string tIdent = replaceTemplateGeneric( \ 427 TClass<MIRA_INTERNAL_CONC_NAMESPACE(Args,2) \ 428 BOOST_PP_SEQ_ELEM(0,Args)<BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_SEQ_ELEM(1,Args), TmplSpec)> >::getIdentifier(), \ 430 BOOST_PP_STRINGIZE(BOOST_PP_SEQ_HEAD(BOOST_PP_TUPLE_TO_SEQ(BOOST_PP_SEQ_ELEM(1,Args),TmplSpec))) \ 432 BOOST_PP_SEQ_FOR_EACH_I( MIRA_TMPL_SPEC_CONCAT, , BOOST_PP_SEQ_TAIL(BOOST_PP_TUPLE_TO_SEQ(BOOST_PP_SEQ_ELEM(1,Args), TmplSpec))) \ 439 std::string const& TemplateClass<MIRA_INTERNAL_CONC_NAMESPACE(Args,2) \ 440 BOOST_PP_SEQ_ELEM(0,Args)<BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_SEQ_ELEM(1,Args), TmplSpec)> >::getName() const { \ 441 static std::string tName = mira_stripNameFromIdentifier( \ 460 #define MIRA_TEMPLATE_CLASS_REGISTER( Namespace, Class, TmplSpec, ... ) \ 461 MIRA_TEMPLATE_CLASS_REGISTER_IMPL( Namespace, Class, 1, MIRA_MAKE_SEQ(1,TmplSpec), __VA_ARGS__ ) 475 #define MIRA_VARTEMPLATE_CLASS_REGISTER( Namespace, Class, NumTmplPrm, TmplSpec, ... ) \ 476 MIRA_TEMPLATE_CLASS_REGISTER_IMPL( Namespace, Class, NumTmplPrm, MIRA_MAKE_SEQ(NumTmplPrm,TmplSpec), __VA_ARGS__ ) 480 #define MIRA_TMPL_SIG_FROM_SEQ( NumTmplPrm, SeqId, Sequence )\ 481 BOOST_PP_TUPLE_REM_CTOR( NumTmplPrm, BOOST_PP_SEQ_ELEM(SeqId,Sequence) ) 483 #define MIRA_TEMPLATE_CLASS_REGISTER_IMPL( Namespace, Class, NumTmplPrm, TmplSpec, ... ) \ 486 ________________________________PLEASE_USE_THE__MIRA_TEMPLATE_CLASS_REGISTER__MACRO_IN_GLOBAL_NAMESPACE_ONLY________________________________\ 487 <MIRA_INTERNAL_CONC_NAMESPACE(Namespace,0)Class \ 488 <MIRA_TMPL_SIG_FROM_SEQ(NumTmplPrm,0,TmplSpec)> >::FOR_CLASS() { return 0; } \ 492 BOOST_PP_SEQ_FOR_EACH(MIRA_INTERNAL_TEMPLATE_CLASS_REGISTER, \ 494 (MIRA_VA_NUM_ARGS(__VA_ARGS__))(NumTmplPrm)(BOOST_PP_ADD(MIRA_VA_NUM_ARGS(__VA_ARGS__),4))\ 495 BOOST_PP_TUPLE_TO_SEQ(MIRA_VA_NUM_ARGS(__VA_ARGS__),(__VA_ARGS__)) \ 496 Namespace,TmplSpec) \ 500 BOOST_PP_IF( BOOST_PP_SEQ_SIZE( Namespace ), \ 502 BOOST_PP_SEQ_FOR_EACH(MIRA_INTERNAL_OPEN_NAMESPACE,~,Namespace) \ 508 BOOST_PP_SEQ_FOR_EACH(MIRA_INTERNAL_TEMPLATE_CLASS_STATIC, \ 509 (Class)(NumTmplPrm), TmplSpec) \ 511 BOOST_PP_IF( BOOST_PP_SEQ_SIZE( Namespace ), \ 513 BOOST_PP_SEQ_FOR_EACH(MIRA_INTERNAL_CLOSE_NAMESPACE,~,Namespace) \ 519 BOOST_PP_SEQ_FOR_EACH(MIRA_INTERNAL_TEMPLATE_IDENTIFIER, \ 520 (Class)(NumTmplPrm)Namespace,TmplSpec) \ specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Get compiler and platform independent typenames.
std::string mira_stripNameFromIdentifier(std::string const &identifier)
Auxiliary function to extract the class name from the given identifier.
Definition: FactoryMacros.h:88
std::string replaceTemplateGeneric(std::string const &genericIdent, std::string const &specialIdent)
Definition: FactoryMacros.h:276