Source

zorkish / World.hpp

/*
 * World.hpp
 *
 *  Created on: 04/09/2012
 *      Author: rhys
 */

#ifndef WORLD_HPP_
#define WORLD_HPP_

#include "Location.hpp"

class World {
private:
    // GCC doesn't have a working std::map for a value w/ move semantics
    std::map<int, Location*> locations;

public:
    std::string name;

    World(std::string name) : name(name) {}

    ~World() {
        for (auto& pair : locations) {
            delete pair.second;
        }
    }

    // Obtains ownership of location
    void add_location(int id, Location* location) {
        this->locations[id] = location;
    }

    Location* get_location(int id) {
        auto it = this->locations.find(id);
        if (it != this->locations.end()) {
            return (*it).second;
        } else {
            return nullptr;
        }
    }
};


#endif /* WORLD_HPP_ */