2020-10-16 00:22:03 +08:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-16 20:49:26 +08:00
|
|
|
#include <iomanip>
|
2020-10-16 00:22:03 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
|
2020-10-16 20:49:26 +08:00
|
|
|
// #define LOG_TIMESTAMP(timestamp, precision)
|
|
|
|
// std::fixed << std::precision(precision) << timestamp;
|
|
|
|
#define LOG_TIMESTAMP(timestamp) \
|
|
|
|
std::fixed << std::setprecision(3) << timestamp;
|
|
|
|
|
2020-10-16 18:08:31 +08:00
|
|
|
#define DISALLOW_COPY_AND_ASSIGN(classname) \
|
|
|
|
classname(const classname &) = delete; \
|
|
|
|
classname &operator=(const classname &) = delete;
|
|
|
|
|
2020-10-16 00:22:03 +08:00
|
|
|
// adapted form baidu apollo cyber/common/macros.h, it is thread safe
|
|
|
|
#define DECLARE_SINGLETON(classname) \
|
|
|
|
public: \
|
2020-10-16 18:08:31 +08:00
|
|
|
static classname *Instance() { \
|
2020-10-16 00:22:03 +08:00
|
|
|
static std::unique_ptr<classname> instance = nullptr; \
|
|
|
|
if (!instance) { \
|
|
|
|
static std::once_flag flag; \
|
|
|
|
std::call_once(flag, \
|
|
|
|
[&] { instance.reset(new (std::nothrow) classname()); }); \
|
|
|
|
} \
|
|
|
|
return instance.get(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
classname() = default; \
|
2020-10-16 18:08:31 +08:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(classname)
|