Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 7, 2015, 5:24:58 PM (9 years ago)
Author:
landauf
Message:

using std::shared_ptr instead of boost::shared_ptr (same for weak_ptr)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/Game.cc

    r10769 r10771  
    3636
    3737#include <exception>
    38 #include <boost/weak_ptr.hpp>
    3938#include <loki/ScopeGuard.h>
    4039
     
    7271    {
    7372        std::string name_;
    74         weak_ptr<GameStateTreeNode> parent_;
    75         std::vector<shared_ptr<GameStateTreeNode>> children_;
     73        std::weak_ptr<GameStateTreeNode> parent_;
     74        std::vector<std::shared_ptr<GameStateTreeNode>> children_;
    7675    };
    7776
     
    124123
    125124        // The empty root state is ALWAYS loaded!
    126         this->rootStateNode_ = shared_ptr<GameStateTreeNode>(new GameStateTreeNode());
     125        this->rootStateNode_ = std::shared_ptr<GameStateTreeNode>(new GameStateTreeNode());
    127126        this->rootStateNode_->name_ = "emptyRootGameState";
    128127        this->loadedTopStateNode_ = this->rootStateNode_;
     
    137136
    138137        assert(loadedStates_.size() <= 1); // Just empty root GameState
    139         // Destroy all GameStates (shared_ptrs take care of actual destruction)
     138        // Destroy all GameStates (std::shared_ptrs take care of actual destruction)
    140139        constructedStates_.clear();
    141140
     
    235234        while (this->requestedStateNodes_.size() > 0)
    236235        {
    237             shared_ptr<GameStateTreeNode> requestedStateNode = this->requestedStateNodes_.front();
     236            std::shared_ptr<GameStateTreeNode> requestedStateNode = this->requestedStateNodes_.front();
    238237            assert(this->loadedTopStateNode_);
    239238            if (!this->loadedTopStateNode_->parent_.expired() && requestedStateNode == this->loadedTopStateNode_->parent_.lock())
     
    281280                orxout(user_error) << "This should really never happen!" << endl;
    282281                orxout(user_error) << "Unloading all GameStates depending on the one that crashed." << endl;
    283                 shared_ptr<GameStateTreeNode> current = this->loadedTopStateNode_;
     282                std::shared_ptr<GameStateTreeNode> current = this->loadedTopStateNode_;
    284283                while (current->name_ != (*it)->getName() && current)
    285284                    current = current->parent_.lock();
     
    372371        }
    373372
    374         shared_ptr<GameStateTreeNode> lastRequestedNode;
     373        std::shared_ptr<GameStateTreeNode> lastRequestedNode;
    375374        if (this->requestedStateNodes_.empty())
    376375            lastRequestedNode = this->loadedTopStateNode_;
     
    384383
    385384        // Check children first
    386         std::vector<shared_ptr<GameStateTreeNode>> requestedNodes;
     385        std::vector<std::shared_ptr<GameStateTreeNode>> requestedNodes;
    387386        for (unsigned int i = 0; i < lastRequestedNode->children_.size(); ++i)
    388387        {
     
    397396        {
    398397            // Check parent and all its grand parents
    399             shared_ptr<GameStateTreeNode> currentNode = lastRequestedNode;
     398            std::shared_ptr<GameStateTreeNode> currentNode = lastRequestedNode;
    400399            while (currentNode != nullptr)
    401400            {
     
    424423    void Game::popState()
    425424    {
    426         shared_ptr<GameStateTreeNode> lastRequestedNode;
     425        std::shared_ptr<GameStateTreeNode> lastRequestedNode;
    427426        if (this->requestedStateNodes_.empty())
    428427            lastRequestedNode = this->loadedTopStateNode_;
     
    435434    }
    436435
    437     shared_ptr<GameState> Game::getState(const std::string& name)
     436    std::shared_ptr<GameState> Game::getState(const std::string& name)
    438437    {
    439438        GameStateMap::const_iterator it = constructedStates_.find(name);
     
    447446            else
    448447                orxout(internal_error) << "Could not find GameState '" << name << "'." << endl;
    449             return shared_ptr<GameState>();
     448            return std::shared_ptr<GameState>();
    450449        }
    451450    }
     
    479478    /*** Internal ***/
    480479
    481     void Game::parseStates(std::vector<std::pair<std::string, int>>::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode)
     480    void Game::parseStates(std::vector<std::pair<std::string, int>>::const_iterator& it, std::shared_ptr<GameStateTreeNode> currentNode)
    482481    {
    483482        SubString tokens(it->first, ",");
     
    491490            if (tokens[i] == this->rootStateNode_->name_)
    492491                ThrowException(GameState, "You shouldn't use 'emptyRootGameState' in the hierarchy...");
    493             shared_ptr<GameStateTreeNode> node(new GameStateTreeNode());
     492            std::shared_ptr<GameStateTreeNode> node(new GameStateTreeNode());
    494493            node->name_ = tokens[i];
    495494            node->parent_ = currentNode;
     
    527526                {
    528527                    // Game state loading failure is serious --> don't catch
    529                     shared_ptr<GameState> gameState = GameStateFactory::fabricate(it->second);
     528                    std::shared_ptr<GameState> gameState = GameStateFactory::fabricate(it->second);
    530529                    if (!constructedStates_.insert(std::make_pair(
    531530                        it->second.stateName, gameState)).second)
     
    582581            graphicsUnloader.Dismiss();
    583582
    584         shared_ptr<GameState> state = this->getState(name);
     583        std::shared_ptr<GameState> state = this->getState(name);
    585584        state->activateInternal();
    586585        if (!this->loadedStates_.empty())
     
    599598        try
    600599        {
    601             shared_ptr<GameState> state = this->getState(name);
     600            std::shared_ptr<GameState> state = this->getState(name);
    602601            state->activity_.topState = false;
    603602            this->loadedStates_.pop_back();
     
    620619    }
    621620
    622     /*static*/ std::map<std::string, shared_ptr<Game::GameStateFactory>>& Game::GameStateFactory::getFactories()
    623     {
    624         static std::map<std::string, shared_ptr<GameStateFactory>> factories;
     621    /*static*/ std::map<std::string, std::shared_ptr<Game::GameStateFactory>>& Game::GameStateFactory::getFactories()
     622    {
     623        static std::map<std::string, std::shared_ptr<GameStateFactory>> factories;
    625624        return factories;
    626625    }
    627626
    628     /*static*/ shared_ptr<GameState> Game::GameStateFactory::fabricate(const GameStateInfo& info)
    629     {
    630         std::map<std::string, shared_ptr<Game::GameStateFactory>>::const_iterator it = getFactories().find(info.className);
     627    /*static*/ std::shared_ptr<GameState> Game::GameStateFactory::fabricate(const GameStateInfo& info)
     628    {
     629        std::map<std::string, std::shared_ptr<Game::GameStateFactory>>::const_iterator it = getFactories().find(info.className);
    631630        assert(it != getFactories().end());
    632631        return it->second->fabricateInternal(info);
Note: See TracChangeset for help on using the changeset viewer.