oh_my_loam/common/macro/macros.h

31 lines
1.5 KiB
C
Raw Normal View History

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>
2021-01-04 21:26:09 +08:00
// format timestamp
#define FMT_TIMESTAMP(timestamp) \
2020-10-16 20:49:26 +08:00
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;
2021-01-04 21:26:09 +08:00
// adapted form baidu apollo cyber/common/macros.h
2020-10-16 00:22:03 +08:00
#define DECLARE_SINGLETON(classname) \
public: \
2020-10-16 18:08:31 +08:00
static classname *Instance() { \
2020-11-02 01:12:53 +08:00
static std::unique_ptr<classname> instance{nullptr}; \
2020-10-16 00:22:03 +08:00
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)