Maze Builder Docs 8.2.1
Loading...
Searching...
No Matches
singleton_base.h
Go to the documentation of this file.
1#ifndef SINGLETON_BASE_H
2#define SINGLETON_BASE_H
3
4#include <memory>
5
8namespace mazes
9{
12 template <typename T>
14 {
15 public:
16 // Deleted copy constructor and assignment operator to prevent copying
17 singleton_base(const singleton_base&) = delete;
18 singleton_base& operator=(const singleton_base&) = delete;
19
20 // Deleted move constructor and assignment operator to prevent moving
22 singleton_base& operator=(singleton_base&&) = delete;
23
24 // Static method to access the singleton instance
25 template <typename... Args>
26 static std::shared_ptr<T>& instance(Args&&... args) noexcept
27 {
28 static std::shared_ptr<T> instance = std::make_shared<T>(std::forward<Args>(args)...);
29 return instance;
30 }
31
32 protected:
33 // Private constructor to prevent instantiation from outside the class
34 singleton_base() = default;
35
36 // Private destructor to prevent deletion from outside the class
37 virtual ~singleton_base() = default;
38 };
39} // namespace mazes
40
41#endif // SINGLETON_BASE_H
Command-line argument handler with JSON support.
Definition args.h:19
Base class for implementing the singleton pattern.
Definition singleton_base.h:14