zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Singleton.hxx
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ZENI_SINGLETON_HXX
19 #define ZENI_SINGLETON_HXX
20 
21 #include <Zeni/Singleton.h>
22 
23 namespace Zeni {
24 
25  template <typename TYPE>
27  return g_type != 0;
28  }
29 
30  template <typename TYPE>
32  if(!g_type) {
33  g_type = TYPE::create();
34 
35  post_reinit.fire();
36  }
37 
38  return *g_type;
39  }
40 
41  template <typename TYPE>
43  pre_uninit.fire();
44 
45  delete g_type;
46  g_type = 0;
47  }
48 
49  template <typename TYPE>
51  destroy();
52  clear();
53  }
54 
55  template <typename TYPE>
57  pre_uninit.lend_Handler(handler);
58  }
59 
60  template <typename TYPE>
62  pre_uninit.give_Handler(handler);
63  }
64 
65  template <typename TYPE>
67  pre_uninit.fax_Handler(handler);
68  }
69 
70  template <typename TYPE>
72  pre_uninit.remove_Handler(handler);
73  }
74 
75  template <typename TYPE>
77  post_reinit.lend_Handler(handler);
78  }
79 
80  template <typename TYPE>
82  post_reinit.give_Handler(handler);
83  }
84 
85  template <typename TYPE>
87  post_reinit.fax_Handler(handler);
88  }
89 
90  template <typename TYPE>
92  post_reinit.remove_Handler(handler);
93  }
94 
95  template <typename TYPE>
97  pre_uninit.fire();
98  }
99 
100  template <typename TYPE>
101  void Singleton<TYPE>::reinit() {
102  post_reinit.fire();
103  }
104 
105  template <typename TYPE>
106  void Singleton<TYPE>::Uninit::operator()() {
107  TYPE::destroy();
108  }
109 
110  template <typename TYPE>
111  typename Singleton<TYPE>::Uninit * Singleton<TYPE>::Uninit::duplicate() const {
112  return new Uninit;
113  }
114 
115  template <typename TYPE>
116  void Singleton<TYPE>::Reinit::operator()() {
117  TYPE::get();
118  }
119 
120  template <typename TYPE>
121  typename Singleton<TYPE>::Reinit * Singleton<TYPE>::Reinit::duplicate() const {
122  return new typename Singleton<TYPE>::Reinit;
123  }
124 
125  template <typename TYPE>
126  void Singleton<TYPE>::clear() {
127  pre_uninit.clear();
128  post_reinit.clear();
129  }
130 
131 }
132 
133 #endif
void clear()
Definition: Event.h:71
static bool is_initialized()
Definition: Singleton.hxx:26
static void remove_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:91
void lend_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:76
void lend_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:56
static void completely_destroy()
Definition: Singleton.hxx:50
static void remove_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:71
static TYPE & get()
Definition: Singleton.hxx:31
void fax_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:86
local int destroy(gz_stream *s)
Definition: gzio.c:355
void fax_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:66
void give_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:61
static void destroy()
Definition: Singleton.hxx:42
Definition: infutil.h:15
void give_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:81