Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 553 for code


Ignore:
Timestamp:
Dec 17, 2007, 1:19:13 AM (17 years ago)
Author:
rgrieder
Message:
  • some minor change in static initialisation of factory (this concept could be adopted to the other singletons in the factory as well)
Location:
code/branches/FICN/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/loader/loader_platform.h

    r382 r553  
    3434  #ifdef LOADER_BUILD
    3535    #define _LoaderExport __declspec( dllexport )
     36  #elif defined(LOADER_STATIC)
     37    #define _LoaderExport
    3638  #else
    3739    #define _LoaderExport __declspec( dllimport )
  • code/branches/FICN/src/orxonox/core/Factory.cc

    r552 r553  
    3838namespace orxonox
    3939{
    40     Factory* Factory::pointer_s = NULL; // Set the static member variable pointer_s to zero
    41 
    4240    /**
    4341        @returns the Identifier with a given name.
     
    4644    Identifier* Factory::getIdentifier(const std::string& name)
    4745    {
    48         Factory::checkPointer();
    49 
    50         return pointer_s->identifierStringMap_[name];
     46        return getFactoryPointer()->identifierStringMap_[name];
    5147    }
    5248
     
    5753    Identifier* Factory::getIdentifier(const unsigned int id)
    5854    {
    59         Factory::checkPointer();
    60 
    61         return pointer_s->identifierNetworkIDMap_[id];
     55        return getFactoryPointer()->identifierNetworkIDMap_[id];
    6256    }
    6357
     
    6963    void Factory::add(const std::string& name, Identifier* identifier)
    7064    {
    71         Factory::checkPointer();
    72 
    73         pointer_s->identifierStringMap_[name] = identifier;
    74         pointer_s->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
     65        getFactoryPointer()->identifierStringMap_[name] = identifier;
     66        getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
    7567    }
    7668
     
    8375    void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID)
    8476    {
    85         Factory::checkPointer();
    86 
    87         pointer_s->identifierNetworkIDMap_.erase(oldID);
    88         pointer_s->identifierNetworkIDMap_[newID] = identifier;
     77        getFactoryPointer()->identifierNetworkIDMap_.erase(oldID);
     78        getFactoryPointer()->identifierNetworkIDMap_[newID] = identifier;
    8979    }
    9080
     
    9484    void Factory::createClassHierarchy()
    9585    {
    96         Factory::checkPointer();
    97 
    9886        COUT(4) << "*** Factory -> Create class-hierarchy\n";
    9987        std::map<std::string, Identifier*>::iterator it;
    100         it = pointer_s->identifierStringMap_.begin();
    101         (*pointer_s->identifierStringMap_.begin()).second->startCreatingHierarchy();
    102         for (it = pointer_s->identifierStringMap_.begin(); it != pointer_s->identifierStringMap_.end(); ++it)
     88        it = getFactoryPointer()->identifierStringMap_.begin();
     89        (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy();
     90        for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it)
    10391        {
    10492            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     
    10694            delete temp;
    10795        }
    108         (*pointer_s->identifierStringMap_.begin()).second->stopCreatingHierarchy();
     96        (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
    10997        COUT(4) << "*** Factory -> Finished class-hierarchy creation\n";
    11098    }
     99
     100    /**
     101        @brief blubb
     102    */
     103    Factory* Factory::getFactoryPointer()
     104    {
     105      static Factory theOneAndOnlyInstance = Factory();
     106      return &theOneAndOnlyInstance;
     107    }
    111108}
  • code/branches/FICN/src/orxonox/core/Factory.h

    r552 r553  
    3838            static void createClassHierarchy();
    3939
     40            static Factory* getFactoryPointer();// avoid overriding pointer_s in the static intialisation process
     41
    4042        private:
    4143            Factory() {}                            // don't create
    4244            Factory(const Factory& factory) {}      // don't copy
    4345            ~Factory() {}                           // don't delete
     46            static void checkPointer();
    4447
    45             /**
    46                 @brief Checks if the pointer to the only Factory-object exists and creates it, if not.
    47             */
    48             inline static void checkPointer()
    49             {
    50                 if (!pointer_s)
    51                     pointer_s = new Factory;
    52             }
    53 
    54             static Factory* pointer_s;                                          //!< The pointer to the singleton
    5548            std::map<std::string, Identifier*> identifierStringMap_;            //!< The map, mapping the name with the Identifier
    5649            std::map<unsigned int, Identifier*> identifierNetworkIDMap_;        //!< The map, mapping the network ID with the Identifier
Note: See TracChangeset for help on using the changeset viewer.