Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9660 in orxonox.OLD for trunk/src/lib/lang/new_class_list.h


Ignore:
Timestamp:
Aug 20, 2006, 11:50:41 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: dynamic class ID is on its way

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/new_class_list.h

    r9659 r9660  
    11/*!
    2  * @file new_class_id.h
     2 * @file new_class_list.h
    33 * @brief Definition of a dynamically allocating ClassID
    44 *
    55 */
    66
    7 #ifndef _NEW_CLASS_ID_H
    8 #define _NEW_CLASS_ID_H
     7#ifndef _NEW_CLASS_LIST_H
     8#define _NEW_CLASS_LIST_H
    99
    1010#include "type_info.h"
     
    1313
    1414#define DeclareClass(ClassName) \
    15    ClassIDDeclaration ClassID_##ClassName(ClassName)
     15   NewClassList ClassID_##ClassName(ClassName)
    1616
    17 class ClassIDDeclaration
     17#define DeclareInClass(ClassName) \
     18   NewClassList classList(ClassName)
     19
     20class NewClassListBase
    1821{
    19   friend class NewClassID;
    2022public:
    21   ClassIDDeclaration(const std::string& name);
    22   ~ClassIDDeclaration();
    23 
    2423  int id() const { return _id; };
    2524  const std::string& name() const { return _name; };
    2625
     26  static int classCount() { return _idCounter; };
     27
     28protected:
     29  NewClassListBase(const std::string& className);
     30private:
     31  NewClassListBase(const NewClassListBase&);
     32
     33
     34private:
     35  int                           _id;
     36  std::string                   _name;
     37
     38private:
     39  static int                           _idCounter;      //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe.
     40  static std::set<NewClassListBase>    _classes;        //!< A Set of all the classes in existance.
     41};
     42
     43template<class T> class NewClassList : public NewClassListBase
     44{
     45public:
     46  NewClassList(const std::string& name);
     47  ~NewClassList();
     48
    2749private:
    2850  //! the copy constructor will be hidden.
    29   ClassIDDeclaration(const ClassIDDeclaration& definer) {};
    30 
    31 private:
    32   int                   _id;
    33   std::string           _name;
     51  NewClassList(const NewClassList& definer) {};
    3452};
    3553
     54template <class T>
     55NewClassList<T>::NewClassList(const std::string& name)
     56    : NewClassListBase(name)
     57{}
    3658
    37 //! A class to dynamically allocate ClassID's and support a isA operator
    38 class NewClassID
    39 {
    40 public:
    41   NewClassID();
    42   ~NewClassID();
     59template <class T>
     60NewClassList<T>::~NewClassList()
     61{}
    4362
    4463
    45 
    46   static int classCount() { return _idCounter; };
    47   static void registerClass(ClassIDDeclaration* namer);
    48   static void unregisterClass(ClassIDDeclaration* namer);
    49 
    50 private:
    51   std::set<ClassIDDeclaration>  _types;
    52   std::string                   _className;
    53 
    54   static int                    _idCounter;      //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe.
    55 };
    56 
    57 
    58 #endif /* _NEW_CLASS_ID_H */
     64#endif /* _NEW_CLASS_LIST_H */
Note: See TracChangeset for help on using the changeset viewer.