The source code is almost exactly copied from the book with the exception of a .h file for the enum of the textures
but here is the class anyway
the TextureHolder.h
#ifndef TEXTUREHOLDER_H
#define TEXTUREHOLDER_H
#include "Textures.h"
#include <map>
#include <string>
#include <memory>
#include <stdexcept>
#include <cassert>
#include <SFML/Graphics.hpp>
class TextureHolder
{
public:
void load(Textures::ID id, const std::string& filename);
sf::Texture& get(Textures::ID id);
const sf::Texture& get(Textures::ID id) const;
private:
std::map<Textures::ID, std::unique_ptr<sf::Texture>> mTextureMap;
};
#endif // TEXTUREHOLDER_H
and the TextureHolder.cpp
#include "TextureHolder.h"
void TextureHolder::load(Textures::ID id,const std::string &filename)
{
std::unique_ptr<sf::Texture> texture(new sf::Texture());
if(!texture->loadFromFile(filename))
{
throw std::runtime_error("TextureHolder::load - Failed to load " + filename);
}
//implement logic error
auto inserted = mTextureMap.insert(std::make_pair(id,std::move(texture)));
assert(inserted.second);
}
sf::Texture& TextureHolder::get(Textures::ID id)
{
auto found = mTextureMap.find(id);
return *found->second;
}
the compiler like I said the default compiler that comes bundled with code::blocks : g++ I think I don't actually know
O and if its important I run ubuntu linux.