#include <iostream>
#include <memory>
#include <mutex>
#include <type_traits>
#include <utility>
#include "cyber/base/macros.h"
Go to the source code of this file.
|
template<typename T > |
std::enable_if< HasShutdown< T >::value >::type | CallShutdown (T *instance) |
|
template<typename T > |
std::enable_if<!HasShutdown< T >::value >::type | CallShutdown (T *instance) |
|
◆ DECLARE_SINGLETON
#define DECLARE_SINGLETON |
( |
|
classname | ) |
|
Value:public: \
static classname *
Instance(
bool create_if_needed =
true) { \
static classname *instance = nullptr; \
if (!instance && create_if_needed) { \
static std::once_flag flag; \
std::call_once(flag, \
[&] { instance = new (std::nothrow) classname(); }); \
} \
return instance; \
} \
\
if (instance != nullptr) { \
CallShutdown(instance); \
} \
} \
\
private: \
classname(); \
DISALLOW_COPY_AND_ASSIGN(classname)
◆ DISALLOW_COPY_AND_ASSIGN
#define DISALLOW_COPY_AND_ASSIGN |
( |
|
classname | ) |
|
Value:classname(const classname &) = delete; \
classname &operator=(const classname &) = delete;
◆ UNUSED
#define UNUSED |
( |
|
param | ) |
(void)param |
◆ CallShutdown() [1/2]
template<typename T >
std::enable_if<HasShutdown<T>::value>::type CallShutdown |
( |
T * |
instance | ) |
|
◆ CallShutdown() [2/2]
template<typename T >
std::enable_if<!HasShutdown<T>::value>::type CallShutdown |
( |
T * |
instance | ) |
|