17#include <drogon/exports.h>
18#include <trantor/utils/Logger.h>
23#include <unordered_map>
36using DrSharedAllocFunc = std::function<std::shared_ptr<DrObjectBase>()>;
51 const DrAllocFunc &func,
52 const DrSharedAllocFunc &sharedFunc =
nullptr);
66 const std::string &className);
76 const std::string &className);
88 static_assert(std::is_base_of<DrObjectBase, T>::value,
89 "T must be a sub-class of DrObjectBase");
90 static auto const singleton =
116 static std::string
demangle(
const char *mangled_name)
121 std::unique_ptr<char,
decltype(&std::free)> ptr(
122 __cxxabiv1::__cxa_demangle(mangled_name,
nullptr, &len, &status),
126 return std::string(ptr.get());
128 LOG_ERROR <<
"Demangle error!";
131 auto pos = strstr(mangled_name,
" ");
133 return std::string{mangled_name};
135 return std::string{pos + 1};
140 static std::unordered_map<std::string,
141 std::pair<DrAllocFunc, DrSharedAllocFunc>> &
A map class which can create DrObjects from names.
Definition DrClassMap.h:42
static std::string demangle(const char *mangled_name)
demangle the type name which is returned by typeid(T).name().
Definition DrClassMap.h:116
static void registerClass(const std::string &className, const DrAllocFunc &func, const DrSharedAllocFunc &sharedFunc=nullptr)
Register a class into the map.
static DrObjectBase * newObject(const std::string &className)
Create a new instance of the class named by className.
static std::shared_ptr< T > getSingleInstance()
Get the singleton T type object.
Definition DrClassMap.h:86
static std::vector< std::string > getAllClassName()
Get all names of classes registered in the map.
static void setSingleInstance(const std::shared_ptr< DrObjectBase > &ins)
Set a singleton object into the map.
static std::shared_ptr< DrObjectBase > newSharedObject(const std::string &className)
Get the shared_ptr instance of the class named by className.
static const std::shared_ptr< DrObjectBase > & getSingleInstance(const std::string &className)
Get the singleton object of the class named by className.
The base class for all drogon reflection classes.
Definition DrObject.h:34
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23