zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Singleton.h
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_H
19 #define ZENI_SINGLETON_H
20 
21 #ifdef _WINDOWS
22 #pragma warning (disable : 4231)
23 #pragma warning( disable : 4661 )
24 #endif
25 
26 #include <Zeni/Event.h>
27 
28 namespace Zeni {
29 
30  template <typename TYPE>
31  class Singleton {
32  // Undefined
33  Singleton(const Singleton &);
34  Singleton & operator=(const Singleton &);
35 
36  protected:
37  Singleton() {}
38 
39  virtual ~Singleton() {};
40 
41  public:
42  static bool is_initialized();
43 
44  static TYPE & get();
45 
46  static void destroy();
47  static void completely_destroy();
48 
49  void lend_pre_uninit(Event::Handler * const &handler);
50  void give_pre_uninit(Event::Handler * const &handler);
51  void fax_pre_uninit(Event::Handler * const &handler);
52  static void remove_pre_uninit(Event::Handler * const &handler);
53 
54  void lend_post_reinit(Event::Handler * const &handler);
55  void give_post_reinit(Event::Handler * const &handler);
56  void fax_post_reinit(Event::Handler * const &handler);
57  static void remove_post_reinit(Event::Handler * const &handler);
58 
59  class Uninit : public Event::Handler {
60  void operator()();
61 
62  Uninit * duplicate() const;
63  };
64 
65  class Reinit : public Event::Handler {
66  void operator()();
67 
68  Reinit * duplicate() const;
69  };
70 
71  private:
72  virtual void uninit();
73  virtual void reinit();
74 
75  static void clear();
76 
77  static TYPE * g_type;
78 
79  static Event pre_uninit;
80  static Event post_reinit;
81  };
82 
83  template <typename TYPE>
85 
86  template <typename TYPE>
88 
89  template <typename TYPE>
91 
92 }
93 
94 #endif
virtual ~Singleton()
Definition: Singleton.h:39
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
void fax_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:86
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