File size: 1,125 Bytes
d1be154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef OT_UTILITY_SINGLETON_HPP_
#define OT_UTILITY_SINGLETON_HPP_

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <memory>

namespace ot {

// Class: EnableSingletonFromThis
// Guarantees that only a single instance of an object will exist throughout the
// lifetime of the program.
template <typename Derived>
class EnableSingletonFromThis {
    
  public:

    static Derived& get(); 

  protected:
    
    EnableSingletonFromThis() = default; 
    ~EnableSingletonFromThis() = default;                                        

  private:
    
    //EnableSingletonFromthis(const EnableSingletonFromThis&) = delete;
    //EnableSingletonFromthis(EnableSingletonFromThis&&) = delete;
    EnableSingletonFromThis & operator = (const EnableSingletonFromThis&) = delete;      
    EnableSingletonFromThis & operator = (EnableSingletonFromThis&&) = delete;   
};

// Function: get
template <typename Derived>
Derived& EnableSingletonFromThis<Derived>::get() {
  static Derived object;
  return object;
}

};  // End of ot namespace. --------------------------------------------------------------

#endif