Changeset 9790 in orxonox.OLD for branches/new_class_id/src/lib/util/loading/resource.cc
- Timestamp:
- Sep 23, 2006, 10:34:42 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/loading/resource.cc
r9789 r9790 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD ING16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD 17 17 18 18 #include "resource.h" 19 19 #include "filesys/file.h" 20 #include "debug.h" 20 21 21 22 ObjectListDefinition(NewResource); 22 23 24 23 std::vector<NewResource::Type*> NewResource::_resourceTypes; 25 24 … … 36 35 { 37 36 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 }44 37 } 45 38 … … 53 46 54 47 55 std::string NewResource::locateFile(const std::string& fileName) 48 std::string NewResource::locateFile(const std::string& fileName) const 56 49 { 57 50 if (File(fileName).exists()) 58 51 return fileName; 59 else if ((NewResource::_mainGlobalPath +File(fileName)) .exists() )52 else if ((NewResource::_mainGlobalPath + File(fileName)).exists() ) 60 53 return (NewResource::_mainGlobalPath + File(fileName)).name(); 61 54 55 printf("LOCATED %s\n", locateFileInSubDir(Directory("/home/bensch/svn/orxonox/data/"), fileName).c_str()); 56 62 57 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 */ 66 std::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 65 80 66 81 … … 99 114 100 115 101 102 103 104 105 106 107 108 std::vector<std::string> NewResource::KeepLevel::_keepLevelNames; 116 void 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 127 bool 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 137 bool 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 149 void 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 168 std::vector<std::string> NewResource::KeepLevel::_keepLevelNames; 109 169 void NewResource::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name) 110 170 { … … 115 175 116 176 177 NewResource::Type::Type(const ClassID& classID) 178 : _id(-1), _classID(classID) 179 { 180 NewResource::registerType(this); 181 } 117 182 118 183 void NewResource::Type::addResource(NewResource::StorePointer* resource) … … 121 186 122 187 } 188 189 bool 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 200 bool 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 123 210 124 211
Note: See TracChangeset
for help on using the changeset viewer.