Public Member Functions | Data Fields
Resource Class Reference

#include <resource.h>

Inheritance diagram for Resource:
MemoryCounter AtlasResource Image ImageSet SDLMusic Shader ShaderProgram SoundEffect SpriteDef WalkLayer XML::Document

Public Member Functions

 Resource ()
virtual ~Resource ()
virtual void incRef ()
virtual void decRef ()
int calcMemoryLocal () const
std::string getCounterName () const
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
virtual ~MemoryCounter ()
int calcMemory (const int level) const
virtual int calcMemoryChilds (const int level) const

Data Fields

time_t mTimeStamp
std::string mIdPath
std::string mSource
unsigned int mRefCount
bool mProtected
bool mNotCount

Detailed Description

A generic reference counted resource object.

Definition at line 33 of file resource.h.

Constructor & Destructor Documentation

◆ Resource()

Resource::Resource ( )


Definition at line 39 of file resource.h.

References A_DELETE_COPY, calcMemoryLocal(), decRef(), incRef(), and ~Resource().

39  :
40  MemoryCounter(),
41  mTimeStamp(0),
42  mIdPath(),
43  mSource(),
44  mRefCount(0),
45  mProtected(false),
47  mNotCount(false),
48  mDumped(false)
49 #else // DEBUG_DUMP_LEAKS
50  mNotCount(false)
51 #endif // DEBUG_DUMP_LEAKS
52  {
53  }
std::string mSource
Definition: resource.h:84
bool mNotCount
Definition: resource.h:88
unsigned int mRefCount
Definition: resource.h:86
time_t mTimeStamp
Definition: resource.h:81
bool mProtected
Definition: resource.h:87
std::string mIdPath
Definition: resource.h:83

◆ ~Resource()

Resource::~Resource ( )


Definition at line 33 of file resource.cpp.

Referenced by Resource().

34 {
35 }

Member Function Documentation

◆ calcMemoryLocal()

int Resource::calcMemoryLocal ( ) const

Reimplemented from MemoryCounter.

Reimplemented in SDLMusic, SoundEffect, and SpriteDef.

Definition at line 75 of file resource.cpp.

References CAST_S32, mIdPath, and mSource.

Referenced by WalkLayer::calcMemoryLocal(), AtlasResource::calcMemoryLocal(), SpriteDef::calcMemoryLocal(), SoundEffect::calcMemoryLocal(), SDLMusic::calcMemoryLocal(), SubImage::calcMemoryLocal(), ImageSet::calcMemoryLocal(), Image::calcMemoryLocal(), and Resource().

76 {
77  return CAST_S32(sizeof(Resource)) +
78  CAST_S32(mIdPath.size()) +
79  CAST_S32(mSource.size());
80 }
std::string mSource
Definition: resource.h:84
#define CAST_S32
Definition: cast.h:29
std::string mIdPath
Definition: resource.h:83

◆ decRef()

void Resource::decRef ( )

Decrements the reference count and deletes the object if no references are left.

true if the object was deleted false otherwise.

Reimplemented in Image, SubImage, and AtlasResource.

Definition at line 49 of file resource.cpp.

References Logger::log(), logger, mIdPath, mNotCount, mRefCount, and ResourceManager::release().

Referenced by Particle::addEffect(), ParticleEngine::addEffect(), ResourceManager::cleanProtected(), ShadersManager::createProgram(), AtlasResource::decRef(), SubImage::decRef(), Image::decRef(), ResourceManager::decRefDelete(), EquipmentWindow::fillBoxes(), EquipmentWindow::fillDefault(), SoundManager::haltMusic(), SpriteDef::includeSprite(), SpriteDef::load(), Theme::loadColors(), Button::loadImage(), Button::loadImageSet(), Theme::loadInfo(), SoundManager::logic(), ResourceManager::moveToDeleted(), ProgressIndicator::ProgressIndicator(), Theme::readSkin(), Resource(), Gui::setUseCustomCursor(), MapReader::unloadEmptyAtlas(), AnimatedSprite::~AnimatedSprite(), BrowserBox::~BrowserBox(), Button::~Button(), EmotePage::~EmotePage(), EmoteWindow::~EmoteWindow(), EquipmentWindow::~EquipmentWindow(), Gui::~Gui(), Map::~Map(), ShaderProgram::~ShaderProgram(), SimpleAnimation::~SimpleAnimation(), and StaticBrowserBox::~StaticBrowserBox().

50 {
51 #ifdef DEBUG_IMAGES
52  logger->log("before decRef for: %p", static_cast<void*>(this));
53 #endif // DEBUG_IMAGES
55  // Reference may not already have reached zero
56  if (mRefCount == 0)
57  {
58  logger->log("Warning: mRefCount already zero for %s", mIdPath.c_str());
59  return;
60  }
62  mRefCount--;
64 #ifdef DEBUG_IMAGES
65  logger->log("after decRef: %p, %u", static_cast<void*>(this), mRefCount);
66 #endif // DEBUG_IMAGES
68  if (mRefCount == 0 && !mNotCount)
69  {
70  // Warn the manager that this resource is no longer used.
72  }
73 }
bool mNotCount
Definition: resource.h:88
unsigned int mRefCount
Definition: resource.h:86
Logger * logger
Definition: logger.cpp:95
void release(Resource *const res)
void log(const char *const log_text,...)
Definition: logger.cpp:243
std::string mIdPath
Definition: resource.h:83

◆ getCounterName()

std::string Resource::getCounterName ( ) const

Reimplemented from MemoryCounter.

Reimplemented in SDLMusic, and SoundEffect.

Definition at line 78 of file resource.h.

References mIdPath, and mSource.

79  { return mIdPath + "-" + mSource; }
std::string mSource
Definition: resource.h:84
std::string mIdPath
Definition: resource.h:83

◆ incRef()

void Resource::incRef ( )

Field Documentation

◆ mIdPath

std::string Resource::mIdPath

◆ mNotCount

bool Resource::mNotCount

Definition at line 88 of file resource.h.

Referenced by decRef(), and ImageSet::ImageSet().

◆ mProtected

bool Resource::mProtected

Definition at line 87 of file resource.h.

Referenced by ResourceManager::cleanProtected(), and SpriteDef::load().

◆ mRefCount

unsigned int Resource::mRefCount

◆ mSource

std::string Resource::mSource

◆ mTimeStamp

time_t Resource::mTimeStamp

Time at which the resource was orphaned.

Definition at line 81 of file resource.h.

Referenced by ResourceManager::cleanOrphans(), and ResourceManager::release().

The documentation for this class was generated from the following files: