= Module Générique = Ceci est un exemple de classe de Module générique et d'une macro permetant de faciliter la création d'un module. Bien sûr il n'est pas obligatoire d'utiliser cette classe, et c'est pour cette raison qu'elle ne fait pas partie intégrante de l'API. Le seule chose essentielle est que vos modules doivent avoir un constructeur prenant en paramètre un {{{IConfig *}}}. {{{ #!c # define ZIA_EXPORT_MODULE(name_, class_) \ extern "C" { IModule *init_##name_(IConfig *s) { return new class_(s); } } }}} Pour utiliser cette classe, il faudra par contre compiler le fichier Module.cc avec tous vos modules. Pour voir comment l'utiliser, il suffit de regarder les autres Howto. == Module.hh == {{{ #!cpp #ifndef MODULE_HH_ # define MODULE_HH_ # include "api/IModule.hh" namespace Zia { /// Common class for all the modules. class Module : public virtual IModule { public: Module(IConfig *config, const std::string & filename = "", int version = 0, const std::string & name = ""); /** * The interface virtual destructor */ virtual ~Module(); /** * Get the IConfig of this module. Any module should * be used with only one IConfig. * @return the module IConfig */ IConfig *getConfig() const; /** * Return the name of the module * @return the module name */ const std::string & getName() const; /** * Return the version of the module. Each 8 bits is a version * number. For example 0x0009040A is 9.4.11 * @return the module version */ int getVersion() const; /** * Return the version of the module as an human readable string. * @return the module version */ std::string getVersionString() const; /** Return the filename of the module. ** @return the module filename */ const std::string & getFileName() const; protected: IConfig *config_; private: std::string filename_; int version_; std::string name_; }; } # define ZIA_MODULE_VERSION(maj_, min_, patch_) \ (((maj_) << 16) | ((min_) << 8) | patch_) # define ZIA_MODULE(_name, _class, _version) \ ZIA_EXPORT_MODULE(_name, _class) \ _class::_class(IConfig *config) \ : Module(config, __FILE__, _version, #_name) #endif // MODULE_HH_ }}} == Module.cc == {{{ #!cpp #include #include "Module.hh" using namespace Zia; Module::Module(IConfig *config, const std::string & filename, int version, const std::string & name) : config_(config), filename_(filename), version_(version), name_(name) { } Module::~Module() { } IConfig * Module::getConfig() const { return (config_); } const std::string & Module::getName() const { return (name_); } int Module::getVersion() const { return (version_); } std::string Module::getVersionString() const { std::ostringstream oss; oss << ((version_ & 0xFF0000) >> 16) << "." << ((version_ & 0x00FF00) >> 8) << "." << ((version_ & 0x0000FF) >> 0); return (oss.str()); } const std::string & Module::getFileName() const { return (filename_); } }}}