Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9800 in orxonox.OLD for branches/new_class_id/src/lib


Ignore:
Timestamp:
Sep 24, 2006, 12:12:14 PM (18 years ago)
Author:
bensch
Message:

namespaces

Location:
branches/new_class_id/src/lib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/graphics/importer/resource_texture.h

    r9791 r9800  
    1212
    1313
    14 class ResourceTexture : public Texture, public NewResource
     14class ResourceTexture : public Texture, public Resources::NewResource
    1515{
    1616public:
  • branches/new_class_id/src/lib/shell/some_shell_commands.cc

    r9794 r9800  
    5353
    5454#include "loading/new_resource_manager.h"
    55 SHELL_COMMAND(debug, NewResourceManager, debug);
    56 
     55namespace Resources
     56{SHELL_COMMAND(debug, NewResourceManager, debug);}
    5757
    5858#include "loading/load_param_class_description.h"
  • branches/new_class_id/src/lib/util/loading/new_resource_manager.cc

    r9799 r9800  
    2222#include <cassert>
    2323
    24 ObjectListDefinition(NewResourceManager);
     24
     25namespace Resources
     26{
     27  ObjectListDefinition(NewResourceManager);
     28  //! Singleton Reference to the NewResourceManager
     29  NewResourceManager* NewResourceManager::_singletonRef = NULL;
    2530
    2631
    27 //! Singleton Reference to the NewResourceManager
    28 NewResourceManager* NewResourceManager::_singletonRef = NULL;
     32  /**
     33   * @brief standard constructor
     34  */
     35  NewResourceManager::NewResourceManager ()
     36  {
     37    this->registerObject(this, NewResourceManager::_objectList);
     38    this->setName("NewResourceManager");
     39
     40    //this->dataDir = "./";
     41  }
    2942
    3043
    31 /**
    32  * @brief standard constructor
    33 */
    34 NewResourceManager::NewResourceManager ()
    35 {
    36   this->registerObject(this, NewResourceManager::_objectList);
    37   this->setName("NewResourceManager");
     44  /**
     45   * @brief standard destructor
     46  */
     47  NewResourceManager::~NewResourceManager ()
     48  {
     49    // deleting the Resources-List
     50    //this->unloadAllByPriority(RP_GAME);
    3851
    39   //this->dataDir = "./";
    40 }
     52    //   if (!this->resourceList.empty())
     53    //     PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
    4154
    42 
    43 /**
    44  * @brief standard destructor
    45 */
    46 NewResourceManager::~NewResourceManager ()
    47 {
    48   // deleting the Resources-List
    49   //this->unloadAllByPriority(RP_GAME);
    50 
    51   //   if (!this->resourceList.empty())
    52   //     PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
    53 
    54   NewResourceManager::_singletonRef = NULL;
    55 }
     55    NewResourceManager::_singletonRef = NULL;
     56  }
    5657
    5758
    5859
    5960
    60 void NewResourceManager::registerType(Resources::Type* type)
    61 {
    62   if(type->id() == -1)
     61  void NewResourceManager::registerType(Resources::Type* type)
    6362  {
    64     type->setID(this->_resourceTypes.size());
    65     this->_resourceTypes.push_back(type);
    66     PRINTF(5)("ResourceType '%s' with ID %d added\n", type->storedClassName().c_str(), type->id());
     63    if(type->id() == -1)
     64    {
     65      type->setID(this->_resourceTypes.size());
     66      this->_resourceTypes.push_back(type);
     67      PRINTF(5)("ResourceType '%s' with ID %d added\n", type->storedClassName().c_str(), type->id());
     68    }
    6769  }
    68 }
    6970
    70 void NewResourceManager::unregisterType(Resources::Type* type)
    71 {
    72   std::vector<Resources::Type*>::iterator it = std::find (this->_resourceTypes.begin(), this->_resourceTypes.end(), type);
    73   if (it != this->_resourceTypes.end())
     71  void NewResourceManager::unregisterType(Resources::Type* type)
    7472  {
    75     this->_resourceTypes.erase(it);
    76     PRINTF(5)("ResourceType '%s' with ID %d removed\n", type->storedClassName().c_str(), type->id());
     73    std::vector<Resources::Type*>::iterator it = std::find (this->_resourceTypes.begin(), this->_resourceTypes.end(), type);
     74    if (it != this->_resourceTypes.end())
     75    {
     76      this->_resourceTypes.erase(it);
     77      PRINTF(5)("ResourceType '%s' with ID %d removed\n", type->storedClassName().c_str(), type->id());
     78    }
    7779  }
    78 }
    7980
    8081
    81 void NewResourceManager::setMainGlobalPath(const Directory& directory)
    82 {
    83   this->_mainGlobalPath = directory;
    84   this->_mainGlobalPath.open();
    85 }
     82  void NewResourceManager::setMainGlobalPath(const Directory& directory)
     83  {
     84    this->_mainGlobalPath = directory;
     85    this->_mainGlobalPath.open();
     86  }
    8687
    87 void NewResourceManager::addGlobalPath(const Directory& directory)
    88 {
    89   std::vector<Directory>::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory);
    90   if (it == this->_globalPaths.end())
    91     this->_globalPaths.push_back(directory);
    92 }
     88  void NewResourceManager::addGlobalPath(const Directory& directory)
     89  {
     90    std::vector<Directory>::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory);
     91    if (it == this->_globalPaths.end())
     92      this->_globalPaths.push_back(directory);
     93  }
    9394
    9495
    95 bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName)
    96 {
    97   std::vector<Resources::Type*>::iterator it;
    98   for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
    99     if (*(*it) == resourceName)
    100       return (*it)->addResourcePath(pathName);
    101   PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
    102   return false;
    103 }
     96  bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName)
     97  {
     98    std::vector<Resources::Type*>::iterator it;
     99    for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
     100      if (*(*it) == resourceName)
     101        return (*it)->addResourcePath(pathName);
     102    PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
     103    return false;
     104  }
    104105
    105 bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName)
    106 {
    107   std::vector<Resources::Type*>::iterator it;
    108   for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
    109     if (*(*it) == resourceName)
    110       return (*it)->addResourceSubPath(pathName);
    111   PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
    112   return false;
    113 }
     106  bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName)
     107  {
     108    std::vector<Resources::Type*>::iterator it;
     109    for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
     110      if (*(*it) == resourceName)
     111        return (*it)->addResourceSubPath(pathName);
     112    PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());
     113    return false;
     114  }
    114115
    115116
    116117
    117 bool NewResourceManager::checkFileInMainPath(const File& fileInside)
    118 {
    119   return (this->_mainGlobalPath + fileInside).exists();
    120 }
     118  bool NewResourceManager::checkFileInMainPath(const File& fileInside)
     119  {
     120    return (this->_mainGlobalPath + fileInside).exists();
     121  }
    121122
    122123
    123124
    124 unsigned int NewResourceManager::addKeepLevelName(const std::string& keepLevelName)
    125 {
    126   this->_keepLevelNames.push_back(keepLevelName);
    127   return _keepLevelNames.size()-1;
    128 }
     125  unsigned int NewResourceManager::addKeepLevelName(const std::string& keepLevelName)
     126  {
     127    this->_keepLevelNames.push_back(keepLevelName);
     128    return _keepLevelNames.size()-1;
     129  }
    129130
    130 unsigned int NewResourceManager::getKeepLevelID(const std::string& keepLevelName) const
    131 {
    132   for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)
    133     if (this->_keepLevelNames[i] == keepLevelName)
    134       return i;
     131  unsigned int NewResourceManager::getKeepLevelID(const std::string& keepLevelName) const
     132  {
     133    for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)
     134      if (this->_keepLevelNames[i] == keepLevelName)
     135        return i;
    135136
    136   PRINTF(2)("KeepLevel '%s' not found. Using 0 instead\n", keepLevelName.c_str());
    137   return 0;
    138 }
     137    PRINTF(2)("KeepLevel '%s' not found. Using 0 instead\n", keepLevelName.c_str());
     138    return 0;
     139  }
    139140
    140 const std::string& NewResourceManager::getKeepLevelName(unsigned int keepLevelID) const
    141 {
    142   assert(keepLevelID < this->_keepLevelNames.size());
    143   return this->_keepLevelNames[keepLevelID];
    144 }
     141  const std::string& NewResourceManager::getKeepLevelName(unsigned int keepLevelID) const
     142  {
     143    assert(keepLevelID < this->_keepLevelNames.size());
     144    return this->_keepLevelNames[keepLevelID];
     145  }
    145146
    146147
    147 /**
    148  * @brief outputs debug information about the NewResourceManager
    149  */
    150 void NewResourceManager::debug() const
    151 {
    152   PRINT(0)("=RM===================================\n");
    153   PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
    154   PRINT(0)("======================================\n");
    155   PRINT(0)(" MainGlobal search path is %s\n", this->_mainGlobalPath.name().c_str());
    156   if(!this->_globalPaths.empty())
     148  /**
     149   * @brief outputs debug information about the NewResourceManager
     150   */
     151  void NewResourceManager::debug() const
    157152  {
    158     PRINT(0)(" Additional Global search Paths are: ");
    159     for (unsigned int i = 0; i < this->_globalPaths.size(); ++i)
    160       PRINT(0)("'%s' ", this->_globalPaths[i].name().c_str());
     153    PRINT(0)("=RM===================================\n");
     154    PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
     155    PRINT(0)("======================================\n");
     156    PRINT(0)(" MainGlobal search path is %s\n", this->_mainGlobalPath.name().c_str());
     157    if(!this->_globalPaths.empty())
     158    {
     159      PRINT(0)(" Additional Global search Paths are: ");
     160      for (unsigned int i = 0; i < this->_globalPaths.size(); ++i)
     161        PRINT(0)("'%s' ", this->_globalPaths[i].name().c_str());
     162      PRINT(0)("\n");
     163    }
     164    PRINT(0)(" Listing %d Types: \n", this->_resourceTypes.size());
     165    std::vector<Resources::Type*>::const_iterator it;
     166    for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
     167    {
     168      (*it)->debug();
     169      if (it != --this->_resourceTypes.end())
     170        PRINT(0)(" ------------------------------------\n ");
     171    }
     172
     173    PRINT(0)("KeepLevels are: ");
     174    for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)
     175      PRINT(0)("%d:'%s'  ", i, this->_keepLevelNames[i].c_str());
    161176    PRINT(0)("\n");
     177    PRINT(0)("==================================RM==\n");
    162178  }
    163   PRINT(0)(" Listing %d Types: \n", this->_resourceTypes.size());
    164   std::vector<Resources::Type*>::const_iterator it;
    165   for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
    166   {
    167     (*it)->debug();
    168     if (it != --this->_resourceTypes.end())
    169       PRINT(0)(" ------------------------------------\n ");
    170   }
    171 
    172   PRINT(0)("KeepLevels are: ");
    173   for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)
    174     PRINT(0)("%d:'%s'  ", i, this->_keepLevelNames[i].c_str());
    175   PRINT(0)("\n");
    176   PRINT(0)("==================================RM==\n");
    177179}
  • branches/new_class_id/src/lib/util/loading/new_resource_manager.h

    r9799 r9800  
    1010#include "filesys/directory.h"
    1111
    12 class NewResourceManager : public BaseObject
     12namespace Resources
    1313{
    14   ObjectListDeclaration(NewResourceManager);
    15 public:
    16   /** @returns a Pointer to the only object of this Class */
    17   inline static NewResourceManager* getInstance() { if (!_singletonRef) _singletonRef = new NewResourceManager();  return _singletonRef; };
     14
     15  class NewResourceManager : public BaseObject
     16  {
     17    ObjectListDeclaration(NewResourceManager);
     18  public:
     19    /** @returns a Pointer to the only object of this Class */
     20    inline static NewResourceManager* getInstance() { if (!_singletonRef) _singletonRef = new NewResourceManager();  return _singletonRef; };
    1821  inline static void deleteInstance() { if (_singletonRef) delete _singletonRef; };
    1922
    2023
    21   void setMainGlobalPath(const Directory& directory);
    22   void addGlobalPath(const Directory& directory);
     24    void setMainGlobalPath(const Directory& directory);
     25    void addGlobalPath(const Directory& directory);
    2326
    24   bool addResourcePath(const std::string& resourceName, const std::string& pathName);
    25   bool addResourceSubPath(const std::string& resourceName, const std::string& pathName);
    26   void registerType(Resources::Type* type);
    27   void unregisterType(Resources::Type* type);
     27    bool addResourcePath(const std::string& resourceName, const std::string& pathName);
     28    bool addResourceSubPath(const std::string& resourceName, const std::string& pathName);
     29    void registerType(Resources::Type* type);
     30    void unregisterType(Resources::Type* type);
    2831
    29   unsigned int addKeepLevelName(const std::string& keepLevelName);
    30   unsigned int getKeepLevelID(const std::string& keepLevelName) const;
    31   const std::string& getKeepLevelName(unsigned int keepLevelID) const;
     32    unsigned int addKeepLevelName(const std::string& keepLevelName);
     33    unsigned int getKeepLevelID(const std::string& keepLevelName) const;
     34    const std::string& getKeepLevelName(unsigned int keepLevelID) const;
    3235
    3336  const std::vector<Resources::Type*> resourceTypes() const { return _resourceTypes; };
    34   const Directory& mainGlobalPath() const { return _mainGlobalPath; };
    35   /** @returns all global paths without mainGlobalPath */
    36   const std::vector<Directory>& globalPaths() const { return _globalPaths; };
     37    const Directory& mainGlobalPath() const { return _mainGlobalPath; };
     38    /** @returns all global paths without mainGlobalPath */
     39    const std::vector<Directory>& globalPaths() const { return _globalPaths; };
    3740
    3841
    39   bool checkFileInMainPath(const File& fileInside);
     42    bool checkFileInMainPath(const File& fileInside);
    4043
    41   bool unloadAllByPriority();
     44    bool unloadAllByKeepLevel(const Resources::KeepLevel& keepLevel);
    4245
    43   void debug() const;
     46    void debug() const;
    4447
    45   // utility functions for handling files in and around the data-directory
    46   static std::string getFullName(const std::string& fileName);
    47   static bool isInDataDir(const std::string& fileName);
    48 private:
    49   NewResourceManager();
    50   virtual ~NewResourceManager();
     48    // utility functions for handling files in and around the data-directory
     49    static std::string getFullName(const std::string& fileName);
     50    static bool isInDataDir(const std::string& fileName);
     51  private:
     52    NewResourceManager();
     53    virtual ~NewResourceManager();
    5154
    52 private:
    53   static NewResourceManager*         _singletonRef;       //!< singleton Reference
     55  private:
     56    static NewResourceManager*         _singletonRef;       //!< singleton Reference
    5457
    55   std::vector<Resources::Type*>      _resourceTypes;
    56   //! GLOBALS
    57   Directory                          _mainGlobalPath;
    58   std::vector<Directory>             _globalPaths;
     58    std::vector<Resources::Type*>      _resourceTypes;
     59    //! GLOBALS
     60    Directory                          _mainGlobalPath;
     61    std::vector<Directory>             _globalPaths;
    5962
    60   std::vector<std::string>           _keepLevelNames;
    61 };
     63    std::vector<std::string>           _keepLevelNames;
     64  };
     65
     66}
    6267
    6368#endif /* _RESOURCE_MANAGER_H */
  • branches/new_class_id/src/lib/util/loading/resource.cc

    r9799 r9800  
    2121#include "debug.h"
    2222
    23 ObjectListDefinition(NewResource);
     23
     24namespace Resources
     25{
     26  ObjectListDefinition(NewResource);
    2427
    2528
    26 /**
    27  * standard constructor
    28 */
    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  }
    3437
    35 /**
    36  * standard deconstructor
    37  */
    38 NewResource::~NewResource ()
    39 {
    40   // delete what has to be deleted here
    41 }
     38  /**
     39   * standard deconstructor
     40   */
     41  NewResource::~NewResource ()
     42  {
     43    // delete what has to be deleted here
     44  }
    4245
    4346
    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
    4763    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;
    5564  }
    5665
    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
    7373  {
    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 "";
    7984  }
    80   return "";
    81 }
    8285
    8386
    8487
    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()];
    8891
    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;
    9399  }
    94100
    95   return NULL;
    96 }
    97101
    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  }
    103106
    104107
     
    107110
    108111
    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  }
    116119
    117 const std::string& Resources::KeepLevel::name() const
    118 {
    119   return NewResourceManager::getInstance()->getKeepLevelName(this->_keepLevel);
    120 }
     120  const std::string& KeepLevel::name() const
     121  {
     122    return NewResourceManager::getInstance()->getKeepLevelName(this->_keepLevel);
     123  }
    121124
    122125
    123126
    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  {}
    130133
    131134
    132135
    133136
    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  }
    143146
    144 Resources::Type::~Type()
    145 {
    146   NewResourceManager::getInstance()->unregisterType(this);
    147 }
     147  Type::~Type()
     148  {
     149    NewResourceManager::getInstance()->unregisterType(this);
     150  }
    148151
    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);
    152155
    153 }
     156  }
    154157
    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;
    163166
    164 }
     167  }
    165168
    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  }
    175178
    176179
    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  }
    181184
    182185
    183 void Resources::Type::debug() const
    184 {
    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");
    193196
     197  }
    194198}
  • branches/new_class_id/src/lib/util/loading/resource.h

    r9799 r9800  
    3030  class StorePointer
    3131  {
    32     public:
    33       StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel);
    34       const std::string& loadString() const { return _loadString; };
    35       const Resources::KeepLevel& keepLevel() const { return _keepLevel; };
     32  public:
     33    StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel);
     34    const std::string& loadString() const { return _loadString; };
     35    const Resources::KeepLevel& keepLevel() const { return _keepLevel; };
    3636
    37     private:
    38       std::string                 _loadString;             //!< An identifier, to match when loading a File.
    39       Resources::KeepLevel        _keepLevel;              //!< The Priority of this resource. (can only be increased, so none else will delete this)
     37  private:
     38    std::string                 _loadString;             //!< An identifier, to match when loading a File.
     39    Resources::KeepLevel        _keepLevel;              //!< The Priority of this resource. (can only be increased, so none else will delete this)
    4040  };
    4141
     
    7373    std::vector<Resources::StorePointer*> _storedResources;
    7474  };
     75
     76
     77  //! A NewResource is an Object, that can be loaded from Disk
     78  /**
     79   *
     80   */
     81  class NewResource : virtual public BaseObject
     82  {
     83    ObjectListDeclaration(NewResource);
     84
     85  public:
     86    NewResource(Resources::Type* type);
     87    virtual ~NewResource();
     88
     89    virtual bool reload() { return false; };
     90    virtual bool unload() { return false; };
     91
     92    std::string locateFile(const std::string& fileName) const;
     93
     94
     95  public:
     96  protected:
     97    Resources::StorePointer* acquireResource(const std::string& loadString);
     98    void addResource(Resources::StorePointer* pointer);
     99
     100  private:
     101    std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const;
     102
     103  private:
     104    Resources::StorePointer*       _pointer;                         //!< Virtual Pointer to the ResourceData.
     105    Resources::Type*               _type;                            //!< Type of the NewResource.
     106  };
    75107}
    76108
    77 //! A NewResource is an Object, that can be loaded from Disk
    78 /**
    79  *
    80  */
    81 class NewResource : virtual public BaseObject
    82 {
    83   ObjectListDeclaration(NewResource);
    84 
    85 public:
    86   NewResource(Resources::Type* type);
    87   virtual ~NewResource();
    88 
    89   virtual bool reload() { return false; };
    90   virtual bool unload() { return false; };
    91 
    92   std::string locateFile(const std::string& fileName) const;
    93 
    94 
    95 public:
    96 protected:
    97   Resources::StorePointer* acquireResource(const std::string& loadString);
    98   void addResource(Resources::StorePointer* pointer);
    99 
    100 private:
    101   std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const;
    102 
    103 private:
    104   Resources::StorePointer*       _pointer;                         //!< Virtual Pointer to the ResourceData.
    105   Resources::Type*               _type;                            //!< Type of the NewResource.
    106 };
    107 
    108109#endif /* _RESOURCE_H */
Note: See TracChangeset for help on using the changeset viewer.