Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 23, 2006, 10:34:42 AM (18 years ago)
Author:
bensch
Message:

added new_resource_manager

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/util/loading/resource.cc

    r9789 r9790  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
    1717
    1818#include "resource.h"
    1919#include "filesys/file.h"
     20#include "debug.h"
    2021
    2122ObjectListDefinition(NewResource);
    22 
    23 
    2423std::vector<NewResource::Type*>    NewResource::_resourceTypes;
    2524
     
    3635{
    3736  this->registerObject(this, NewResource::_objectList);
    38 
    39   if(this->_type->id() == -1)
    40   {
    41     NewResource::_resourceTypes.push_back(this->_type);
    42     this->_type->setID(NewResource::_resourceTypes.size()-1);
    43   }
    4437}
    4538
     
    5346
    5447
    55 std::string NewResource::locateFile(const std::string& fileName)
     48std::string NewResource::locateFile(const std::string& fileName) const
    5649{
    5750  if (File(fileName).exists())
    5851    return fileName;
    59   else if ((NewResource::_mainGlobalPath+File(fileName)) . exists() )
     52  else if ((NewResource::_mainGlobalPath + File(fileName)).exists() )
    6053    return (NewResource::_mainGlobalPath + File(fileName)).name();
    6154
     55  printf("LOCATED %s\n", locateFileInSubDir(Directory("/home/bensch/svn/orxonox/data/"), fileName).c_str());
     56
    6257  return std::string("/home/bensch/svn/orxonox/data/") + fileName;
    63 
    64 }
     58}
     59
     60/**
     61 * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists.
     62 * @param directory the directory to in what to search for all subdirectories for.
     63 * @param fileName the Name of the File to query for
     64 * @return true on success.
     65 */
     66std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const
     67{
     68  std::vector<Directory>::const_iterator it;
     69  for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it)
     70  {
     71    Directory dir = directory + (*it);
     72    File file = dir + File(fileName);
     73    printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str());
     74    if ((dir+ File(fileName)).exists())
     75      return (dir+File(fileName)).name();
     76  }
     77  return "";
     78}
     79
    6580
    6681
     
    99114
    100115
    101 
    102 
    103 
    104 
    105 
    106 
    107 
    108 std::vector<std::string>  NewResource::KeepLevel::_keepLevelNames;
     116void NewResource::registerType(NewResource::Type* type)
     117{
     118  NewResource::debug();
     119  if(type->id() == -1)
     120  {
     121    NewResource::_resourceTypes.push_back(type);
     122    type->setID(NewResource::_resourceTypes.size()-1);
     123  }
     124  NewResource::debug();
     125}
     126
     127bool NewResource::addResourcePath(const std::string& resourceName, const std::string& pathName)
     128{
     129  std::vector<NewResource::Type*>::iterator it;
     130  for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)
     131    if (*(*it) == resourceName)
     132      return (*it)->addResourcePath(pathName);
     133  PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
     134  return false;
     135}
     136
     137bool NewResource::addResourceSubPath(const std::string& resourceName, const std::string& pathName)
     138{
     139  std::vector<NewResource::Type*>::iterator it;
     140  for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)
     141    if (*(*it) == resourceName)
     142      return (*it)->addResourceSubPath(pathName);
     143  PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
     144  return false;
     145}
     146
     147
     148
     149void NewResource::debug()
     150{
     151  PRINT(0)("==================================\n");
     152  PRINT(0)("DEBUG output for all Resources\n");
     153  PRINT(0)("==================================\n");
     154
     155  PRINT(0)("Listing %d Types: \n", NewResource::_resourceTypes.size());
     156  std::vector<NewResource::Type*>::iterator it;
     157  for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)
     158    PRINT(0)("ResourceType '%s'\n", (*it)->storedClassID().name().c_str());
     159
     160  PRINT(0)("==================================\n");
     161
     162}
     163
     164
     165
     166
     167
     168std::vector<std::string> NewResource::KeepLevel::_keepLevelNames;
    109169void NewResource::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name)
    110170{
     
    115175
    116176
     177NewResource::Type::Type(const ClassID& classID)
     178    : _id(-1), _classID(classID)
     179{
     180  NewResource::registerType(this);
     181}
    117182
    118183void NewResource::Type::addResource(NewResource::StorePointer* resource)
     
    121186
    122187}
     188
     189bool NewResource::Type::addResourcePath(const std::string& path)
     190{
     191  std::vector<Directory>::const_iterator it;
     192  for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it)
     193    if ((*it) == path)
     194      return false;
     195  this->_resourcePaths.push_back(path);
     196  return true;
     197
     198}
     199
     200bool NewResource::Type::addResourceSubPath(const std::string& subPath)
     201{
     202  std::vector<Directory>::const_iterator it;
     203  for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it)
     204    if ((*it) == subPath)
     205      return false;
     206  this->_resourceSubPaths.push_back(subPath);
     207  return true;
     208}
     209
    123210
    124211
Note: See TracChangeset for help on using the changeset viewer.