Loading...
Searching...
No Matches
Go to the documentation of this file.
27#undef CUTL_COPY_AND_ASSIGN
28#define CUTL_COPY_AND_ASSIGN(classname) \
29 classname(const classname &) = delete; \
30 classname &operator=(const classname &) = delete;
36#undef CUTL_SINGLETON_PTR
37#define CUTL_SINGLETON_PTR(classname) \
39 static classname *get_instance(bool create_if_needed = true) \
41 static classname *obj = nullptr; \
42 if (!obj && create_if_needed) \
44 static std::once_flag flag; \
45 std::call_once(flag, [&] { obj = new (std::nothrow) classname(); }); \
53 CUTL_COPY_AND_ASSIGN(classname)
59#undef CUTL_SINGLETON_PTR_DEFAULT_CTOR
60#define CUTL_SINGLETON_PTR_DEFAULT_CTOR(classname) \
62 static classname *get_instance(bool create_if_needed = true) \
64 static classname *obj = nullptr; \
65 if (!obj && create_if_needed) \
67 static std::once_flag flag; \
68 std::call_once(flag, [&] { obj = new (std::nothrow) classname(); }); \
75 classname() = default; \
76 CUTL_COPY_AND_ASSIGN(classname)
82#undef CUTL_SINGLETON_REF
83#define CUTL_SINGLETON_REF(classname) \
85 static classname &get_instance(bool create_if_needed = true) \
87 static classname obj; \
94 CUTL_COPY_AND_ASSIGN(classname)
100#undef CUTL_SINGLETON_REF_DEFAULT_CTOR
101#define CUTL_SINGLETON_REF_DEFAULT_CTOR(classname) \
103 static classname &get_instance(bool create_if_needed = true) \
105 static classname obj; \
111 classname() = default; \
112 CUTL_COPY_AND_ASSIGN(classname)