drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::DrClassMap Class Reference

A map class which can create DrObjects from names. More...

#include <drogon/DrClassMap.h>

Static Public Member Functions

static void registerClass (const std::string &className, const DrAllocFunc &func, const DrSharedAllocFunc &sharedFunc=nullptr)
 Register a class into the map.
static DrObjectBasenewObject (const std::string &className)
 Create a new instance of the class named by className.
static std::shared_ptr< DrObjectBasenewSharedObject (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.
template<typename T>
static std::shared_ptr< T > getSingleInstance ()
 Get the singleton T type object.
static void setSingleInstance (const std::shared_ptr< DrObjectBase > &ins)
 Set a singleton object into the map.
static std::vector< std::string > getAllClassName ()
 Get all names of classes registered in the map.
static std::string demangle (const char *mangled_name)
 demangle the type name which is returned by typeid(T).name().

Static Protected Member Functions

static std::unordered_map< std::string, std::pair< DrAllocFunc, DrSharedAllocFunc > > & getMap ()

Detailed Description

A map class which can create DrObjects from names.

Member Function Documentation

◆ demangle()

std::string drogon::DrClassMap::demangle ( const char * mangled_name)
inlinestatic

demangle the type name which is returned by typeid(T).name().

Parameters
mangled_nameThe type name which is returned by typeid(T).name().
Returns
std::string The human readable type name.

◆ getAllClassName()

std::vector< std::string > drogon::DrClassMap::getAllClassName ( )
static

Get all names of classes registered in the map.

Returns
std::vector<std::string> the vector of class names.

◆ getSingleInstance() [1/2]

template<typename T>
std::shared_ptr< T > drogon::DrClassMap::getSingleInstance ( )
inlinestatic

Get the singleton T type object.

Template Parameters
TThe type of the class
Returns
std::shared_ptr<T> The smart pointer to the instance.
Note
The T must be a subclass of the DrObjectBase class.

◆ getSingleInstance() [2/2]

const std::shared_ptr< DrObjectBase > & drogon::DrClassMap::getSingleInstance ( const std::string & className)
static

Get the singleton object of the class named by className.

Parameters
classNameThe name of the class
Returns
const std::shared_ptr<DrObjectBase>& The smart pointer to the instance.

◆ newObject()

DrObjectBase * drogon::DrClassMap::newObject ( const std::string & className)
static

Create a new instance of the class named by className.

Parameters
classNameThe name of the class
Returns
DrObjectBase* The pointer to the newly created instance.

◆ registerClass()

void drogon::DrClassMap::registerClass ( const std::string & className,
const DrAllocFunc & func,
const DrSharedAllocFunc & sharedFunc = nullptr )
static

Register a class into the map.

Parameters
classNameThe name of the class
funcThe function which can create a new instance of the class.

◆ setSingleInstance()

void drogon::DrClassMap::setSingleInstance ( const std::shared_ptr< DrObjectBase > & ins)
static

Set a singleton object into the map.

Parameters
insThe smart pointer to the instance.

The documentation for this class was generated from the following file: