Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

namespaces

File size: 5.0 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
[9785]23
[9800]24namespace Resources
[3365]25{
[9800]26  ObjectListDefinition(NewResource);
[1853]27
[9783]28
[9800]29  /**
30   * standard constructor
31  */
32  NewResource::NewResource (Type* type)
33      : _pointer(NULL), _type(type)
34  {
35    this->registerObject(this, NewResource::_objectList);
36  }
[9783]37
[9800]38  /**
39   * standard deconstructor
40   */
41  NewResource::~NewResource ()
42  {
43    // delete what has to be deleted here
44  }
45
46
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
[9791]63    return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name();
[9800]64  }
[9783]65
[9800]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
[9793]73  {
[9800]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 "";
[9793]84  }
[9795]85
[9799]86
[9785]87
[9800]88  StorePointer* NewResource::acquireResource(const std::string& loadString)
[9790]89  {
[9800]90    //const Type* const type = _resourceTypes[this->_type->id()];
[9785]91
[9800]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    }
[9785]97
[9800]98    return NULL;
99  }
[9790]100
[9783]101
[9800]102  void NewResource::addResource(StorePointer* pointer)
[9786]103  {
[9800]104    this->_type->addResource(pointer);
[9786]105  }
[9783]106
107
108
[9784]109
[9785]110
111
[9800]112  ///////////////////
113  //// KEEPLEVEL ////
114  ///////////////////
115  KeepLevel::KeepLevel(const std::string& keepLevelName)
116  {
117    this->_keepLevel = NewResourceManager::getInstance()->getKeepLevelID(keepLevelName);
118  }
[9785]119
[9800]120  const std::string& KeepLevel::name() const
121  {
122    return NewResourceManager::getInstance()->getKeepLevelName(this->_keepLevel);
123  }
[9785]124
125
[9790]126
[9800]127  ///////////////////////
128  //// STORE POINTER ////
129  ///////////////////////
130  StorePointer::StorePointer(const std::string& loadString, const KeepLevel& keeplevel)
131      : _loadString(loadString), _keepLevel(keeplevel)
132  {}
[9790]133
[9798]134
[9799]135
[9790]136
[9800]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  }
[9790]146
[9800]147  Type::~Type()
148  {
149    NewResourceManager::getInstance()->unregisterType(this);
150  }
[9790]151
[9800]152  void Type::addResource(StorePointer* resource)
153  {
154    this->_storedResources.push_back(resource);
[9785]155
[9800]156  }
[9785]157
[9800]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;
[9799]166
[9800]167  }
[9785]168
[9800]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  }
[9785]178
179
[9800]180  void Type::setID(int id)
181  {
182    this->_id = id;
183  }
[9790]184
185
[9800]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");
[9790]196
[9800]197  }
[9785]198}
Note: See TracBrowser for help on using the repository browser.