Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

PG_SurfaceCache Class Reference

A class for caching SDL_Surface images. More...

#include <pgsurfacecache.h>

List of all members.

Public Member Functions

 PG_SurfaceCache ()
virtual ~PG_SurfaceCache ()
void CreateKey (std::string &key, Uint16 w, Uint16 h, PG_Gradient *gradient, SDL_Surface *background, PG_Draw::BkMode bkmode, Uint8 blend)
 Create a fairly unique key for a given surface.
SDL_Surface * FindSurface (const std::string &key)
 Find the surface to a given key .
SDL_Surface * AddSurface (const std::string &key, SDL_Surface *surface)
 Add a surface to the list.
void DeleteSurface (SDL_Surface *surface, bool bDeleteIfNotExists=true)
 Deletes a surface from the list.
void IncRef (const std::string &key)
 Increase the reference counter of a surface.
void Cleanup ()
 Removes all surfaces from the cache.


Detailed Description

A class for caching SDL_Surface images.

To reduce memory consumption, paragui classes use this class to cache their surfaces. The class stores an internal counter for each surface that is decreased every time the surface is deleted. It is proposed to use this interface if you add a new class to ParaGui.

Definition at line 57 of file pgsurfacecache.h.


Constructor & Destructor Documentation

PG_SurfaceCache::PG_SurfaceCache  ) 
 

Definition at line 77 of file pgsurfacecache.cpp.

PG_SurfaceCache::~PG_SurfaceCache  )  [virtual]
 

Definition at line 82 of file pgsurfacecache.cpp.

References Cleanup(), MY_SURFACEINDEX, and MY_SURFACEMAP.


Member Function Documentation

SDL_Surface * PG_SurfaceCache::AddSurface const std::string &  key,
SDL_Surface *  surface
 

Add a surface to the list.

Parameters:
key the key associated with the surface
surface the surface you want to add to the cache
Returns:
the surface from the cache
Warning:
If you add a surface whose key already exists and which is different from the surface in the cache, your surface will be quietly deleted. So NEVER touch a surface again after you have added it to the cache. ALWAYS use the returned pointer instead.
This behaviour has a slight drawback if you add a surface the second time, because then the surface is not deleted...

Definition at line 200 of file pgsurfacecache.cpp.

References pg_surface_cache_t::key, PG_LogDBG(), pg_surface_cache_t::refcount, and pg_surface_cache_t::surface.

Referenced by PG_ThemeWidget::CreateThemedSurface(), and PG_FileArchive::LoadSurface().

void PG_SurfaceCache::Cleanup  ) 
 

Removes all surfaces from the cache.

Definition at line 92 of file pgsurfacecache.cpp.

References MY_SURFACEINDEX, MY_SURFACEMAP, and pg_surface_cache_t::surface.

Referenced by ~PG_SurfaceCache().

void PG_SurfaceCache::CreateKey std::string &  key,
Uint16  w,
Uint16  h,
PG_Gradient gradient,
SDL_Surface *  background,
PG_Draw::BkMode  bkmode,
Uint8  blend
 

Create a fairly unique key for a given surface.

Parameters:
key the key will be returned here
w width of the surface
h height of the surface
gradient is added to the key if non-zero
background the surface for the key
bkmode see explanation
blend see explanation
This function has the task of creating a unique key to a given surface. This is done by simply writing all parameters one after the other, but the implementation may change in future versions. Therefore, the parameters are not really neccessary. However, to ensure that the created keys are unique, you should use the parameters.

Definition at line 113 of file pgsurfacecache.cpp.

References assert, and PG_Gradient::colors.

Referenced by PG_ThemeWidget::CreateThemedSurface().

void PG_SurfaceCache::DeleteSurface SDL_Surface *  surface,
bool  bDeleteIfNotExists = true
 

Deletes a surface from the list.

Parameters:
surface the surface to be deleted
bDeleteIfNotExists if set to true, the surface is deleted when the reference counter reaches 0
This function reduces the reference counter of the surface. If the counter reaches 0 and the bool parameter is set, the surface is freed.

Definition at line 236 of file pgsurfacecache.cpp.

References pg_surface_cache_t::key, MY_SURFACEINDEX, MY_SURFACEMAP, pg_surface_cache_t::refcount, and pg_surface_cache_t::surface.

Referenced by PG_ThemeWidget::DeleteThemedSurface(), and PG_FileArchive::UnloadSurface().

SDL_Surface * PG_SurfaceCache::FindSurface const std::string &  key  ) 
 

Find the surface to a given key .

Parameters:
key the key whose surface is searched
Returns:
the surface or NULL if no surfac was found

Definition at line 185 of file pgsurfacecache.cpp.

References MY_SURFACEMAP.

Referenced by PG_ThemeWidget::CreateThemedSurface(), and PG_FileArchive::LoadSurface().

void PG_SurfaceCache::IncRef const std::string &  key  ) 
 

Increase the reference counter of a surface.

Parameters:
key the key of the surface

Definition at line 267 of file pgsurfacecache.cpp.

References pg_surface_cache_t::refcount.

Referenced by PG_ThemeWidget::CreateThemedSurface(), and PG_FileArchive::LoadSurface().


The documentation for this class was generated from the following files:
Generated on Tue Jun 24 02:19:36 2008 for Advanced Strategic Command by  doxygen 1.4.2