// license:GPL-2.0+ // copyright-holders:Couriersud #ifndef PDYNLIB_H_ #define PDYNLIB_H_ /// /// \file pdynlib.h /// #include "pstring.h" #include "ptypes.h" namespace plib { // ---------------------------------------------------------------------------------------- // pdynlib: dynamic loading of libraries ... // ---------------------------------------------------------------------------------------- class dynlib : public nocopyassignmove { public: explicit dynlib(const pstring &libname); dynlib(const pstring &path, const pstring &libname); ~dynlib(); COPYASSIGNMOVE(dynlib, delete) bool isLoaded() const { return m_isLoaded; } template T getsym(const pstring &name) const noexcept { return reinterpret_cast(getsym_p(name)); } private: void *getsym_p(const pstring &name) const noexcept; bool m_isLoaded; void *m_lib; }; template class dynproc { public: using calltype = R(*) (Args... args); dynproc() : m_sym(nullptr) { } dynproc(dynlib &dl, const pstring &name) noexcept { m_sym = dl.getsym(name); } void load(dynlib &dl, const pstring &name) noexcept { m_sym = dl.getsym(name); } R operator ()(Args&&... args) const { return m_sym(std::forward(args)...); //return m_sym(args...); } bool resolved() const noexcept { return m_sym != nullptr; } private: calltype m_sym; }; } // namespace plib #endif // PSTRING_H_