Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/lang/new_class_list.h @ 9661

Last change on this file since 9661 was 9661, checked in by bensch, 18 years ago

renamings

File size: 1.8 KB
Line 
1/*!
2 * @file new_class_list.h
3 * @brief Definition of a dynamically allocating ClassID
4 *
5 */
6
7#ifndef _NEW_CLASS_LIST_H
8#define _NEW_CLASS_LIST_H
9
10#include "type_info.h"
11#include <set>
12#include <string>
13
14#define DeclareClass(ClassName) \
15   NewObjectList ClassID_##ClassName(ClassName)
16
17#define DeclareInClass(ClassName) \
18   NewObjectList classList(ClassName)
19
20class NewObjectListBase
21{
22public:
23  int id() const { return _id; };
24  const std::string& name() const { return _name; };
25
26  static int classCount() { return _idCounter; };
27
28  bool compareName(const NewObjectListBase& more) { return this->_name < more.name(); };
29  bool compareID(const NewObjectListBase& more) { return this->_id < more.id(); };
30
31protected:
32  NewObjectListBase(const std::string& className);
33  ~NewObjectListBase();
34private:
35  NewObjectListBase(const NewObjectListBase&);
36
37  static bool exists(const std::string& className);
38
39private:
40  int                           _id;
41  std::string                   _name;
42
43private:
44  typedef std::set<NewObjectListBase*>  cList;
45
46  static int                           _idCounter;      //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe.
47  static cList*                        _classes;        //!< A Set of all the classes in existance.
48};
49
50
51/////////////////////////
52//// TEMPLATISATION /////
53/////////////////////////
54template<class T> class NewObjectList : public NewObjectListBase
55{
56public:
57  NewObjectList(const std::string& name);
58  ~NewObjectList();
59
60private:
61  //! the copy constructor will be hidden.
62  NewObjectList(const NewObjectList& definer) {};
63};
64
65template <class T>
66NewObjectList<T>::NewObjectList(const std::string& name)
67    : NewObjectListBase(name)
68{}
69
70template <class T>
71NewObjectList<T>::~NewObjectList()
72{}
73
74
75#endif /* _NEW_CLASS_LIST_H */
Note: See TracBrowser for help on using the repository browser.