ManaPlus
Public Member Functions | Data Fields
AtlasResource Class Reference

#include <atlasresource.h>

Inheritance diagram for AtlasResource:
Resource MemoryCounter

Public Member Functions

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

Data Fields

std::vector< TextureAtlas * > atlases
 
- Data Fields inherited from Resource
time_t mTimeStamp
 
std::string mIdPath
 
std::string mSource
 
unsigned int mRefCount
 
bool mProtected
 
bool mNotCount
 

Detailed Description

Definition at line 33 of file atlasresource.h.

Constructor & Destructor Documentation

◆ AtlasResource()

AtlasResource::AtlasResource ( )
inline

Definition at line 36 of file atlasresource.h.

36  :
37  atlases()
38  { }
std::vector< TextureAtlas * > atlases
Definition: atlasresource.h:52

Referenced by calcMemoryLocal().

◆ ~AtlasResource()

AtlasResource::~AtlasResource ( )

Definition at line 33 of file atlasresource.cpp.

34 {
35  FOR_EACH (STD_VECTOR<TextureAtlas*>::iterator, it, atlases)
36  {
37  TextureAtlas *const atlas = *it;
38  if (atlas != nullptr)
39  {
40  FOR_EACH (STD_VECTOR<AtlasItem*>::iterator, it2, atlas->items)
41  {
42  AtlasItem *const item = *it2;
43  if (item != nullptr)
44  {
45  Image *const image2 = item->image;
46  if (image2 != nullptr)
47  image2->decRef();
48  delete item;
49  }
50  }
51  Image *const image = atlas->atlasImage;
52  if (image != nullptr)
53  image->decRef();
54  delete atlas;
55  }
56  }
58 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
void clearDeleted(const bool full)
Image * image
Definition: atlasitem.h:54
Image * atlasImage
Definition: textureatlas.h:75
std::vector< AtlasItem * > items
Definition: textureatlas.h:78

References atlases, TextureAtlas::atlasImage, ResourceManager::clearDeleted(), FOR_EACH, AtlasItem::image, and TextureAtlas::items.

Member Function Documentation

◆ calcMemoryChilds()

int AtlasResource::calcMemoryChilds ( const int  level) const
virtual

Reimplemented from MemoryCounter.

Definition at line 81 of file atlasresource.cpp.

82 {
83  int sz = 0;
84  FOR_EACH (STD_VECTOR<TextureAtlas*>::const_iterator, it, atlases)
85  {
86  TextureAtlas *const atlas = *it;
87  sz += atlas->calcMemory(level + 1);
88  }
89  return sz;
90 }
int calcMemory(const int level) const

References atlases, MemoryCounter::calcMemory(), and FOR_EACH.

◆ calcMemoryLocal()

int AtlasResource::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 74 of file atlasresource.cpp.

75 {
76  return static_cast<int>(sizeof(AtlasResource)) +
78  static_cast<int>(atlases.capacity() * sizeof(TextureAtlas*));
79 }
int calcMemoryLocal() const
Definition: resource.cpp:76

References atlases, AtlasResource(), and Resource::calcMemoryLocal().

◆ decRef()

void AtlasResource::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 from Resource.

Definition at line 67 of file atlasresource.cpp.

68 {
70  if (mRefCount == 0U)
72 }
static void moveToDeleted(AtlasResource *const resource)
virtual void decRef()
Definition: resource.cpp:50
unsigned int mRefCount
Definition: resource.h:87

References Resource::decRef(), AtlasManager::moveToDeleted(), and Resource::mRefCount.

Referenced by Map::~Map().

◆ incRef()

void AtlasResource::incRef ( )
virtual

Increments the internal reference count.

Reimplemented from Resource.

Definition at line 60 of file atlasresource.cpp.

61 {
62  if (mRefCount == 0U)
65 }
static void injectToResources(const AtlasResource *const resource)
virtual void incRef()
Definition: resource.cpp:38

References Resource::incRef(), AtlasManager::injectToResources(), and Resource::mRefCount.

Field Documentation

◆ atlases

std::vector<TextureAtlas*> AtlasResource::atlases

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