14 #include "ReferenceTo.h"
21 template< class Parent> class List;
24 template< class Parent>
29 friend class List<Parent>;
32 Parent* get () const { return instance; }
35 Entry () { instance = 0; }
38 virtual ~Entry () { if (instance) delete instance; }
48 std::cerr << "Registry::Entry<Parent>::register_child"
49 " instance=" << _instance << " registry=" << ®istry <<
50 " size=" << registry. size() + 1 << std::endl;
57 virtual Parent* create () const = 0;
64 template< class Parent>
68 friend class Entry<Parent>;
73 template< class Child> class Instances;
76 template< class Child> class Enter;
79 template< class Child, class Argument> class Unary;
91 Parent* create ( unsigned i) const { return entries[i]->create(); }
106 std::vector< Reference::To< Entry<Parent> > > entries;
115 template< class Parent>
116 template< class Child>
120 static unsigned get_instances () { return instances; }
121 static void add_instance () { instances++; }
123 static unsigned instances;
127 template< class Parent>
128 template< class Child>
129 class List<Parent>::Enter : public Entry<Parent>
135 if (Instances<Child>::get_instances() == 0)
136 this->register_child ( new Child);
137 Instances<Child>::add_instance();
142 Parent* create () const { return new Child; }
146 template< class Parent>
147 template< class Child, class Argument>
153 Unary ( const Argument& arg)
157 this->register_child( new Child(arg) );
162 Parent* create () const { return new Child(argument); }
170 template< class Parent>
171 template< class Child>
174 template< class Parent>
177 template< class Parent>
180 template< class Parent>
static List * registry The single registry instance for the Parent class. Definition: Registry.h:114
Entry() Null constructor. Definition: Registry.h:40
Parent * get() const Return the pointer to the instance. Definition: Registry.h:37
void add(Entry< Parent > *entry) Add an entry to the registry. Definition: Registry.h:108
virtual Parent * create() const =0 Return a pointer to a new instance of a Parent (or its children)
static bool verbose verbosity flag used for debugging Definition: Registry.h:99
std::vector< Reference::To< Entry< Parent > > > entries The vector of registry entries. Definition: Registry.h:111
Parent * create(unsigned i) const Return pointer to a null-constructed instance of Parent class. Definition: Registry.h:96
Template class manages Reference::Able objects. Definition: Reference.h:74
static List & get_registry() provide access to the single registry instance Definition: Registry.h:102
unsigned size() const Return the size of the list. Definition: Registry.h:87
Manages Reference::To references to the instance. Definition: ReferenceAble.h:40
void erase(unsigned i) Remove the specified entry. Definition: Registry.h:93
Pure virtual template base class of Registry::List<Parent>::Enter<Child> Definition: Registry.h:30
void register_child(Parent *_instance) Adds this instance to the Parent::Registry::List<Parent> Definition: Registry.h:48
List of Registry::Entry. Definition: Registry.h:26
Counts the number of instances of Child entries. Definition: Registry.h:78
static Reference::To< List > auto_delete Clean up the registry when the program exits. Definition: Registry.h:117
Enter Child with unary constructor into Registry::List<Parent> Definition: Registry.h:84
virtual ~Entry() Destructor deletes instance of Parent. Definition: Registry.h:43
Parent * operator[](unsigned i) const Return the specified entry. Definition: Registry.h:90
Generated using doxygen 1.8.17
|