Access specific part of list

closed account (1yvXoG1T)
Right now I'm trying to write a graphics manager for a project in SFML.
My idea is that whenever an object is made it checks with a list to see if the image for that object has been loaded before and if not then load the image and save the address for that image in a list.
Currently it looks vaguely like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
std::list<std::string> StrList; //This stores the filenames to compare
std::list<sf::Image*>  ImgList; //This stores the addresses so I don't have to reload an image everytime I make a new instance

sf::Image*
GFXManager::LoadImage(string fileName) {
     for(std::list<std::string>::iterator it = StrList.begin(); it != StrList.end(); it++) {
          if(*it == filename)
               //Insert code for getting address
     }
     
     StrList.push_back(fileName);

     sf::Image Image;
     if(!Image.LoadFromFile(fileName))
          exit(1);
     ImgList.push_back(&Image);
     //Insert return end of list statement
}


Any suggestions on how to retrieve the proper address?
1
2
3
4
5
6
7
8
struct cache{
  std::string name;
  sf::Image *address;
};

for(std::list<cache>::iterator it = StrList.begin(); it != StrList.end(); it++)
  if(it->name == filename)
    return it->address;
Last edited on
closed account (1yvXoG1T)
Umm... How is that going to help? I'm already storing the values but I need a way to be able to know if I'm accessing the right addresses.

Example:
1
2
3
Object obj1;   //It starts up, loads the image and all that other jazz
Object obj2;   /*Checks and finds that the file has been loaded but 
                          doesn't know what address to refer to for that image*/

Unless I'm missing how a struct that contains two variables can somehow refer me to the right address.

You have to assume that this system is going to load anywhere from 1 to 1,000,000 images (not literally going to be that many but it has to be flexible enough to where it could)
If I understand you, every string corresponds to one Image * (the address stored). So you can map the the two variables std::map<std::string, sf::Image *> cache;
closed account (1yvXoG1T)
Ahhh.. I see. That map makes all the difference. I should have this manager up and running soon. Thanks for the help :D
Topic archived. No new replies allowed.