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 static sf::TClassRegistration<InterfaceType, ParamType>::entry_t* current; \
87 return sf::TClassRegistration<InterfaceType, ParamType>(entries, current); \
97#define SF_REG_CLASS(InterfaceType, ParamType, FuncName, DerivedType, RegName, Description) \
100 __attribute__((constructor)) void _## DerivedType## _() \
102 size_t dist = InterfaceType::FuncName().registerClass( \
103 RegName, Description, sf::TClassRegistration<InterfaceType, ParamType>::callback_t([](const ParamType& params) -> InterfaceType* { \
104 auto inst = new DerivedType(params); \
105 sf::TClassRegistration<InterfaceType, ParamType>::setRegisterName(inst, RegName); \
123template<
typename T,
typename P>
145 static auto constexpr npos = std::numeric_limits<size_t>::max();
181 size_t indexOf(
const std::string& name)
const;
189 T*
create(
const std::string& name,
const P& params = P{})
const;
197 T*
create(
size_t index,
const P& params = P{})
const;
255 const char* _description;
270 const entry_t* find(
const std::string& name)
const;
275 typename entries_t::const_iterator lookup(
const std::string& name)
const;
286#include <misc/gen/TClassRegistration.hpp>
#define SF_DL_NAME_FUNC
Definition TClassRegistration.h:13
Type of registered entry in the list.
Definition TClassRegistration.h:235
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:125
TClosure< T *, const P & > callback_t
Callback closure type for creating instances.
Definition TClassRegistration.h:128
size_t registerClass(const char *name, const char *description, const callback_t &callback)
Register a derived class.
const char * getName(size_t index) const
Gets the name of the class from the passed index.
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:145
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.
std::string getRegisterName(const T *inst) const
Gets the register name of the passed instance.
TClassRegistration(const TClassRegistration &inst)
Copy constructor.
T * create(size_t index, const P ¶ms=P{}) const
Function create registered class by index.
TClassRegistration(entries_t &entries, entry_t *¤t)
Constructor for the base class.
TVector< std::string > strings_t
Type used to report the list of implementations in.
Definition TClassRegistration.h:140
std::vector< entry_t > entries_t
Vector type to register implementations in.
Definition TClassRegistration.h:135
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 ...
Encapsulates the std::function() template.
Definition TClosure.h:14
Counted vector having additional methods and operators for ease of usage. This template class extends...
Definition TVector.h:19
Definition Application.h:10
std::string getLibraryName()
function to get the library filename this function is called from.
Definition TClassRegistration.h:56