Hermes  0.9.5-beta
Hierarchical Distributed I/O Buffering System
singleton.h
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Distributed under BSD 3-Clause license. *
3  * Copyright by The HDF Group. *
4  * Copyright by the Illinois Institute of Technology. *
5  * All rights reserved. *
6  * *
7  * This file is part of Hermes. The full Hermes copyright notice, including *
8  * terms governing use, modification, and redistribution, is contained in *
9  * the COPYING file, which can be found at the top directory. If you do not *
10  * have access to the file, you may request a copy from help@hdfgroup.org. *
11  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12 
13 #ifndef HERMES_ADAPTER_SINGLETON_H
14 #define HERMES_ADAPTER_SINGLETON_H
15 
16 #include <iostream>
17 #include <memory>
18 #include <utility>
24 namespace hermes {
25 template <typename T>
29 class Singleton {
30  public:
36  template <typename... Args>
37  static T* GetInstance(Args... args) {
38  if (instance == nullptr)
39  instance = std::make_unique<T>(std::forward<Args>(args)...);
40  return instance.get();
41  }
42 
46  Singleton& operator=(const Singleton) = delete; /* deleting = operators*/
47 
48  public:
52  Singleton(const Singleton&) = delete; /* deleting copy constructor. */
53 
54  protected:
58  static std::unique_ptr<T> instance;
59  Singleton() {} /* hidden default constructor. */
60 };
61 
62 template <typename T>
63 std::unique_ptr<T> Singleton<T>::instance = nullptr;
64 } // namespace hermes
65 #endif // HERMES_ADAPTER_SINGLETON_H
Definition: singleton.h:29
Singleton & operator=(const Singleton)=delete
static T * GetInstance(Args... args)
Definition: singleton.h:37
static std::unique_ptr< T > instance
Definition: singleton.h:58
Singleton(const Singleton &)=delete
Definition: adapter_utils.cc:35