Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9660 in orxonox.OLD for trunk


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

orxonox/trunk: dynamic class ID is on its way

Location:
trunk/src/lib
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/Makefile.am

    r9659 r9660  
    88                lang/class_list.cc \
    99                lang/new_class_id.cc \
     10                lang/new_class_list.cc \
    1011                \
    1112                coord/p_node.cc \
     
    1617                lang/base_object.h \
    1718                lang/class_list.h \
     19                lang/new_class_id.h \
     20                lang/new_class_list.h \
    1821                \
    1922                coord/p_node.h \
  • trunk/src/lib/lang/new_class_id.cc

    r9659 r9660  
    1919#include <cassert>
    2020
    21 ClassIDDeclaration::ClassIDDeclaration(const std::string& name)
    22   : _id(-1), _name(name)
    23 {
    24   NewClassID::registerClass(this);
    25 }
    26 
    27 ClassIDDeclaration::~ClassIDDeclaration()
    28 {
    29   NewClassID::unregisterClass(this);
    30 }
    31 
    32 
    33 
    3421///////////////////////////////////////////////////////////
    3522//// CLASS ID definiton. //////////////////////////////////
     
    3926 */
    4027NewClassID::NewClassID ()
    41   : _className("")
    42 {
    43 }
     28    : _className("")
     29{}
    4430
    4531
     
    5339
    5440
    55 int NewClassID::_idCounter = 0;
    56 
    57 //! TODO make access to the idCounter ThreadSafe!
    58 void NewClassID::registerClass(ClassIDDeclaration* namer)
    59 {
    60   assert (namer->id() != -1 && "Do not register any ClassID's for yourself.");
    61 
    62   namer->_id = NewClassID::_idCounter++;
    63 }
    64 
    65 void NewClassID::unregisterClass(ClassIDDeclaration* namer)
    66 {
    67   // here nothing is done, because Classes cannot be realigned fast.
    68 }
  • trunk/src/lib/lang/new_class_id.h

    r9659 r9660  
    1212#include <string>
    1313
    14 #define DeclareClass(ClassName) \
    15    ClassIDDeclaration ClassID_##ClassName(ClassName)
    16 
    17 class ClassIDDeclaration
    18 {
    19   friend class NewClassID;
    20 public:
    21   ClassIDDeclaration(const std::string& name);
    22   ~ClassIDDeclaration();
    23 
    24   int id() const { return _id; };
    25   const std::string& name() const { return _name; };
    26 
    27 private:
    28   //! the copy constructor will be hidden.
    29   ClassIDDeclaration(const ClassIDDeclaration& definer) {};
    30 
    31 private:
    32   int                   _id;
    33   std::string           _name;
    34 };
    35 
    36 
    3714//! A class to dynamically allocate ClassID's and support a isA operator
    3815class NewClassID
     
    4219  ~NewClassID();
    4320
    44 
    45 
    46   static int classCount() { return _idCounter; };
    47   static void registerClass(ClassIDDeclaration* namer);
    48   static void unregisterClass(ClassIDDeclaration* namer);
    49 
    5021private:
    51   std::set<ClassIDDeclaration>  _types;
    5222  std::string                   _className;
    5323
    54   static int                    _idCounter;      //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe.
    5524};
    5625
  • trunk/src/lib/lang/new_class_list.cc

    r9659 r9660  
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "new_class_id.h"
     18#include "new_class_list.h"
    1919#include <cassert>
    2020
    21 ClassIDDeclaration::ClassIDDeclaration(const std::string& name)
    22   : _id(-1), _name(name)
     21
     22NewClassListBase::NewClassListBase(const std::string& className)
     23  : _id(-1), _name(className)
    2324{
    24   NewClassID::registerClass(this);
     25
    2526}
    26 
    27 ClassIDDeclaration::~ClassIDDeclaration()
    28 {
    29   NewClassID::unregisterClass(this);
    30 }
    31 
    32 
    33 
    34 ///////////////////////////////////////////////////////////
    35 //// CLASS ID definiton. //////////////////////////////////
    36 ///////////////////////////////////////////////////////////
    37 /**
    38  * @brief standard constructor
    39  */
    40 NewClassID::NewClassID ()
    41   : _className("")
    42 {
    43 }
    44 
    45 
    46 /**
    47  * @brief standard deconstructor
    48  */
    49 NewClassID::~NewClassID ()
    50 {
    51   // delete what has to be deleted here
    52 }
    53 
    54 
    55 int NewClassID::_idCounter = 0;
    56 
    57 //! TODO make access to the idCounter ThreadSafe!
    58 void NewClassID::registerClass(ClassIDDeclaration* namer)
    59 {
    60   assert (namer->id() != -1 && "Do not register any ClassID's for yourself.");
    61 
    62   namer->_id = NewClassID::_idCounter++;
    63 }
    64 
    65 void NewClassID::unregisterClass(ClassIDDeclaration* namer)
    66 {
    67   // here nothing is done, because Classes cannot be realigned fast.
    68 }
  • 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.