#include "exception.h"
#include "types.h"
#include <vector>
#include <map>
#include <string>
Go to the source code of this file.
Classes | |
class | libglass::PluginManagerBase |
class | libglass::PluginManager |
class | libglass::PluginBase |
class | libglass::PluginInterface |
Namespaces | |
namespace | libglass |
Defines | |
#define | PLUGIN(cl) |
#define | PLUGIN_CONSTRUCTOR(cl) |
#define PLUGIN | ( | cl | ) |
Value:
private: \ cl(); \ void operator=(cl &); \ static bool registered; /* avoid duplicate id */\ static cl singleton; /* for auto-registering */ \ protected: \ /* prototypes for virtual functions */ \ bool processPacket(Packet &p); \ void unregisterNode(nodeId id); \ /* the virtual constructor */ \ PluginBase *instance(PluginManager *parent) { \ cl *inst = new cl(); \ inst->pm_parent = parent; \ return inst; \ } \ friend class PluginManagerBase; \ public: \ static cl & getHandle(void) { \ return singleton; \ }
#define PLUGIN_CONSTRUCTOR | ( | cl | ) |
Value:
bool cl::registered = false; \ cl cl::singleton; \ cl::cl() : PluginBase(#cl, ®istered)
PLUGIN_CONSTRUCTOR(MyClass), init1(), init2() { some code; }
Consider a concrete example that uses the PLUGIN_CONSTRUCTOR macro: In alias.cpp we have...
PLUGIN_CONSTRUCTOR(AliasBase) { // add your constructor code here }
This gets expanded to (note additional comments added in expanded code)...
// Initialisation of class static member // Note: This is performed during runtime initialisation before calling main() bool AliasBase::registered = false; // Initialisation of class static member object // Note: This is performed during runtime initialisation before calling main() // Will call default constructor for the class (see below), which calls // the PluginBase constructor during initialisation as... // PluginBase(const PluginId id, bool *registered) AliasBase AliasBase::singleton; // Define the default constructor AliasBase::AliasBase() : PluginBase("AliasBase", ®istered) { // add your constructor code here }
You can't have any parameters in the constructors. If you desperatedly need parameters, let us developers know, because I can't think of any reason. Remember that the user will *not* call this constructor, *ever*, so it's impossible to pass a parameter! If you wish to get/set parameters after the constructor returns, it's suggested to use an objected derived from PluginInterface, so the user will have access to those functions.
Note that the PLUGIN_CONSTRUCTOR macro uses the gnu c-preprocessor syntax for _stringification_ (or stringization as Microsoft call it) of the argument. That is to say c1 gets expanded (once) to a constant string. For example,
#define FOO(bar) format(#bar) FOO(hello)
would produce
format("hello")