singleton.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Utils_singleton_
18 #define HH_SENF_Utils_singleton_ 1
19 
20 // Custom includes
21 #include <boost/noncopyable.hpp>
22 
23 //#include "singleton.mpp"
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 namespace senf {
27 
77  template <class Self>
78  class singleton
79  : boost::noncopyable
80  {
81  protected:
82  singleton();
83  ~singleton();
84 
85  static Self & instance();
86  static bool alive();
87 
88  private:
92  struct force_creation
93  {
94  force_creation();
95  void nop() const;
96  };
97 
98  static force_creation creator_;
99  static bool alive_;
100  };
101 
102 }
103 
104 //-/////////////////////////////////////////////////////////////////////////////////////////////////
105 //#include "singleton.cci"
106 //#include "singleton.ct"
107 #include "singleton.cti"
108 #endif
109 
110 
111 // Local Variables:
112 // mode: c++
113 // fill-column: 100
114 // c-file-style: "senf"
115 // indent-tabs-mode: nil
116 // ispell-local-dictionary: "american"
117 // compile-command: "scons -u test"
118 // comment-column: 40
119 // End:
static bool alive()
Return true, if instance ok, false otherwise.
Mark a class as singleton and provide singleton accessor.
Definition: singleton.hh:78
static Self & instance()
Return singleton instance.