#pragma once #include #include #include template class DLWrapper { private: std::map funcs; public: void append(std::string name, void* ptr) { if(ptr) { funcs.insert({name, ptr}); } } void remove(std::string name) { for(auto it = funcs.begin(); it != funcs.end(); ) { if(it->first == name) { it = funcs.erase(it); return; } else { ++it; } } } template void operator()(Args... args) const { for(auto fun : funcs) { (T)(fun)(args...); } } }; /* the addon handler loads addon shared library objects and calls in every loaded addon the implemented events, when they're implemented. */ class AddonHandler { private: //list of loaded addons with library pointer std::map loaded_addon_paths; std::map loaded_addon_libs; public: AddonHandler(); // loads an addon and returns it's name, if successfully loaded std::optional load(std::filesystem::path path); // unload an addon void unload(std::string name); // returns whether an addon with name is loaded bool isLoaded(std::string name); // returns the list of loaded addons (name, path) std::map loadedAddons(); DLWrapper on_request; DLWrapper on_response; };