12#define SF_DL_NAME_FUNC_NAME "_dl_name_"
13#define SF_DL_NAME_FUNC _dl_name_
17 #define SF_DL_STRING_COPY(dest, src, sz) strncpy_s(dest, sz, src, sz)
19 #define SF_DL_STRING_COPY(dest, src, sz) strncpy(dest, src, sz)
26#define SF_DL_INFORMATION(name, description) \
29 const char* _dl_ = SF_DL_MARKER_BEGIN name SF_DL_NAME_SEPARATOR description SF_DL_MARKER_END; \
31 extern "C" TARGET_EXPORT const char* SF_DL_NAME_FUNC(const char* nm) \
33 static char storage[256]; \
35 SF_DL_STRING_COPY(storage, nm, sizeof(storage)); \
48#define SF_DL_NAME_FUNC_TYPE const char* (*) (const char*)
71#define SF_DECL_IFACE(InterfaceType, ParamType, FuncName) \
73 std::string _Register_Name_; \
76 static sf::TClassRegistration<InterfaceType, ParamType> FuncName(); \
77 friend class sf::TClassRegistration<InterfaceType, ParamType>;
82#define SF_IMPL_IFACE(InterfaceType, ParamType, FuncName) \
83 sf::TClassRegistration<InterfaceType, ParamType> InterfaceType::FuncName() \
85 static sf::TClassRegistration<InterfaceType, ParamType>::entries_t entries; \
86 return sf::TClassRegistration<InterfaceType, ParamType>(entries); \
96#define SF_REG_CLASS(InterfaceType, ParamType, FuncName, DerivedType, RegName, Description) \
99 __attribute__((constructor)) void _## DerivedType## _() \
101 size_t dist = InterfaceType::FuncName().registerClass( \
102 RegName, Description, sf::TClassRegistration<InterfaceType, ParamType>::callback_t([](const ParamType& params) -> InterfaceType* { \
103 auto inst = new DerivedType(params); \
104 sf::TClassRegistration<InterfaceType, ParamType>::setRegisterName(inst, RegName); \
122template<
typename T,
typename P>
143 static auto constexpr npos = std::numeric_limits<size_t>::max();
168 _entries = inst._entries;
187 [[nodiscard]]
size_t indexOf(
const std::string& name)
const;
195 T*
create(
const std::string& name,
const P& params = P{})
const;
203 T*
create(
size_t index,
const P& params = P{})
const;
209 [[nodiscard]]
size_t size()
const;
217 inst->_Register_Name_ = name;
228 [[nodiscard]]
const char*
getName(
size_t index)
const;
264 const char* _description;
279 const entry_t* find(
const std::string& name)
const;
289 typename entries_t::const_iterator lookup(
const std::string& name)
const;
295#include <misc/gen/TClassRegistration.hpp>
#define SF_DL_NAME_FUNC
Definition TClassRegistration.h:13
Type of registered entry in the list.
Definition TClassRegistration.h:244
entry_t(const char *name, const char *description, const callback_t &callback)
Constructor.
entry_t(const entry_t &e)
Copy constructor.
Template class used to register derived classes from a (virtual) interface class. Registering name an...
Definition TClassRegistration.h:124
TClosure< T *, const P & > callback_t
Definition TClassRegistration.h:128
size_t registerClass(const char *name, const char *description, const callback_t &callback)
Register a derived class.
TClassRegistration self_t
Definition TClassRegistration.h:127
const char * getName(size_t index) const
Gets the name of the class from the passed index.
TClassRegistration(entries_t &entries)
Constructor for the base class.
T * create(const std::string &name, const P ¶ms=P{}) const
Find and create registered class by name.
static auto constexpr npos
Index value for when not found.
Definition TClassRegistration.h:143
strings_t getNames() const
Gets the all the registered names.
const char * getDescription(size_t index) const
Returns the description of the class from the passed index.
size_t size() const
Returns the amount of registered entries.
TClassRegistration & operator=(const TClassRegistration &inst)
Assignment operator.
Definition TClassRegistration.h:163
TClassRegistration(const TClassRegistration &inst)
Copy constructor.
T * create(size_t index, const P ¶ms=P{}) const
Function create registered class by index.
const std::string & getRegisterName(T *inst) const
Gets the register name of the passed.
TVector< std::string > strings_t
Type used to report the list of implementations in.
Definition TClassRegistration.h:138
std::vector< entry_t > entries_t
Vector type to register implementations in.
Definition TClassRegistration.h:133
size_t indexOf(const std::string &name) const
Find a registered class structure index. When not found it returns.
TClassRegistration(TClassRegistration &&inst) noexcept
Move constructor.
static void setRegisterName(T *inst, const char *name)
Sets the register name on the passed instance. This automatically is called from the callback_t when ...
Definition TClassRegistration.h:215
Encapsulates the std::function() template.
Definition TClosure.h:14
Counted vector having additional methods and operators for ease of usage.
Definition TVector.h:25
Definition Application.h:10
std::string getLibraryName()
function to get the library filename this function is called from.
Definition TClassRegistration.h:56