Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib/lang


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

Location:
trunk/src/lib/lang
Files:
7 deleted
3 edited
4 copied

Legend:

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

    r9677 r9869  
    1 MAINSRCDIR=../..
    2 include $(MAINSRCDIR)/defs/include_paths.am
    3 
    4 LIB_PREFIX=$(MAINSRCDIR)/lib
    5 include $(MAINSRCDIR)/lib/BuildLibs.am
     1INCLUDES = -I../..
     2INCLUDES +=-I..
     3INCLUDES +=-I../util
    64
    75noinst_LIBRARIES = libORXlang.a
     
    97libORXlang_a_SOURCES = \
    108                base_object.cc \
    11                 class_list.cc \
    12                 new_class_id.cc \
    13                 new_object_list.cc
     9                class_id.cc \
     10                object_list.cc
    1411
    1512noinst_HEADERS = \
    1613                base_object.h \
    17                 class_list.h \
    18                 new_class_id.h \
    19                 new_object_list.h
    20 
    21 
    22 
    23 
    24 
    25 ## THIS ALL IS JUST FOR TESTING!!
    26 check_PROGRAMS = test_object_list
    27 
    28 test_object_list_SOURCES = \
    29                 test_object_list.cc
    30 
    31 test_object_list_DEPENDENCIES = libORXlang.a
    32 
    33 test_object_list_LDADD = \
    34                 $(MAINSRCDIR)/util/libORXutils.a \
    35                 $(libORXlibs_a_LIBRARIES_) \
    36                 $(MAINSRCDIR)/world_entities/libORXwe.a \
    37                 $(libORXlibs_a_LIBRARIES_) \
    38                 $(MAINSRCDIR)/util/libORXutils.a
    39 
    40 #test_object_list_LDADD = \
    41                 libORXlang.a
     14                class_id.h \
     15                object_list.h
  • trunk/src/lib/lang/base_object.cc

    r9406 r9869  
    1 
    2 
    31/*
    42   orxonox - the future of 3D-vertical-scrollers
     
    1917#include "base_object.h"
    2018
     19#include "util/debug.h"
    2120#include "util/loading/load_param.h"
    22 #include "class_list.h"
     21
     22ObjectListDefinition(BaseObject);
    2323
    2424/**
    2525 * @brief sets the name from a LoadXML-Element
    26  * @param root the element to load from
     26 * @param objectName: The name of the Object.
    2727 */
    2828BaseObject::BaseObject(const std::string& objectName)
    2929{
    30   this->classID = CL_BASE_OBJECT;
    3130  this->className = "BaseObject";
    3231
    3332  this->objectName = objectName;
    34   this->classList = NULL;
    3533  this->xmlElem = NULL;
    36 
    37   //ClassList::addToClassList(this, this->classID, "BaseObject");
     34  this->registerObject(this, BaseObject::_objectList);
    3835}
    3936
     
    4340BaseObject::~BaseObject ()
    4441{
    45   ClassList::removeFromClassList(this);
     42  /// Remove from the ObjectLists
     43  ClassEntries::iterator it;
     44  PRINTF(5)("Deleting Object of type %s::%s\n", this->getClassCName(), getCName());
     45  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     46  {
     47    if (ORX_DEBUG >= 5)
     48      assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this));
     49    (*it)._objectList->unregisterObject((*it)._iterator);
     50    delete (*it)._iterator;
     51  }
    4652
    4753  if (this->xmlElem != NULL)
     
    6975
    7076/**
    71  * @brief sets the class identifiers
    72  * @param id a number for the class from class_id.h enumeration
    73  * @param className the class name
    74 */
    75 void BaseObject::setClassID(ClassID classID, const std::string& className)
    76 {
    77   //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
    78   assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA ));
    79 
    80   this->leafClassID = classID;
    81   this->classID |= (long)classID;
    82   this->className = className;
    83 
    84   this->classList = ClassList::addToClassList(this, classID, this->classID, className);
    85 }
    86 
    87 
    88 /**
    8977 * @brief set the name of the Object
    9078 * @param objectName The new name of the Object.
     
    9785
    9886/**
    99  * @brief queries for the ClassID of the Leaf Class (the last made class of this type
    100  * @returns the ClassID of the Leaf Class (e.g. the ID of the Class)
    101  *
    102  * the returned ID can be used to generate new Objects of the same type through
    103  * Factory::fabricate(Object->getLeafClassID());
     87 * @brief Seeks in the Inheritance if it matches objectList.
     88 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
     89 * @return True if found, false if not.
    10490 */
    105 const ClassID& BaseObject::getLeafClassID() const
     91bool BaseObject::isA(const ObjectListBase& objectList) const
    10692{
    107   return this->leafClassID;
    108 }
    109 
    110 
    111 
    112 /**
    113  * @brief checks if the class is a classID
    114  * @param classID the Identifier to check for
    115  * @returns true if it is, false otherwise
    116 */
    117 bool BaseObject::isA (ClassID classID) const
    118 {
    119   // if classID is a derivable object from a SUPERCLASS
    120   if (classID & CL_MASK_SUPER_CLASS)
    121   {
    122     if( likely(this->classID & classID))
     93  ClassEntries::const_iterator it;
     94  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     95    if ((*it)._objectList == &objectList)
    12396      return true;
    124   }
    125   // if classID is a SubSuperClass, and
    126   else if (classID & CL_MASK_SUBSUPER_CLASS)
    127   {
    128     if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
    129         this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
    130       return true;
    131   }
    132   // if classID is a LOWLEVEL-class
    133   else
    134   {
    135     if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
    136       return true;
    137   }
    13897  return false;
    13998}
    14099
    141100
     101/**
     102 * @brief Seeks in the Inheritance if it matches objectList.
     103 * @param classID The ClassID this should be a member of (by Pointer-comparison).
     104 * @return True if found, false if not.
     105 */
     106bool BaseObject::isA(const ClassID& classID) const
     107{
     108  ClassEntries::const_iterator it;
     109  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     110    if (*(*it)._objectList == classID)
     111      return true;
     112  return false;
     113}
    142114
    143115/**
    144  * @brief checks if the class is a classID
    145  * @param classID the Identifier to check for
    146  * @returns true if it is, false otherwise
     116 * @brief Seeks in the Inheritance if it matches objectList.
     117 * @param classID The ClassID of the class this should be a member of.
     118 * @return True if found, false if not.
    147119 */
    148 bool BaseObject::isA (const std::string& className) const
     120bool BaseObject::isA(int classID) const
    149121{
    150   ClassID classID = ClassList::StringToID(className);
    151   if (classID != CL_NULL)
    152     return this->isA(classID);
    153   else
    154     return false;
     122  ClassEntries::const_iterator it;
     123  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     124    if (*(*it)._objectList == classID)
     125
     126      return true;
     127  return false;
     128}
     129
     130/**
     131 * @brief Seeks in the Inheritance if it matches objectList.
     132 * @param className The ClassName of the class this should be a member of.
     133 * @return True if found, false if not.
     134 */
     135bool BaseObject::isA(const std::string& className) const
     136{
     137  ClassEntries::const_iterator it;
     138  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     139    if (*(*it)._objectList == className)
     140      return true;
     141  return false;
    155142}
    156143
    157144
    158145/**
    159  * @brief compares the ObjectName with an external name
    160  * @param objectName: the name to check.
    161  * @returns true on match, false otherwise.
     146 * @brief This is for debug purposes, to see the Inheritances of this Object and its classes.
     147 *
     148 * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency.
    162149 */
    163 bool BaseObject::operator==(const std::string& objectName) const
     150void BaseObject::listInheritance() const
    164151{
    165   return (this->objectName == objectName);
     152  PRINT(0)("Listing inheritance diagram for %s::%s: ", getClassCName(), getCName());
     153  ClassEntries::const_iterator it;
     154  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     155    PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
     156  PRINT(0)("\n");
     157
    166158}
    167 
  • trunk/src/lib/lang/base_object.h

    r9406 r9869  
    1414#define __BASE_OBJECT_H_
    1515
    16 #include "class_id.h"
    17 #include "sigslot/slot.h"
     16#include "object_list.h"
     17#include "util/sigslot/slot.h"
    1818
    1919#include <string>
     
    2626class BaseObject : public sigslot::has_slots<>
    2727{
    28 
     28  //! Declare an ObjectList for this Class.
     29  ObjectListDeclaration(BaseObject);
    2930public:
    3031  BaseObject (const std::string& objectName = "");
     
    4142  inline TiXmlNode* getXmlElem() const { return this->xmlElem; };
    4243
    43   /** @returns the className of the corresponding Object */
    44   inline const std::string& getClassName() const { return this->className; }
     44  //  /** @returns the className of the corresponding Object */
     45  //inline const std::string& getClassName() const { return this->className; }
    4546  /** @returns the className of the corresponding Object as a C-compliant string (const char*) */
    46   inline const char* getClassCName() const { return this->className.c_str(); };
    47   /** @returns the classID of the corresponding Object */
    48   inline int getClassID() const { return this->classID; };
    49   const ClassID& getLeafClassID() const;
     47  inline const char* getClassCName() const { return _classes.front()._objectList->name().c_str(); };
     48  /** @returns the ClassName of the Topmost Object of the ClassStack */
     49  inline const std::string& getClassName() const { return _classes.front()._objectList->name(); };
    5050
    51   bool isA (ClassID classID) const;
    52   bool isA (const std::string& className) const;
     51  /** @returns the ClassID of this Object */
     52  inline const ClassID& getClassID() const { return _classes.front()._objectList->identity(); }
     53  /** @returns the ID of the Topmost object of the ClassStack */
     54  inline const int& getLeafClassID() const { return _classes.front()._objectList->identity().id(); }
     55
     56  bool isA(const ObjectListBase& objectList) const;
     57  bool isA(const ClassID& classID) const;
     58  bool isA(int classID) const;
     59  bool isA(const std::string& className) const;
     60
     61  void listInheritance() const;
    5362
    5463  /** @param classID comparer for a ClassID @returns true on match, false otherwise */
    55   bool operator==(ClassID classID) const  { return this->isA(classID); };
    56   bool operator==(const std::string& objectName) const;
     64  bool operator==(int classID) const  { return this->isA(classID); };
     65  /** @param objectName: the name to check. * @returns true on match, false otherwise. */
     66  bool operator==(const std::string& objectName) const { return this->objectName == objectName;};
    5767
    5868protected:
    59   void setClassID(ClassID classID, const std::string& className);
     69  template<class T> void registerObject(T* object, ObjectList<T>& list);
    6070
    6171protected:
     
    6373
    6474private:
    65   std::string        className;        //!< the name of the class
    66   long               classID;          //!< this is the id from the class_id.h enumeration
    67   ClassID            leafClassID;      //!< The Leaf Class ID
    68 
    69   ClassList*         classList;        //!< Pointer to the ClassList this Object is inside of
    7075
    7176  TiXmlNode*         xmlElem;          //!< The XML Element with wich this Object was loaded(saved).
     77
     78  //////////////////////////////
     79  //// Type Definition Part ////
     80  //////////////////////////////
     81  //! A ClassEntry so we can store Classes inside of Objects
     82  struct ClassEntry
     83  {
     84    /** Simple Constuctor @param objectList the ObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */
     85    inline ClassEntry (ObjectListBase* objectList, ObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
     86    ObjectListBase*                _objectList;  //!< An ObjectList this Object is part of
     87    ObjectListBase::IteratorBase*  _iterator;    //!< An iterator pointing to the position of the Object inside of the List.
     88  };
     89  typedef std::list<ClassEntry>       ClassEntries;   //!< Type definition for the List.
     90
     91  std::string                         className;    //!< the name of the class
     92  ClassEntries                        _classes;     //!< All Classes this object is part of.
    7293};
    7394
     95
     96/**
     97 * @brief Registeres an Object of Type T to objectList
     98 * @param object The Object to append to the objectList.
     99 * @param objectList The ObjectList to append the Object to.
     100 *
     101 * This function is essential to integrate objects into their designated ObjectList.
     102 * Remember if you do not want objects to be stored in Lists (less overhead),
     103 * do not attempt to call this function.
     104 */
     105template<class T>
     106inline void BaseObject::registerObject(T* object, ObjectList<T>& objectList)
     107{
     108  this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object)));
     109}
     110
    74111#endif /* __BASE_OBJECT_H_ */
Note: See TracChangeset for help on using the changeset viewer.