UniqueObject.h
Go to the documentation of this file.
1 #ifndef _utl_UniqueObject_h_
2 #define _utl_UniqueObject_h_
3 
4 #include <sstream>
5 #include <utl/TypeId.h>
6 #include <utl/AugerException.h>
7 
8 
9 namespace utl {
10 
26  template<class T>
27  class UniqueObject {
28  public:
29  static
30  void
32  {
33  if (fgCounter != 1) {
34  std::stringstream err;
35  err << "Class " << TypeId<T>.Name() << " is not unique"
36  " (" << fgCounter << " instances)!";
37  throw utl::InitSequenceException(err.str());
38  }
39  }
40 
41  protected:
42  // derived class can call ctor and dtor
45 
46  // this is only for testing purposes
47  static void Reset() { fgCounter = 0; }
48 
49  private:
50  static int fgCounter = 0;
51 
52  };
53 
54 }
55 
56 
57 #endif
static void EnsureUnique()
Definition: UniqueObject.h:31
static int fgCounter
Definition: UniqueObject.h:50
Exception to use if sequence of initialisations violated.
Curiously Recurring Template Pattern (CRTP) for unique object.
Definition: UniqueObject.h:27
static void Reset()
Definition: UniqueObject.h:47

, generated on Tue Sep 26 2023.