Changeset 9800 in orxonox.OLD for branches/new_class_id/src/lib/util/loading/resource.cc
- Timestamp:
- Sep 24, 2006, 12:12:14 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/loading/resource.cc
r9799 r9800 21 21 #include "debug.h" 22 22 23 ObjectListDefinition(NewResource); 23 24 namespace Resources 25 { 26 ObjectListDefinition(NewResource); 24 27 25 28 26 /**27 * standard constructor28 */29 NewResource::NewResource (Resources::Type* type)30 : _pointer(NULL), _type(type)31 {32 this->registerObject(this, NewResource::_objectList);33 }29 /** 30 * standard constructor 31 */ 32 NewResource::NewResource (Type* type) 33 : _pointer(NULL), _type(type) 34 { 35 this->registerObject(this, NewResource::_objectList); 36 } 34 37 35 /**36 * standard deconstructor37 */38 NewResource::~NewResource ()39 {40 // delete what has to be deleted here41 }38 /** 39 * standard deconstructor 40 */ 41 NewResource::~NewResource () 42 { 43 // delete what has to be deleted here 44 } 42 45 43 46 44 std::string NewResource::locateFile(const std::string& fileName) const 45 { 46 if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() ) 47 std::string NewResource::locateFile(const std::string& fileName) const 48 { 49 if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() ) 50 return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 51 52 std::string locatedFile; 53 locatedFile = locateFileInSubDir(NewResourceManager::getInstance()->mainGlobalPath(), fileName); 54 if (!locatedFile.empty()) 55 { 56 printf("FILE found %s\n", locatedFile.c_str()); 57 return locatedFile; 58 } 59 60 if (File(fileName).exists()) 61 return fileName; 62 47 63 return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 48 49 std::string locatedFile;50 locatedFile = locateFileInSubDir(NewResourceManager::getInstance()->mainGlobalPath(), fileName);51 if (!locatedFile.empty())52 {53 printf("FILE found %s\n", locatedFile.c_str());54 return locatedFile;55 64 } 56 65 57 if (File(fileName).exists()) 58 return fileName; 59 60 return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 61 } 62 63 /** 64 * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists. 65 * @param directory the directory to in what to search for all subdirectories for. 66 * @param fileName the Name of the File to query for 67 * @return true on success. 68 */ 69 std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const 70 { 71 std::vector<Directory>::const_iterator it; 72 for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it) 66 /** 67 * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists. 68 * @param directory the directory to in what to search for all subdirectories for. 69 * @param fileName the Name of the File to query for 70 * @return true on success. 71 */ 72 std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const 73 73 { 74 Directory dir = directory + (*it); 75 File file = dir + File(fileName); 76 printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str()); 77 if ((dir+ File(fileName)).exists()) 78 return (dir+File(fileName)).name(); 74 std::vector<Directory>::const_iterator it; 75 for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it) 76 { 77 Directory dir = directory + (*it); 78 File file = dir + File(fileName); 79 printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str()); 80 if ((dir+ File(fileName)).exists()) 81 return (dir+File(fileName)).name(); 82 } 83 return ""; 79 84 } 80 return "";81 }82 85 83 86 84 87 85 Resources::StorePointer* NewResource::acquireResource(const std::string& loadString)86 {87 //const Resources::Type* const type = Resources::_resourceTypes[this->_type->id()];88 StorePointer* NewResource::acquireResource(const std::string& loadString) 89 { 90 //const Type* const type = _resourceTypes[this->_type->id()]; 88 91 89 for (unsigned int i = 0; i < _type->storedResources().size(); ++i) 90 { 91 if (_type->storedResources()[i]->loadString() == loadString) 92 return _type->storedResources()[i]; 92 for (unsigned int i = 0; i < _type->storedResources().size(); ++i) 93 { 94 if (_type->storedResources()[i]->loadString() == loadString) 95 return _type->storedResources()[i]; 96 } 97 98 return NULL; 93 99 } 94 100 95 return NULL;96 }97 101 98 99 void NewResource::addResource(Resources::StorePointer* pointer) 100 { 101 this->_type->addResource(pointer); 102 } 102 void NewResource::addResource(StorePointer* pointer) 103 { 104 this->_type->addResource(pointer); 105 } 103 106 104 107 … … 107 110 108 111 109 ///////////////////110 //// KEEPLEVEL ////111 ///////////////////112 Resources::KeepLevel::KeepLevel(const std::string& keepLevelName)113 {114 this->_keepLevel = NewResourceManager::getInstance()->getKeepLevelID(keepLevelName);115 }112 /////////////////// 113 //// KEEPLEVEL //// 114 /////////////////// 115 KeepLevel::KeepLevel(const std::string& keepLevelName) 116 { 117 this->_keepLevel = NewResourceManager::getInstance()->getKeepLevelID(keepLevelName); 118 } 116 119 117 const std::string& Resources::KeepLevel::name() const118 {119 return NewResourceManager::getInstance()->getKeepLevelName(this->_keepLevel);120 }120 const std::string& KeepLevel::name() const 121 { 122 return NewResourceManager::getInstance()->getKeepLevelName(this->_keepLevel); 123 } 121 124 122 125 123 126 124 ///////////////////////125 //// STORE POINTER ////126 ///////////////////////127 Resources::StorePointer::StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel)128 : _loadString(loadString), _keepLevel(keeplevel)129 {}127 /////////////////////// 128 //// STORE POINTER //// 129 /////////////////////// 130 StorePointer::StorePointer(const std::string& loadString, const KeepLevel& keeplevel) 131 : _loadString(loadString), _keepLevel(keeplevel) 132 {} 130 133 131 134 132 135 133 136 134 //////////////135 //// TYPE ////136 //////////////137 Resources::Type::Type(const std::string& typeName)138 : _id(-1), _typeName(typeName)139 {140 NewResourceManager::getInstance()->registerType(this);141 PRINTF(4)("Created ResourceType '%s'\n", typeName.c_str());142 }137 ////////////// 138 //// TYPE //// 139 ////////////// 140 Type::Type(const std::string& typeName) 141 : _id(-1), _typeName(typeName) 142 { 143 NewResourceManager::getInstance()->registerType(this); 144 PRINTF(4)("Created ResourceType '%s'\n", typeName.c_str()); 145 } 143 146 144 Resources::Type::~Type()145 {146 NewResourceManager::getInstance()->unregisterType(this);147 }147 Type::~Type() 148 { 149 NewResourceManager::getInstance()->unregisterType(this); 150 } 148 151 149 void Resources::Type::addResource(Resources::StorePointer* resource)150 {151 this->_storedResources.push_back(resource);152 void Type::addResource(StorePointer* resource) 153 { 154 this->_storedResources.push_back(resource); 152 155 153 }156 } 154 157 155 bool Resources::Type::addResourcePath(const std::string& path)156 {157 std::vector<Directory>::const_iterator it;158 for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it)159 if ((*it) == path)160 return false;161 this->_resourcePaths.push_back(path);162 return true;158 bool Type::addResourcePath(const std::string& path) 159 { 160 std::vector<Directory>::const_iterator it; 161 for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it) 162 if ((*it) == path) 163 return false; 164 this->_resourcePaths.push_back(path); 165 return true; 163 166 164 }167 } 165 168 166 bool Resources::Type::addResourceSubPath(const std::string& subPath)167 {168 std::vector<Directory>::const_iterator it;169 for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it)170 if ((*it) == subPath)171 return false;172 this->_resourceSubPaths.push_back(subPath);173 return true;174 }169 bool Type::addResourceSubPath(const std::string& subPath) 170 { 171 std::vector<Directory>::const_iterator it; 172 for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it) 173 if ((*it) == subPath) 174 return false; 175 this->_resourceSubPaths.push_back(subPath); 176 return true; 177 } 175 178 176 179 177 void Resources::Type::setID(int id)178 {179 this->_id = id;180 }180 void Type::setID(int id) 181 { 182 this->_id = id; 183 } 181 184 182 185 183 void Resources::Type::debug() const184 {185 PRINT(0)(" ResourceType '%s' with ID %d stores %d Resources\n", this->_typeName.c_str(), this->_id, this->_storedResources.size());186 PRINT(0)(" Paths:\n");187 for (unsigned int i = 0; i < this->_resourcePaths.size(); ++i)188 PRINT(0)(" %s\n", this->_resourcePaths[i].name().c_str());189 PRINT(0)(" Sub-Paths:");190 for (unsigned int i = 0; i < this->_resourceSubPaths.size(); ++i)191 PRINT(0)(" '%s'", this->_resourceSubPaths[i].name().c_str());192 PRINT(0)("\n");186 void Type::debug() const 187 { 188 PRINT(0)(" ResourceType '%s' with ID %d stores %d Resources\n", this->_typeName.c_str(), this->_id, this->_storedResources.size()); 189 PRINT(0)(" Paths:\n"); 190 for (unsigned int i = 0; i < this->_resourcePaths.size(); ++i) 191 PRINT(0)(" %s\n", this->_resourcePaths[i].name().c_str()); 192 PRINT(0)(" Sub-Paths:"); 193 for (unsigned int i = 0; i < this->_resourceSubPaths.size(); ++i) 194 PRINT(0)(" '%s'", this->_resourceSubPaths[i].name().c_str()); 195 PRINT(0)("\n"); 193 196 197 } 194 198 }
Note: See TracChangeset
for help on using the changeset viewer.