

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. | |
| T | 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. | |
| T | 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 |
|
|||||
|
Definition at line 23 of file ResourcePack.h. |
|
|||||
|
Definition at line 19 of file ResourcePack.h. |
|
|||||
|
Definition at line 21 of file ResourcePack.h. |
|
|||||
|
Definition at line 22 of file ResourcePack.h. |
|
|||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||
|
Count resources with this name.
Definition at line 134 of file ResourcePack.h. 00135 {
00136 return m_reses.count(name);
00137 }
|
|
||||||||||
|
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 }
|
|
||||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
|||||||||
|
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 }
|
|
||||||||||
|
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 }
|
|
|||||||||
|
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 }
|
|
||||||||||
|
Implemented in ResColorPack, ResDialogPack, ResImagePack, and ResSoundPack. |
|
|||||
|
Definition at line 24 of file ResourcePack.h. |
1.4.2