Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Class Registration Example

Interface Dynamic Library

Create class having a structure for passing arguments to the derived class on creation.

Interface Header

++
class DL_EXPORT RuntimeIface
{
public:
struct Parameters
{
explicit Parameters(int h) : Handle(h) {}
int Handle;
};
explicit RuntimeIface(const Parameters& params) = default;
virtual ~RuntimeIface();
virtual const char* getString() = 0;
// Declare the interface function.
SF_DECL_IFACE(RuntimeIface, RuntimeIface::Parameters, Interface)
};
#define SF_DECL_IFACE(InterfaceType, ParamType, FuncName)
Declares a public static function in the class where it is used.
Definition TClassRegistration.h:79

Interface Code

Only line using a macro for implementing the interface class.

++
SF_IMPL_IFACE(RuntimeIface, RuntimeIface::Parameters, Interface)
#define SF_IMPL_IFACE(InterfaceType, ParamType, FuncName)
Implements the public static function in the class where it is used.
Definition TClassRegistration.h:90

Implementation Dynamic Library

Implementation Header

++
class RuntimeLibImplementationA : public RuntimeIface
{
public:
explicit RuntimeLibImplementationA(const Parameters& params);
const char* getString() override;
private:
std::string FMessage;
};

Implementation Code

This _DL_INFORMATION(...) library information into the target.
See sf::DynamicLibraryInfo

++
// Declaration of the dynamic library information.
SF_DL_INFORMATION("Implementation Library A",
R"(This is the description of the library and what it contains.
A second line of a multi lined description.)"
)
// Register this derived class.
(
RuntimeIface, RuntimeIface::Parameters, Interface,
RuntimeLibImplementationA, "Class-A", "Actual name of the class."
)
RuntimeLibImplementationA::RuntimeLibImplementationA(const RuntimeIface::Parameters& params)
: RuntimeIface(params)
{
SF_RTTI_NOTIFY(DO_CLOG, "Constructed: " << sf::string_format("Handle(%d)", params.Handle))
}
const char* RuntimeLibImplementationA::getString()
{
SF_RTTI_NOTIFY(DO_CLOG, "Calling(" << Interface().RegisterName(this) << "): " << __FUNCTION__)
FMessage = sf::string_format("Greetings from Class '%s' created by name '%s' ", _RTTI_TYPENAME.c_str(),
Interface().RegisterName(this).c_str());
return FMessage.c_str();
}
#define SF_DL_INFORMATION(name, description)
Definition TClassRegistration.h:27
#define SF_REG_CLASS(InterfaceType, ParamType, FuncName, DerivedType, RegName, Description)
Registers a derived type from the interface type.
Definition TClassRegistration.h:105
#define SF_RTTI_NOTIFY(f, a)
Definition dbgutils.h:265
#define DO_CLOG
Definition dbgutils.h:246
std::string string_format(const std::string &format, Args &&... args)
Better implementation of 'stringf' ?
Definition string.h:145