Hey guys, ive been using this imageManager, now i can use it find and what not, but I dont "fully" understand it, here is the header and cpp file
Everything with a //---// at the end i dont understand
imageManager.h
//Image manager header
#ifndef gIMAGEMANAGER_H
#define gIMAGEMANAGER_H
//Includes
#include <SFML/Graphics.hpp>
//Body
class gImageManager
{
public:
gImageManager();
~gImageManager();
private:
gImageManager( const gImageManager& ); //---//1a
gImageManager& operator =( const gImageManager& ); //---//1b
public:
const sf::Texture& get_image( const std::string& filename ); //---//1c
private:
std::map< std::string, sf::Texture > images_;
std::vector< std::string > resource_directories_;
};
//end body
#endif
1a = gImageManager passes a reference of another gImageManager???
1b = I have no idea with that function
1c = why does it use so many references? can i not just remove these?
imageManager.cpp
#include <map>
#include <iostream>
#include <SFML/Graphics.hpp>
#include "gImageManager.h"
gImageManager::gImageManager() : images_(), resource_directories_() //---//1a
{
}
gImageManager::~gImageManager() //---//1b
{
images_.clear();
resource_directories_.clear();
}
const sf::Texture& gImageManager::get_image( const std::string& filename )
{
// Check, whether the image already exists
for( std::map<std::string, sf::Texture>::const_iterator ci = images_.begin();
ci != images_.end();
++ci)
{
if( filename == ci->first ) //---// 1c
{
//std::cout << "DEBUG_MESSAGE: " << filename << " using existing image.\n";
return ci->second;
}
}
// The image doesen't exists. Create it and save it.
sf::Texture image;
// Search project's main directory
if( image.loadFromFile( filename ) )
{
images_[filename] = image;
//std::cout << "DEBUG_MESSAGE: " << filename << " loading image.\n";
return images_[filename];
}
/*// If the image has still not been found, search all registered directories
for( std::vector< std::string >::iterator it = resource_directories_.begin();
it != resource_directories_.end();
++it )
{
if( image.loadFromFile( (*it) + filename ) )
{
images_[filename] = image;
//std::cout << "DEBUG_MESSAGE: " << filename << " loading image.\n";
return images_[filename];
}
}*/
std::cout << "GAME_ERROR: Image was not found. It is filled with an empty image.\n";
images_[filename] = image;
return images_[filename];
}
1a = I just dont understand the : images_(), resource_directories_() after the gImageManager::gImageManager... what does that line do??? ": images_(), resource_directories_()"
1b = Im sure this is just the de-construction of the class, but im just making sure.
1c =
if it isnt the first item, then return the second item?
If anyone could just quickly explain these, it would be a great help
Canvas