Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 17, 2007, 1:02:01 AM (17 years ago)
Author:
landauf
Message:

funny hack, i hope this works for reto

Location:
code/branches/FICN/src/orxonox/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/orxonox/core/Factory.cc

    r513 r551  
    3838namespace orxonox
    3939{
    40     Factory* Factory::pointer_s = NULL; // Set the static member variable pointer_s to zero
     40    Factory* Factory::pointer1_s;
     41    Factory* Factory::pointer2_s;
     42    Factory* Factory::pointer3_s;
     43    Factory* Factory::pointer4_s;
     44    Factory* Factory::pointer5_s = NULL; // Set the static member variable pointer5_s to zero
     45
     46    /**
     47        @brief Checks if the pointer to the only Factory-object exists and creates it, if not.
     48    */
     49    void Factory::checkPointer()
     50    {
     51        if ((!pointer5_s) || (pointer1_s != pointer2_s) || (pointer2_s != pointer3_s) || (pointer3_s != pointer4_s) || (pointer4_s != pointer5_s))
     52        {
     53            std::cout << pointer1_s << std::endl;
     54            std::cout << pointer2_s << std::endl;
     55            std::cout << pointer3_s << std::endl;
     56            std::cout << pointer4_s << std::endl;
     57            std::cout << pointer5_s << std::endl;
     58            pointer1_s = pointer2_s = pointer3_s = pointer4_s = pointer5_s = new Factory;
     59            std::cout << pointer1_s << std::endl;
     60            std::cout << pointer2_s << std::endl;
     61            std::cout << pointer3_s << std::endl;
     62            std::cout << pointer4_s << std::endl;
     63            std::cout << pointer5_s << std::endl;
     64        }
     65    }
    4166
    4267    /**
     
    4671    Identifier* Factory::getIdentifier(const std::string& name)
    4772    {
    48         if (!pointer_s)
    49             pointer_s = new Factory;
     73        Factory::checkPointer();
    5074
    51         return pointer_s->identifierStringMap_[name];
     75        return pointer1_s->identifierStringMap_[name];
    5276    }
    5377
     
    5882    Identifier* Factory::getIdentifier(const unsigned int id)
    5983    {
    60         if (!pointer_s)
    61             pointer_s = new Factory;
     84        Factory::checkPointer();
    6285
    63         return pointer_s->identifierNetworkIDMap_[id];
     86        return pointer1_s->identifierNetworkIDMap_[id];
    6487    }
    6588
     
    7194    void Factory::add(const std::string& name, Identifier* identifier)
    7295    {
    73         if (!pointer_s)
    74             pointer_s = new Factory;
     96        Factory::checkPointer();
    7597
    76         pointer_s->identifierStringMap_[name] = identifier;
    77         pointer_s->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
     98        pointer1_s->identifierStringMap_[name] = identifier;
     99        pointer1_s->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
    78100    }
    79101
     
    86108    void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID)
    87109    {
    88         pointer_s->identifierNetworkIDMap_.erase(oldID);
    89         pointer_s->identifierNetworkIDMap_[newID] = identifier;
     110        Factory::checkPointer();
     111
     112        pointer1_s->identifierNetworkIDMap_.erase(oldID);
     113        pointer1_s->identifierNetworkIDMap_[newID] = identifier;
    90114    }
    91115
     
    95119    void Factory::createClassHierarchy()
    96120    {
    97         if (!pointer_s)
    98             pointer_s = new Factory;
     121        Factory::checkPointer();
    99122
    100123        COUT(4) << "*** Factory -> Create class-hierarchy\n";
    101124        std::map<std::string, Identifier*>::iterator it;
    102         it = pointer_s->identifierStringMap_.begin();
    103         (*pointer_s->identifierStringMap_.begin()).second->startCreatingHierarchy();
    104         for (it = pointer_s->identifierStringMap_.begin(); it != pointer_s->identifierStringMap_.end(); ++it)
     125        it = pointer1_s->identifierStringMap_.begin();
     126        (*pointer1_s->identifierStringMap_.begin()).second->startCreatingHierarchy();
     127        for (it = pointer1_s->identifierStringMap_.begin(); it != pointer1_s->identifierStringMap_.end(); ++it)
    105128        {
    106129            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     
    108131            delete temp;
    109132        }
    110         (*pointer_s->identifierStringMap_.begin()).second->stopCreatingHierarchy();
     133        (*pointer1_s->identifierStringMap_.begin()).second->stopCreatingHierarchy();
    111134        COUT(4) << "*** Factory -> Finished class-hierarchy creation\n";
    112135    }
  • code/branches/FICN/src/orxonox/core/Factory.h

    r496 r551  
    3939
    4040        private:
    41             Factory() {}                        // don't create
    42             Factory(const Factory& factory) {}  // don't copy
    43             ~Factory() {}                       // don't delete
     41            Factory() {}                            // don't create
     42            Factory(const Factory& factory) {}      // don't copy
     43            ~Factory() {}                           // don't delete
     44            static void checkPointer();
    4445
    45             static Factory* pointer_s;                                          //!< The pointer to the singleton
     46            static Factory* pointer1_s;                                         //!< The 1st pointer to the singleton
     47            static Factory* pointer2_s;                                         //!< The 2nd pointer to the singleton
     48            static Factory* pointer3_s;                                         //!< The 3rd pointer to the singleton
     49            static Factory* pointer4_s;                                         //!< The 4th pointer to the singleton
     50            static Factory* pointer5_s;                                         //!< The 5th pointer to the singleton
    4651            std::map<std::string, Identifier*> identifierStringMap_;            //!< The map, mapping the name with the Identifier
    4752            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.