/*! * @file class_id.h * @brief Definition of a dynamically allocating ClassID * */ #ifndef _CLASS_ID_H #define _CLASS_ID_H #include class ObjectListBase; //! A class to dynamically allocate ClassID's and to support a isA operator /** * A ClassID can only be aquired over a ObjectList, * thus enabling the developer to have permanent access to the correct ID and ClassName * * The Idea behind this concept is, that storing a ClassID that changes its internal state * all ClassID's will be updated correctly. * * Since the Existance of any ObjectList is a requirement during the working process all * ID's should reference a valid ID and ClassName */ class ClassID { public: ClassID(); ClassID(const ObjectListBase* const id); /// the copy constructor is also defined implicitely. /** @returns A constant reference to the ID. */ const int& id() const { return *_id; }; /** @returns A constant reference to the Name. */ const std::string& name() const { return *_name; }; /** @param id the id to compare @returns true on match (match is same ID) @brief compares two id's */ bool operator==(const ClassID& id) const { return *_id == *id._id /* || _name == id._name */; }; /** @param id the id to compare @returns true on match (match is same ID) @brief compares two id's */ bool operator==(int id) const { return *_id == id; }; /** @param name the id to compare @returns true on match (match is same Name) @brief compares an ID with a ClassName */ bool operator==(const std::string& name) const { return *_name == name; }; /** @param id the id to compare @returns false on match (match is same ID) @brief compares two id's */ bool operator!=(const ClassID& id) const { return *_id != *id._id /* && _name != id._name*/; }; /** @param id the id to compare @returns false on match (match is same ID) @brief compares two id's */ bool operator!=(int id) const { return *_id != id; }; /** @param name the id to compare @returns false on match (match is same Name) @brief compares an ID with a ClassName */ bool operator!=(const std::string& name) const { return *_name != name; }; private: const int* _id; //!< A pointer to the ID of the ClassID. const std::string* _name; //!< A pointer to the Name of the ClassID. }; //! A NullClass. This is the Null of the ClassID. /** * implemented as a Class id can be used to reference NullObjects. */ class NullClass { public: /** @returns the NullClass' ID. */ static const ClassID& staticClassID() { return NullClass::_classID; } /** @param id the ID to acquire @param name the name to acquire @brief acquires the ID of this Class */ static void acquireID(const int*& id, const std::string*& name) { id = &_nullID; name = &_nullName; }; private: NullClass() {}; //!< The Default Constructor is hidden from the User. private: static ClassID _classID; //!< The NullClass' ID static const std::string _nullName; //!< The NullClass' Name ("NullClass") static int _nullID; //!< The NullClass' ID }; #endif /* _CLASS_ID_H */