Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

nicer definition of the StorePointer

File size: 3.0 KB
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
17
18#include "resource.h"
19#include "filesys/file.h"
20
21ObjectListDefinition(NewResource);
22
23
24std::vector<NewResource::Type*>    NewResource::_resourceTypes;
25
26//! GLOBALS
27Directory NewResource::_mainGlobalPath;
28std::vector<Directory>        NewResource::_globalPaths;
29
30
31/**
32 * standard constructor
33*/
34NewResource::NewResource (NewResource::Type* type)
35    : _pointer(NULL), _type(type)
36{
37  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}
45
46/**
47 * standard deconstructor
48 */
49NewResource::~NewResource ()
50{
51  // delete what has to be deleted here
52}
53
54
55std::string NewResource::locateFile(const std::string& fileName)
56{
57  if (File(fileName).exists())
58    return fileName;
59  else if ((NewResource::_mainGlobalPath+File(fileName)) . exists() )
60    return (NewResource::_mainGlobalPath + File(fileName)).name();
61
62  return std::string("/home/bensch/svn/orxonox/data/") + fileName;
63
64}
65
66
67NewResource::StorePointer* NewResource::acquireResource(const std::string& loadString)
68{
69  //const NewResource::Type* const type = NewResource::_resourceTypes[this->_type->id()];
70
71  for (unsigned int i = 0; i < _type->storedResources().size(); ++i)
72  {
73    if (_type->storedResources()[i]->loadString() == loadString)
74      return _type->storedResources()[i];
75  }
76
77  return NULL;
78}
79
80void NewResource::setMainGlobalPath(const Directory& directory)
81{
82  NewResource::_mainGlobalPath = directory;
83  NewResource::_mainGlobalPath.open();
84}
85
86void NewResource::addGlobalPath(const Directory& directory)
87{
88  std::vector<Directory>::const_iterator it = std::find(NewResource::_globalPaths.begin(), NewResource::_globalPaths.end(), directory);
89  if (it == NewResource::_globalPaths.end())
90    NewResource::_globalPaths.push_back(directory);
91}
92
93
94
95void NewResource::addResource(NewResource::StorePointer* pointer)
96{
97  this->_type->addResource(pointer);
98}
99
100
101
102
103
104
105
106
107
108std::vector<std::string>  NewResource::KeepLevel::_keepLevelNames;
109void NewResource::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name)
110{
111  if (_keepLevelNames.size() <= level)
112    _keepLevelNames.resize(level+1);
113  _keepLevelNames[level] = name;
114}
115
116
117
118void NewResource::Type::addResource(NewResource::StorePointer* resource)
119{
120  this->_storedResources.push_back(resource);
121
122}
123
124
125NewResource::StorePointer::StorePointer(const std::string& loadString, const NewResource::KeepLevel& keeplevel)
126    : _loadString(loadString), _keepLevel(keeplevel)
127{}
128
129
130void NewResource::Type::setID(int id)
131{
132  this->_id = id;
133}
Note: See TracBrowser for help on using the repository browser.