Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/resource.cc @ 9792

Last change on this file since 9792 was 9792, checked in by bensch, 18 years ago

removed dependency from ClassID

File size: 4.1 KB
RevLine 
[4744]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[7195]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[9790]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
[1853]17
[7193]18#include "resource.h"
[9791]19#include "new_resource_manager.h"
20
[9790]21#include "debug.h"
[1853]22
[9788]23ObjectListDefinition(NewResource);
[9785]24
25
[3245]26/**
[4838]27 * standard constructor
[3245]28*/
[9791]29NewResource::NewResource (Resources::Type* type)
[9785]30    : _pointer(NULL), _type(type)
[3365]31{
[9788]32  this->registerObject(this, NewResource::_objectList);
[3365]33}
[1853]34
[3245]35/**
[4838]36 * standard deconstructor
[7195]37 */
[9788]38NewResource::~NewResource ()
[3543]39{
40  // delete what has to be deleted here
41}
[9783]42
43
[9790]44std::string NewResource::locateFile(const std::string& fileName) const
[9785]45{
46  if (File(fileName).exists())
47    return fileName;
[9791]48  else if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() )
49    return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name();
[9783]50
[9790]51  printf("LOCATED %s\n", locateFileInSubDir(Directory("/home/bensch/svn/orxonox/data/"), fileName).c_str());
52
[9785]53  return std::string("/home/bensch/svn/orxonox/data/") + fileName;
[9790]54}
[9785]55
[9790]56/**
57 * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists.
58 * @param directory the directory to in what to search for all subdirectories for.
59 * @param fileName the Name of the File to query for
60 * @return true on success.
61 */
62std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const
63{
64  std::vector<Directory>::const_iterator it;
65  for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it)
66  {
67    Directory dir = directory + (*it);
68    File file = dir + File(fileName);
69    printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str());
70    if ((dir+ File(fileName)).exists())
71      return (dir+File(fileName)).name();
72  }
73  return "";
[9785]74}
75
76
[9790]77
[9791]78Resources::StorePointer* NewResource::acquireResource(const std::string& loadString)
[9784]79{
[9791]80  //const Resources::Type* const type = Resources::_resourceTypes[this->_type->id()];
[9783]81
[9785]82  for (unsigned int i = 0; i < _type->storedResources().size(); ++i)
[9786]83  {
84    if (_type->storedResources()[i]->loadString() == loadString)
85      return _type->storedResources()[i];
86  }
[9783]87
[9784]88  return NULL;
89}
[9783]90
91
[9791]92void NewResource::addResource(Resources::StorePointer* pointer)
[9785]93{
[9786]94  this->_type->addResource(pointer);
95}
[9784]96
[9785]97
98
99
100
101
[9791]102///////////////////
103//// KEEPLEVEL ////
104///////////////////
105std::vector<std::string> Resources::KeepLevel::_keepLevelNames;
106void Resources::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name)
[9790]107{
[9791]108  if (_keepLevelNames.size() <= level)
109    _keepLevelNames.resize(level+1);
110  _keepLevelNames[level] = name;
[9790]111}
112
113
[9791]114///////////////////////
115//// STORE POINTER ////
116///////////////////////
117Resources::StorePointer::StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel)
118  : _loadString(loadString), _keepLevel(keeplevel)
119{}
[9790]120
121
122
[9785]123
[9791]124//////////////
125//// TYPE ////
126//////////////
[9792]127Resources::Type::Type(const std::string& typeName)
128    : _id(-1), _typeName(typeName)
[9790]129{
[9791]130  NewResourceManager::getInstance()->registerType(this);
[9790]131}
[9785]132
[9791]133void Resources::Type::addResource(Resources::StorePointer* resource)
[9786]134{
135  this->_storedResources.push_back(resource);
[9785]136
[9786]137}
[9785]138
[9791]139bool Resources::Type::addResourcePath(const std::string& path)
[9790]140{
141  std::vector<Directory>::const_iterator it;
142  for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it)
143    if ((*it) == path)
144      return false;
145  this->_resourcePaths.push_back(path);
146  return true;
[9785]147
[9790]148}
149
[9791]150bool Resources::Type::addResourceSubPath(const std::string& subPath)
[9790]151{
152  std::vector<Directory>::const_iterator it;
153  for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it)
154    if ((*it) == subPath)
155      return false;
156  this->_resourceSubPaths.push_back(subPath);
157  return true;
158}
159
160
[9791]161void Resources::Type::setID(int id)
[9785]162{
163  this->_id = id;
164}
Note: See TracBrowser for help on using the repository browser.