Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

ResourcePack< T > Class Template Reference

Inheritance diagram for ResourcePack< T >:

Inheritance graph
[legend]
Collaboration diagram for ResourcePack< T >:

Collaboration graph
[legend]

Detailed Description

template<class T>
class ResourcePack< T >

Share resources.

Definition at line 17 of file ResourcePack.h.

Public Types

typedef std::vector< T > t_range

Public Member Functions

virtual ~ResourcePack ()
void removeAll ()
 Free all resources.
void removeRes (const std::string &name)
 Unload all resources with this name.
void addRes (const std::string &name, T res)
 Store resource under this name.
getRes (const std::string &name, int rank=0)
 Get resource with this name.
t_range getRange (const std::string &name)
 Get all resources with this name.
getRandomRes (const std::string &name)
 Get resource at random index or return NULL.
int countRes (const std::string &name)
 Count resources with this name.
std::string toString () const

Protected Types

typedef std::multimap< std::string,
T > 
t_reses
typedef t_reses::iterator t_resIterator
typedef t_reses::const_iterator t_constIterator

Protected Member Functions

virtual void unloadRes (T res)=0

Protected Attributes

t_reses m_reses


Member Typedef Documentation

template<class T>
typedef t_reses::const_iterator ResourcePack< T >::t_constIterator [protected]
 

Definition at line 23 of file ResourcePack.h.

template<class T>
typedef std::vector<T> ResourcePack< T >::t_range
 

Definition at line 19 of file ResourcePack.h.

template<class T>
typedef std::multimap<std::string,T> ResourcePack< T >::t_reses [protected]
 

Definition at line 21 of file ResourcePack.h.

template<class T>
typedef t_reses::iterator ResourcePack< T >::t_resIterator [protected]
 

Definition at line 22 of file ResourcePack.h.


Constructor & Destructor Documentation

template<class T>
virtual ResourcePack< T >::~ResourcePack  )  [inline, virtual]
 

Definition at line 30 of file ResourcePack.h.

00031     {
00032         if (!m_reses.empty()) {
00033             LOG_WARNING(ExInfo("resources are not released")
00034                 .addInfo("pack", toString()));
00035         }
00036     }


Member Function Documentation

template<class T>
void ResourcePack< T >::addRes const std::string &  name,
res
[inline]
 

Store resource under this name.

Definition at line 71 of file ResourcePack.h.

00072     {
00073         m_reses.insert(
00074                 std::pair<std::string,T>(name, res));
00075     }

template<class T>
int ResourcePack< T >::countRes const std::string &  name  )  [inline]
 

Count resources with this name.

Definition at line 134 of file ResourcePack.h.

00135     {
00136         return m_reses.count(name);
00137     }

template<class T>
T ResourcePack< T >::getRandomRes const std::string &  name  )  [inline]
 

Get resource at random index or return NULL.

Definition at line 116 of file ResourcePack.h.

00117     {
00118         T result = NULL;
00119         typename t_reses::size_type count = m_reses.count(name);
00120         if (count > 0) {
00121             result = getRes(name, Random::randomInt(count));
00122         }
00123         else {
00124             LOG_WARNING(ExInfo("no such resource")
00125                     .addInfo("name", name)
00126                     .addInfo("pack", toString()));
00127         }
00128         return result;
00129     }

template<class T>
t_range ResourcePack< T >::getRange const std::string &  name  )  [inline]
 

Get all resources with this name.

NOTE: range can be empty.

Definition at line 100 of file ResourcePack.h.

00101     {
00102         t_range result;
00103         std::pair<t_resIterator, t_resIterator> range =
00104             m_reses.equal_range(name);
00105         while (range.first != range.second) {
00106             result.push_back(range.first->second);
00107             range.first++;
00108         }
00109 
00110         return result;
00111     }

template<class T>
T ResourcePack< T >::getRes const std::string &  name,
int  rank = 0
[inline]
 

Get resource with this name.

Definition at line 80 of file ResourcePack.h.

00081     {
00082         std::pair<t_resIterator, t_resIterator> range =
00083             m_reses.equal_range(name);
00084         for (int i = 0; i < rank && range.first != range.second; ++i) {
00085             ++(range.first);
00086         }
00087         if (range.second == range.first) {
00088             throw ResourceException(ExInfo("no such resource at index")
00089                     .addInfo("name", name)
00090                     .addInfo("index", rank)
00091                     .addInfo("pack", toString()));
00092         }
00093         return range.first->second;
00094     }

template<class T>
void ResourcePack< T >::removeAll  )  [inline]
 

Free all resources.

NOTE: we cannot call virtual functions from desctructor

Definition at line 42 of file ResourcePack.h.

00043         {
00044             t_resIterator end = m_reses.end();
00045             for (t_resIterator item = m_reses.begin(); item != end; ++item) {
00046                 unloadRes(item->second);
00047             }
00048             m_reses.clear();
00049         }

template<class T>
void ResourcePack< T >::removeRes const std::string &  name  )  [inline]
 

Unload all resources with this name.

Definition at line 54 of file ResourcePack.h.

00055         {
00056             std::pair<t_resIterator, t_resIterator> range =
00057                 m_reses.equal_range(name);
00058             while (range.first != range.second) {
00059                 unloadRes(range.first->second);
00060                 ++(range.first);
00061             }
00062             m_reses.erase(name);
00063             LOG_DEBUG(ExInfo("removed resources")
00064                     .addInfo("name", name));
00065         }

template<class T>
std::string ResourcePack< T >::toString  )  const [inline]
 

Definition at line 139 of file ResourcePack.h.

00140     {
00141             ExInfo available_res = ExInfo("resources")
00142                 .addInfo("name", getName());
00143 
00144             t_constIterator end = m_reses.end();
00145             for (t_constIterator item = m_reses.begin(); item != end; ++item) {
00146                 available_res.addInfo("key", item->first);
00147             }
00148             return available_res.info();
00149     }

template<class T>
virtual void ResourcePack< T >::unloadRes res  )  [protected, pure virtual]
 

Implemented in ResColorPack, ResDialogPack, ResImagePack, and ResSoundPack.


Field Documentation

template<class T>
t_reses ResourcePack< T >::m_reses [protected]
 

Definition at line 24 of file ResourcePack.h.


The documentation for this class was generated from the following file:
Generated on Wed Jun 1 09:56:28 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2