ManaPlus
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 ()
 
 ~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 ( )
inline

Constructor

Definition at line 39 of file resource.h.

39  :
40  MemoryCounter(),
41  mTimeStamp(0),
42  mIdPath(),
43  mSource(),
44  mRefCount(0),
45  mProtected(false),
46 #ifdef DEBUG_DUMP_LEAKS
47  mNotCount(false),
48  mDumped(false)
49 #else // DEBUG_DUMP_LEAKS
50  mNotCount(false)
51 #endif // DEBUG_DUMP_LEAKS
52  {
53  }

◆ ~Resource()

Resource::~Resource ( )

Destructor.

Definition at line 33 of file resource.cpp.

34 {
35 }

Member Function Documentation

◆ calcMemoryLocal()

int Resource::calcMemoryLocal ( ) const
virtual

◆ decRef()

void Resource::decRef ( )
virtual

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

Returns
true if the object was deleted false otherwise.

Reimplemented in Image, SubImage, and AtlasResource.

Definition at line 49 of file resource.cpp.

50 {
51 #ifdef DEBUG_IMAGES
52  logger->log("before decRef for: %p", static_cast<void*>(this));
53 #endif // DEBUG_IMAGES
54 
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  }
61 
62  mRefCount--;
63 
64 #ifdef DEBUG_IMAGES
65  logger->log("after decRef: %p, %u", static_cast<void*>(this), mRefCount);
66 #endif // DEBUG_IMAGES
67 
68  if (mRefCount == 0 && !mNotCount)
69  {
70  // Warn the manager that this resource is no longer used.
72  }
73 }

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(), SoundManager::playGuiSfx(), SoundManager::playSfx(), ProgressIndicator::ProgressIndicator(), Theme::readSkin(), Button::setImage(), Gui::setUseCustomCursor(), MapReader::unloadEmptyAtlas(), AnimatedSprite::~AnimatedSprite(), BrowserBox::~BrowserBox(), Button::~Button(), EmotePage::~EmotePage(), EmoteWindow::~EmoteWindow(), EquipmentWindow::~EquipmentWindow(), Gui::~Gui(), Map::~Map(), ShaderProgram::~ShaderProgram(), SimpleAnimation::~SimpleAnimation(), StaticBrowserBox::~StaticBrowserBox(), and WindowMenu::~WindowMenu().

◆ getCounterName()

std::string Resource::getCounterName ( ) const
inlinevirtual

Reimplemented from MemoryCounter.

Reimplemented in SDLMusic, and SoundEffect.

Definition at line 78 of file resource.h.

79  { return mIdPath + "-" + mSource; }

References mIdPath, and mSource.

◆ incRef()

void Resource::incRef ( )
virtual

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:
Resource
Definition: resource.h:33
Resource::mNotCount
bool mNotCount
Definition: resource.h:88
Resource::mProtected
bool mProtected
Definition: resource.h:87
logger
Logger * logger
Definition: logger.cpp:88
Resource::mTimeStamp
time_t mTimeStamp
Definition: resource.h:81
MemoryCounter::MemoryCounter
MemoryCounter()
Definition: memorycounter.cpp:27
Resource::mSource
std::string mSource
Definition: resource.h:84
ResourceManager::release
void release(Resource *const res)
Definition: resourcemanager.cpp:475
CAST_S32
#define CAST_S32
Definition: cast.h:29
Resource::mRefCount
unsigned int mRefCount
Definition: resource.h:86
Logger::log
void log(const char *const log_text,...)
Definition: logger.cpp:268
Resource::mIdPath
std::string mIdPath
Definition: resource.h:83