Midge  v3.9.2
Data Processing Framework
initializer.hh
Go to the documentation of this file.
1 #ifndef _midge_initializer_hh_
2 #define _midge_initializer_hh_
3 
4 #include <cstddef>
5 
6 
7 namespace midge
8 {
9 
10  template< class x_type >
12  {
13  public:
14  initializer();
15  ~initializer();
16 
17  private:
18  static x_type* f_instance;
19  static int f_count;
20 
21  public:
22  static char f_data[ sizeof(x_type) ];
23  };
24 
25  template< class x_type >
26  char initializer< x_type >::f_data[ sizeof(x_type) ] =
27  { };
28 
29  template< class x_type >
31 
32  template< class x_type >
33  x_type* initializer< x_type >::f_instance = NULL;
34 
35  template< class x_type >
37  {
38  if( 0 == f_count++ )
39  {
40  f_instance = new ( (x_type*) (&f_data) ) x_type();
41  }
42  }
43  template< class x_type >
45  {
46  if( 0 == --f_count )
47  {
48  f_instance->~x_type();
49  }
50  }
51 
52 }
53 
54 #endif
Definition: _buffer.hh:11
static char f_data[sizeof(x_type)]
Definition: initializer.hh:22
static x_type * f_instance
Definition: initializer.hh:18
static int f_count
Definition: initializer.hh:19