Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (16 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/Identifier.h

    r1856 r2087  
    5757#include <set>
    5858#include <map>
     59#include <vector>
    5960#include <string>
    6061#include <utility>
    6162#include <typeinfo>
    6263#include <stdlib.h>
     64#include <cassert>
    6365
    6466#include "MetaObjectList.h"
    6567#include "Iterator.h"
    6668#include "Super.h"
     69#include "Functor.h"
    6770#include "util/Debug.h"
    6871#include "util/String.h"
     
    99102            inline void addFactory(BaseFactory* factory) { this->factory_ = factory; }
    100103
    101             BaseObject* fabricate();
     104            BaseObject* fabricate(BaseObject* creator);
    102105            bool isA(const Identifier* identifier) const;
    103106            bool isExactlyA(const Identifier* identifier) const;
     
    107110            bool isDirectParentOf(const Identifier* identifier) const;
    108111
     112            /** @brief Returns true if the class can be loaded through XML. */
     113            inline bool isLoadable() const { return this->bLoadable_; }
     114            /** @brief Set the class to be loadable through XML or not. */
     115            inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }
     116
    109117            /** @brief Returns the list of all existing objects of this class. @return The list */
    110118            inline ObjectListBase* getObjects() const
     
    204212            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); }
    205213
     214            /** @brief Returns the map that stores all XMLPort events. @return The const_iterator */
     215            inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortEventMap() const { return this->xmlportEventContainers_; }
     216            /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort events. @return The const_iterator */
     217            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapBegin() const { return this->xmlportEventContainers_.begin(); }
     218            /** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */
     219            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); }
     220
    206221            /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
    207222            inline bool hasConfigValues() const { return this->bHasConfigValues_; }
    208223            /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */
    209224            inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; }
     225            /** @brief Returns true if this class has at least one construction callback Functor registered. */
     226            inline bool hasConstructionCallback() const { return this->bHasConstructionCallback_; }
    210227
    211228            /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
     
    228245            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    229246
     247            void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container);
     248            XMLPortObjectContainer* getXMLPortEventContainer(const std::string& eventname);
     249
    230250            ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
    231251            ConsoleCommand* getConsoleCommand(const std::string& name) const;
    232252            ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;
     253
     254            void addConstructionCallback(Functor* functor);
     255            void removeConstructionCallback(Functor* functor);
    233256
    234257            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     
    252275            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
    253276
     277            bool bHasConstructionCallback_;                                //!< True if at least one Functor is registered to get informed when an object of type T is created.
     278            std::vector<Functor*> constructionCallbacks_;                  //!< All construction callback Functors of this class.
     279
    254280            ObjectListBase* objects_;                                      //!< The list of all objects of this class
    255281
     
    285311            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    286312            bool bSetName_;                                                //!< True if the name is set
     313            bool bLoadable_;                                               //!< False = it's not permitted to load the object through XML
    287314            std::string name_;                                             //!< The name of the class the Identifier belongs to
    288315            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
     
    300327            std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_;     //!< All loadable parameters
    301328            std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_;   //!< All attachable objects
     329            std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_;    //!< All events
    302330    };
    303331
     
    423451        COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
    424452        object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
     453        if (this->bHasConstructionCallback_)
     454        {
     455            // Call all registered callbacks that a new object of type T has been created.
     456            // Do NOT deliver a T* pointer here because it's way too risky (object not yet fully created).
     457            for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i)
     458                (*constructionCallbacks_[i])();
     459        }
    425460    }
    426461
     
    480515            SubclassIdentifier<T>& operator=(Identifier* identifier)
    481516            {
    482                 if (!identifier->isA(ClassIdentifier<T>::getIdentifier()))
     517                if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier()))
    483518                {
    484519                    COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
    485                     COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
    486                     COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
    487                     COUT(1) << "Aborting..." << std::endl;
    488                     abort();
     520                    if (identifier)
     521                    {
     522                        COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
     523                        COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
     524                    }
     525                    else
     526                    {
     527                        COUT(1) << "Error: Can't assign NULL identifier" << std::endl;
     528                    }
    489529                }
    490                 this->identifier_ = identifier;
     530                else
     531                {
     532                    this->identifier_ = identifier;
     533                }
    491534                return *this;
    492535            }
     
    495538                @brief Overloading of the * operator: returns the assigned identifier.
    496539            */
    497             inline Identifier* operator*()
     540            inline Identifier* operator*() const
    498541            {
    499542                return this->identifier_;
     
    520563                @return The new object
    521564            */
    522             T* fabricate()
    523             {
    524                 BaseObject* newObject = this->identifier_->fabricate();
     565            T* fabricate(BaseObject* creator) const
     566            {
     567                BaseObject* newObject = this->identifier_->fabricate(creator);
    525568
    526569                // Check if the creation was successful
     
    546589                    }
    547590
    548                     abort();
     591                    assert(false);
     592                    return 0;
    549593                }
    550594            }
Note: See TracChangeset for help on using the changeset viewer.