Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9845 in orxonox.OLD for branches/new_class_id/src/lib/util


Ignore:
Timestamp:
Sep 27, 2006, 11:13:17 PM (18 years ago)
Author:
bensch
Message:

some more functionality for the unloading of resources

Location:
branches/new_class_id/src/lib/util/loading
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/util/loading/resource.cc

    r9843 r9845  
    137137  //////////////
    138138  Type::Type(const std::string& typeName)
    139       : _id(-1), _typeName(typeName)
     139      : _typeName(typeName)
    140140  {
    141141    ResourceManager::getInstance()->registerType(this);
     
    151151  {
    152152    this->_storedResources.push_back(resource);
    153 
    154153  }
    155154
     
    175174  }
    176175
    177 
    178   void Type::setID(int id)
    179   {
    180     this->_id = id;
     176  void Type::unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel)
     177  {
     178    std::vector<Resources::StorePointer*>::iterator it;
     179    for (it = this->_storedResources.begin(); it != this->_storedResources.end(); ++it)
     180      if((*it)->keepLevel() < keepLevel)
     181    {
     182      delete (*it);
     183      this->_storedResources.erase(it);
     184      it = this->_storedResources.begin();
     185    }
    181186  }
    182187
     
    184189  void Type::debug() const
    185190  {
    186     PRINT(0)(" ResourceType '%s' with ID %d stores %d Resources\n", this->_typeName.c_str(), this->_id, this->_storedResources.size());
     191    PRINT(0)(" ResourceType '%s' stores %d Resources\n", this->_typeName.c_str(), this->_storedResources.size());
    187192    PRINT(0)("  Paths:\n");
    188193    for (unsigned int i = 0; i < this->_resourcePaths.size(); ++i)
  • branches/new_class_id/src/lib/util/loading/resource.h

    r9844 r9845  
    2929    KeepLevel(const std::string& keepLevelName);
    3030
     31    bool operator==(const KeepLevel& keepLevel) const { return this->_keepLevel == keepLevel._keepLevel; };
     32    bool operator!=(const KeepLevel& keepLevel) const { return this->_keepLevel != keepLevel._keepLevel; };
     33    bool operator<=(const KeepLevel& keepLevel) const { return this->_keepLevel <= keepLevel._keepLevel; };
     34    bool operator<(const KeepLevel& keepLevel) const { return this->_keepLevel < keepLevel._keepLevel; };
     35
    3136    /** @returns the KeepLevel */
    3237    unsigned int keepLevel() const { return _keepLevel; };
     
    4146  public:
    4247    StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel);
     48    //! Virtual Destructor, that removes the Stored information-pointer.
     49    virtual ~StorePointer() {};
     50
    4351    /** @returns the LoadString this resource was loaded with */
    4452    const std::string& loadString() const { return _loadString; };
     
    7381    const std::string& storedClassName() const { return _typeName; };
    7482    /** @returns the ID of the Type != ClassID */
    75     int id() const { return _id; };
    7683    /** @returns the type-specific paths this Resource searches in. */
    7784    const std::vector<Directory>& resourcePaths() const { return _resourcePaths; };
     
    8390    virtual void createFromString(const std::string& loadString) = 0;
    8491
    85     void setID(int id);
     92    void unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel);
     93
    8694    void addResource(Resources::StorePointer* resource);
    8795
     
    94102    Type(const Type& type) {};
    95103  private:
    96     int                                   _id;                //!< ID of the Type in over all of the Types.
    97104    const std::string                     _typeName;          //!< Name of the Type. (Name of the Resource this loads.)
    98105    std::vector<Directory>                _resourcePaths;     //!< The Paths to search for files in this type
  • branches/new_class_id/src/lib/util/loading/resource_manager.cc

    r9836 r9845  
    6060  void ResourceManager::registerType(Resources::Type* type)
    6161  {
    62     if(type->id() == -1)
    63     {
    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());
    67     }
     62    this->_resourceTypes.push_back(type);
     63    PRINTF(5)("ResourceType '%s' added\n", type->storedClassName().c_str());
    6864  }
    6965
     
    7470    {
    7571      this->_resourceTypes.erase(it);
    76       PRINTF(5)("ResourceType '%s' with ID %d removed\n", type->storedClassName().c_str(), type->id());
     72      PRINTF(5)("ResourceType '%s' removed\n", type->storedClassName().c_str());
    7773    }
    7874  }
     
    149145
    150146
     147  void ResourceManager::unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel)
     148  {
     149    std::vector<Resources::Type*>::const_iterator it;
     150    for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
     151    {
     152      (*it)->unloadAllBelowKeepLevel(keepLevel);
     153    }
     154  }
     155
     156
    151157  /**
    152158   * @brief outputs debug information about the ResourceManager
  • branches/new_class_id/src/lib/util/loading/resource_manager.h

    r9836 r9845  
    4646    std::string prependAbsoluteMainPath(const std::string& fileName);
    4747
    48     bool unloadAllByKeepLevel(const Resources::KeepLevel& keepLevel);
     48    void unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel);
    4949
    5050    void debug() const;
Note: See TracChangeset for help on using the changeset viewer.