zenilib: zenilib/jni/external/zenilib/zeni/Zeni/Singleton.hxx Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
26 bool Singleton<TYPE>::is_initialized() {
27 return g_type != 0;
28 }
29
30 template <typename TYPE>
31 TYPE & Singleton<TYPE>::get() {
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>
42 void Singleton<TYPE>::destroy() {
43 pre_uninit.fire();
44
45 delete g_type;
46 g_type = 0;
47 }
48
49 template <typename TYPE>
50 void Singleton<TYPE>::completely_destroy() {
51 destroy();
52 clear();
53 }
54
55 template <typename TYPE>
56 void Singleton<TYPE>::lend_pre_uninit(Event::Handler * const &handler) {
57 pre_uninit.lend_Handler(handler);
58 }
59
60 template <typename TYPE>
61 void Singleton<TYPE>::give_pre_uninit(Event::Handler * const &handler) {
62 pre_uninit.give_Handler(handler);
63 }
64
65 template <typename TYPE>
66 void Singleton<TYPE>::fax_pre_uninit(Event::Handler * const &handler) {
67 pre_uninit.fax_Handler(handler);
68 }
69
70 template <typename TYPE>
71 void Singleton<TYPE>::remove_pre_uninit(Event::Handler * const &handler) {
72 pre_uninit.remove_Handler(handler);
73 }
74
75 template <typename TYPE>
76 void Singleton<TYPE>::lend_post_reinit(Event::Handler * const &handler) {
77 post_reinit.lend_Handler(handler);
78 }
79
80 template <typename TYPE>
81 void Singleton<TYPE>::give_post_reinit(Event::Handler * const &handler) {
82 post_reinit.give_Handler(handler);
83 }
84
85 template <typename TYPE>
86 void Singleton<TYPE>::fax_post_reinit(Event::Handler * const &handler) {
87 post_reinit.fax_Handler(handler);
88 }
89
90 template <typename TYPE>
91 void Singleton<TYPE>::remove_post_reinit(Event::Handler * const &handler) {
92 post_reinit.remove_Handler(handler);
93 }
94
95 template <typename TYPE>
96 void Singleton<TYPE>::uninit() {
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
Zeni::Singleton
Definition: Singleton.h:31
Zeni::Event::clear
void clear()
Definition: Event.h:71
Zeni::Singleton::is_initialized
static bool is_initialized()
Definition: Singleton.hxx:26
Zeni::Singleton::remove_post_reinit
static void remove_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:91
Zeni::Singleton::lend_post_reinit
void lend_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:76
Zeni::Singleton::lend_pre_uninit
void lend_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:56
Zeni::Singleton::completely_destroy
static void completely_destroy()
Definition: Singleton.hxx:50
Zeni::Singleton::remove_pre_uninit
static void remove_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:71
Zeni::Singleton::get
static TYPE & get()
Definition: Singleton.hxx:31
Zeni::Singleton::fax_post_reinit
void fax_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:86
destroy
local int destroy(gz_stream *s)
Definition: gzio.c:355
Zeni::Singleton::fax_pre_uninit
void fax_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:66
Zeni::Singleton::give_pre_uninit
void give_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:61
Zeni::Event::Handler
Definition: Event.h:27
Singleton.h
Zeni::Singleton::destroy
static void destroy()
Definition: Singleton.hxx:42
TYPE
Definition: infutil.h:15
Zeni::Singleton::give_post_reinit
void give_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:81