Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 5, 2009, 5:15:35 PM (15 years ago)
Author:
rgrieder
Message:

Improved CMake performance for runs after the first one.
There are some optimisations in the macro argument parser and I manually added the header files for util and network (since they don't change too much and it still compiles with a missing header files).

Location:
code/branches/resource2/src/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/core/ClassFactory.h

    r3196 r5610  
    5454    class ClassFactory : public BaseFactory
    5555    {
     56        friend class Factory;
     57
    5658        public:
    5759            static bool create(const std::string& name, bool bLoadable = true);
     
    5961
    6062        private:
    61             ClassFactory() {}                               // Don't create
    62             ClassFactory(const ClassFactory& factory) {}    // Don't copy
     63            ClassFactory(bool bLoadable) : bLoadable_(bLoadable) {}
     64            ClassFactory(const ClassFactory& factory)    // Don't copy
    6365            virtual ~ClassFactory() {}                      // Don't delete
    6466
    65             static T* createNewObject(BaseObject* creator);
     67            Identifier* createIdentifier(const std::string& name);
     68
     69            bool bLoadable_;
    6670    };
    6771
     
    7680    {
    7781        COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
    78         ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
    79         ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
    80         Factory::add(name, ClassIdentifier<T>::getIdentifier());
     82        Factory::add(name, new ClassFactory<T>(bLoadable));
    8183
    8284        return true;
     
    9092    inline BaseObject* ClassFactory<T>::fabricate(BaseObject* creator)
    9193    {
    92         return ClassFactory<T>::createNewObject(creator);
     94        return new T(creator);
    9395    }
    9496
    9597    /**
    96         @brief Creates and returns a new object of class T; this is a wrapper for the new operator.
    97         @return The new object
    9898    */
    9999    template <class T>
    100     inline T* ClassFactory<T>::createNewObject(BaseObject* creator)
     100    inline Identifier* ClassFactory<T>::createIdentifier(const std::string& name)
    101101    {
    102         return new T(creator);
     102        Identifier* identifier = ClassIdentifier<T>::getIdentifier(name);
     103        identifier->addFactory(this);
     104        identifier->setLoadable(this->bLoadable_);
     105        return identifier;
    103106    }
    104107}
  • code/branches/resource2/src/core/Factory.cc

    r3196 r5610  
    7373        @param identifier The identifier to add
    7474    */
    75     void Factory::add(const std::string& name, Identifier* identifier)
     75    void Factory::add(const std::string& name, BaseFactory* factory)
    7676    {
    77         getFactoryPointer()->identifierStringMap_[name] = identifier;
    78         getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
     77        getFactoryPointer()->factoryMap_[name] = factory;
    7978    }
    8079
     
    105104    {
    106105        COUT(3) << "*** Factory: Create class-hierarchy" << std::endl;
    107         std::map<std::string, Identifier*>::iterator it;
    108         it = getFactoryPointer()->identifierStringMap_.begin();
    109         (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy();
    110         for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it)
     106        std::map<std::string, BaseFactory*>::iterator it;
     107        it = getFactoryPointer()->factoryMap_.begin();
     108        Identifier::startCreatingHierarchy();
     109        for (it = getFactoryPointer()->factoryMap_.begin(); it != getFactoryPointer()->factoryMap_.end(); ++it)
    111110        {
     111            // Create the corresponding identifier first
     112            Identifier* identifier = it->second->createIdentifier(it->first);
     113            getFactoryPointer()->identifierStringMap_[it->first] = identifier;
     114            getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
    112115            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
    113             BaseObject* temp = (*it).second->fabricate(0);
     116            BaseObject* temp = identifier->fabricate(0);
    114117            delete temp;
    115118        }
    116         (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
     119        Identifier::stopCreatingHierarchy();
    117120        COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
    118121    }
  • code/branches/resource2/src/core/Factory.h

    r2761 r5610  
    6161            static Identifier* getIdentifier(const std::string& name);
    6262            static Identifier* getIdentifier(const uint32_t id);
    63             static void add(const std::string& name, Identifier* identifier);
     63            static void add(const std::string& name, BaseFactory* factory);
    6464            static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID);
    6565            static void cleanNetworkIDs();
     
    6969
    7070            /** @brief Returns the factory-map. */
    71             static const std::map<std::string, Identifier*>& getFacbtoryMap()
     71            static const std::map<std::string, Identifier*>& getFactoryMap()
    7272                { return Factory::getFactoryPointer()->identifierStringMap_; }
    7373            /** @brief Returns the begin-iterator of the factory-map. */
     
    8585            std::map<std::string, Identifier*> identifierStringMap_;            //!< The map, mapping the name with the Identifier
    8686            std::map<uint32_t, Identifier*> identifierNetworkIDMap_;        //!< The map, mapping the network ID with the Identifier
     87            std::map<std::string, BaseFactory*> factoryMap_;
    8788    };
    8889
     
    9596        public:
    9697            virtual BaseObject* fabricate(BaseObject* creator) = 0;
     98            virtual Identifier* createIdentifier(const std::string& name) = 0;
    9799            virtual ~BaseFactory() {};
    98100    };
Note: See TracChangeset for help on using the changeset viewer.