singleton.cti
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 
14 /** \file
15  \brief singleton inline template implementation */
16 
17 //#include "singleton.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 template <class Self>
25 prefix_ senf::singleton<Self>::singleton()
26 {
27  alive_ = true;
28 }
29 
30 template <class Self>
31 prefix_ senf::singleton<Self>::~singleton()
32 {
33  alive_ = false;
34 }
35 
36 template <class Self>
37 bool senf::singleton<Self>::alive_ (false);
38 
39 template <class Self>
40 prefix_ Self & senf::singleton<Self>::instance()
41 {
42  static Self instance_;
43  // Force instantiation of force_creation (at static object creation time)
44  creator_.nop();
45  return instance_;
46 }
47 
48 template <class Self>
49 prefix_ bool senf::singleton<Self>::alive()
50 {
51  return alive_;
52 }
53 
54 template <class Self>
55 prefix_ senf::singleton<Self>::force_creation::force_creation()
56 {
57  // Force execution of instance() thereby creating instance
58  senf::singleton<Self>::instance();
59 }
60 
61 template <class Self>
62 prefix_ void senf::singleton<Self>::force_creation::nop()
63  const
64 {
65  // No operation ...
66 }
67 
68 template <class Self>
69 typename senf::singleton<Self>::force_creation senf::singleton<Self>::creator_;
70 
71 //-/////////////////////////////////////////////////////////////////////////////////////////////////
72 #undef prefix_
73 
74 
75 // Local Variables:
76 // mode: c++
77 // fill-column: 100
78 // c-file-style: "senf"
79 // indent-tabs-mode: nil
80 // ispell-local-dictionary: "american"
81 // compile-command: "scons -u test"
82 // comment-column: 40
83 // End: