Function getSingleInstance

Summary

#include <lib/inc/drogon/DrClassMap.h>

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

(2) template <typename T>
    static std::shared_ptr< T > getSingleInstance()

Function overload

Synopsis

#include <lib/inc/drogon/DrClassMap.h>

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

Description

Get the singleton object of the class named by className.

Parameters:

className - The name of the class

Return
const std::shared_ptr<DrObjectBase>& The smart pointer to the instance.

Source

Line 66 in lib/inc/drogon/DrClassMap.h.

Synopsis

#include <lib/inc/drogon/DrClassMap.h>

template <typename T>
static std::shared_ptr< T > getSingleInstance()

Description

Get the singleton T type object.

Template Parameters:

T - The type of the class

Return
std::shared_ptr<T> The smart pointer to the instance.
Note
The T must be a subclass of the DrObjectBase class.

Source

Lines 76-85 in lib/inc/drogon/DrClassMap.h.

template <typename T>
static std::shared_ptr<T> getSingleInstance()
{
    static_assert(std::is_base_of<DrObjectBase, T>::value,
                  "T must be a sub-class of DrObjectBase");
    static auto const singleton =
        std::dynamic_pointer_cast<T>(getSingleInstance(T::classTypeName()));
    assert(singleton);
    return singleton;
}





Add Discussion as Guest

Log in to DocsForge