I am trying to write an application that dynamically loads its extensions at runtime. I used the Preostcessor Boost library to write a preprocessor function, which, given the list of names, declares a class for each name (and makes all of them subclasses of some AbstractPlugin class), and then declares a Boost MPL sequence containing these classes. Then I wrote a class that tries to point to a pointer to AbstractPlugin if it can be applied to any type in this MPL sequence. The problem here is that my preprocessor function needs a complete list of all the extensions that I want to create and download. Is there any method to register each extension in a separate file?
Update:
I believe that my explanation of the situation was too vague, so I decided to make it more specific.
I would like to define a set of extension types. For each type of extension, there can be any number of extensions. At run time, the program loads an external library, enables the entry point function, calls it, and, as a result, gets a pointer. Then he tries to point this pointer to all registered extension types (using dynamic_cast, therefore, classes for extension types all inherit from some polymorphic base class). If casting to some type of extension is successful, then a cast pointer is used when calling a special handler for this type of extension.
The number of extension types is known at compile time (while, obviously, the number of extensions is infinite). Using my aproach, the loader class uses this knowledge to check if a handler exists for each type of extension (if not, the program does not compile). Also, my aproach does not force classes for extension types to know anything about the loader (so it's easy to modify the loader). But it would be more convenient if each type of extension registered itself.
source
share