From: stephan b. <st...@ei...> - 2003-10-13 09:33:40
|
One of the most important classes, classloader_register<> does not get documented by doxygen because it is an anonymous namespace (for linking reasons). It is in toolbox/ClassLoader.h, and explains how the collisions-free class/factory registration is handled. i wish i knew how to get doxygen to doc it :/. Here's what the INSTANTIATOR-like macro looks like: #define CLASSLOADER_REGISTER(BaseT,SubT) \ namespace { template<> struct classloader_registerer<BaseT,SubT>{\ typedef BaseT base_t; \ typedef SubT sub_t; \ typedef classloader_registerer<base_t,sub_t> this_t; \ static int placeholder; \ static std::string class_name(){ return # SubT; } \ static int startup( const std::string & classname) { \ return toolbox::ClassLoader< base_t >::register_factory( classname, toolbox::Factory< base_t, sub_t >::newInstance ); \ }\ }; \ int classloader_registerer<BaseT,SubT>::placeholder = classloader_registerer<BaseT,SubT>::startup( # SubT );\ } // string arg to startup(...) is not strictly necessary any more. that ensures that when the app starts up (or DLL is dlopen()ed) that the proper classloader is registered for the given type. The BaseT parameter is the one used by clients when "casting". e.g., that would be LoadableClass or Serializable in the current libfun code. The SubT param is, of course, a subtype of BaseT. The docs/headers cover this in excruciating detail (or should, anwyay). The classloader is fundamentally different than conventional ones. It doesn't read ANY symbols from DLLs. Instead it just opens them, triggering these "callbacks", and then asks itself if someone registered the appropriate factory. -- ----- st...@ei... - http://www.einsurance.de "... NOT because we are America's poodle ..." Tony Blair, 30.9.2003 |