Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3672 in orxonox.OLD for orxonox/trunk/src/lib/util


Ignore:
Timestamp:
Mar 30, 2005, 3:02:58 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: ResourceManager not totally static anymore, list-iterators, and so on

Location:
orxonox/trunk/src/lib/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/util/resource_manager.cc

    r3667 r3672  
    1111   ### File Specific:
    1212   main-programmer: Benjamin Grauer
    13    co-programmer: ...
     13   co-programmer: Patrick Boenzli
    1414*/
    1515
     
    3838{
    3939   this->setClassName ("ResourceManager");
    40    dataDir = NULL;
    41    imageDirs = new tList<char>();
    42    resourceList = new tList<Resource>();
     40   this->dataDir = "./";
     41   this->imageDirs = new tList<char>();
     42   this->resourceList = new tList<Resource>();
    4343}
    4444
     
    5555//! Singleton Reference to the ResourceManager
    5656ResourceManager* ResourceManager::singletonRef = NULL;
    57 //! The List of Resources, that has already been loaded.
    58 tList<Resource>* ResourceManager::resourceList = NULL;
    59 //! The Data Directory, where all relevant Data is stored.
    60 char* ResourceManager::dataDir = NULL;
    61 //! A list of directories in which images are stored.
    62 tList<char>* ResourceManager::imageDirs = NULL;
    6357
    6458/**
     
    6862{
    6963  // deleting the Resources-List
    70   unloadAllByPriority(RP_GAME);
    71   delete resourceList;
    72   resourceList = NULL;
     64  this->unloadAllByPriority(RP_GAME);
     65  delete this->resourceList;
    7366  // deleting the Directorie Lists
    74   char* tmpDir = imageDirs->enumerate();
     67  tIterator<char>* tmpIt = imageDirs->getIterator();
     68  char* tmpDir = tmpIt->nextElement();
    7569  while(tmpDir)
    7670    {
    7771      delete []tmpDir;
    78       tmpDir = imageDirs->nextElement();
    79     }
    80 
    81   delete imageDirs;
    82   imageDirs = NULL;
     72      tmpDir = tmpIt->nextElement();
     73    }
     74  delete tmpIt;
     75
     76  delete this->imageDirs;
     77
    8378  ResourceManager::singletonRef = NULL;
    8479}
     
    9287  if (isDir(dataDir))
    9388    {
    94       ResourceManager::dataDir = new char[strlen(dataDir)+1];
    95       strcpy(ResourceManager::dataDir, dataDir);
     89      this->dataDir = new char[strlen(dataDir)+1];
     90      strcpy(this->dataDir, dataDir);
    9691    }
    9792  else
     
    113108    {
    114109      // check if the Directory has been added before
    115       char* tmpDir = imageDirs->enumerate();
     110      tIterator<char>* tmpImageDirs = imageDirs->getIterator();
     111      char* tmpDir = tmpImageDirs->nextElement();
    116112      while(tmpDir)
    117113        {
     
    119115            {
    120116              PRINTF(4)("Path %s already loaded\n", imageDir);
     117              delete tmpImageDirs;
    121118              return true;
    122119            }
    123           tmpDir = imageDirs->nextElement();
    124         }
     120          tmpDir = tmpImageDirs->nextElement();
     121        }
     122      delete tmpImageDirs;
     123
    125124      // adding the directory to the List
    126125      tmpDir  = new char[strlen(imageDir)+1];
    127126      strcpy(tmpDir, imageDir);
    128       imageDirs->add(tmpDir);
     127      this->imageDirs->add(tmpDir);
    129128      return true;
    130129    }
     
    162161    tmpType = IMAGE;
    163162
    164   return ResourceManager::load(fileName, tmpType, prio);
     163  return this->load(fileName, tmpType, prio);
    165164}
    166165
     
    175174{
    176175  // searching if the resource was loaded before.
    177   Resource* tmpResource = ResourceManager::locateResourceByName(fileName);
     176  Resource* tmpResource = this->locateResourceByName(fileName);
    178177  if (!tmpResource) // if the resource was not loaded before.
    179178    {
     
    189188      // creating the full name. (directoryName + FileName)
    190189      char* fullName = new char[strlen(dataDir)+strlen(fileName)+1];
    191       sprintf(fullName, "%s%s", dataDir, fileName);
     190      sprintf(fullName, "%s%s", this->dataDir, fileName);
    192191     
    193192      // Checking for the type of resource \see ResourceType
     
    251250          tmpResource->pointer = NULL;
    252251        }
    253       resourceList->add(tmpResource);
     252      this->resourceList->add(tmpResource);
    254253      delete []fullName;
    255254    }
     
    274273{
    275274  // if pointer is existent. and only one resource of this type exists.
    276   Resource* tmpResource =ResourceManager::locateResourceByPointer(pointer);
     275  Resource* tmpResource = this->locateResourceByPointer(pointer);
    277276  if (!tmpResource)
    278277    {
     
    310309          PRINTF(4)("Resource %s safely removed.\n", resource->name);
    311310          delete []resource->name;
    312           resourceList->remove(resource);
     311          this->resourceList->remove(resource);
    313312        }
    314313      else
     
    327326bool ResourceManager::unloadAllByPriority(ResourcePriority prio)
    328327{
    329 
    330328  tIterator<Resource>* iterator = resourceList->getIterator();
    331329  Resource* enumRes = iterator->nextElement();
  • orxonox/trunk/src/lib/util/resource_manager.h

    r3660 r3672  
    5656  virtual ~ResourceManager();
    5757
    58   static bool setDataDir(char* dataDir);
    59   static bool addImageDir(char* imageDir);
    60   static void* load(const char* fileName, ResourcePriority prio = RP_NO);
    61   static void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO);
    62   static bool unload(void* pointer, ResourcePriority prio = RP_NO);
    63   static bool unload(Resource* resource, ResourcePriority = RP_NO);
    64   static bool unloadAllByPriority(ResourcePriority prio);
     58  bool setDataDir(char* dataDir);
     59  bool addImageDir(char* imageDir);
     60  void* load(const char* fileName, ResourcePriority prio = RP_NO);
     61  void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO);
     62  bool unload(void* pointer, ResourcePriority prio = RP_NO);
     63  bool unload(Resource* resource, ResourcePriority = RP_NO);
     64  bool unloadAllByPriority(ResourcePriority prio);
    6565
    6666 private:
     
    6868  static ResourceManager* singletonRef;
    6969
    70   static tList<Resource>* resourceList;
    71   static char* dataDir;
    72   static tList<char>* imageDirs;
     70  tList<Resource>* resourceList;       //!< The List of Resources, that has already been loaded.
     71  char* dataDir;                       //!< The Data Directory, where all relevant Data is stored.
     72  tList<char>* imageDirs;              //!< A list of directories in which images are stored.
    7373
    74   static Resource* locateResourceByName(const char* fileName);
    75   static Resource* locateResourceByPointer(const void* pointer);
     74
     75  Resource* locateResourceByName(const char* fileName);
     76  Resource* locateResourceByPointer(const void* pointer);
    7677 
    77   static bool isDir(const char* directory);
    78   static bool isFile(const char* directory); 
     78  bool isDir(const char* directory);
     79  bool isFile(const char* directory); 
    7980};
    8081
Note: See TracChangeset for help on using the changeset viewer.