pool.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_POOL_H
00023 #define FIFE_POOL_H
00024
00025
00026 #include <map>
00027 #include <vector>
00028 #include <string>
00029 #include <iostream>
00030 #include <cassert>
00031
00032
00033
00034
00035
00036
00037
00038 #include "resource.h"
00039 #include "resource_location.h"
00040
00041 namespace FIFE {
00042
00043 struct ResourceLocationComparator {
00044 bool operator()(const ResourceLocation* r1, const ResourceLocation* r2) const
00045 {
00046 return r1->operator<(*r2);
00047 }
00048 };
00049
00050 class IResource;
00051
00052 enum { RES_LOADED = 0x01, RES_NON_LOADED = 0x02};
00053
00061 class Pool {
00062 public:
00065 static const int INVALID_ID = -1;
00066
00070 Pool(const std::string& name);
00071
00074 virtual ~Pool();
00075
00078 virtual void addResourceLoader(ResourceLoader* loader);
00079
00082 virtual void clearResourceLoaders();
00083
00087 virtual int addResourceFromLocation(ResourceLocation* loc);
00088
00096 virtual int addResourceFromFile(const std::string& filename);
00097
00102 virtual IResource& get(unsigned int index, bool inc = false);
00103
00109 virtual void release(unsigned int index, bool dec = false);
00110
00116 virtual int purgeLoadedResources();
00117
00120 virtual int getResourceCount(int status);
00121
00124 virtual void printStatistics();
00125
00128 void sanityCheck();
00129
00135 virtual void reset();
00136
00137 protected:
00138 class PoolEntry {
00139 public:
00140 PoolEntry(): resource(0), location(0), loader(0) {}
00141 ~PoolEntry() {
00142 delete location;
00143 delete resource;
00144 }
00145
00146
00147 IResource* resource;
00148
00149 ResourceLocation* location;
00150
00151 ResourceLoader* loader;
00152 };
00153
00154 void findAndSetProvider(PoolEntry& entry);
00155
00156 std::vector<PoolEntry*> m_entries;
00157 typedef std::map<ResourceLocation*, int, ResourceLocationComparator> ResourceLocationToEntry;
00158 ResourceLocationToEntry m_location_to_entry;
00159 std::vector<ResourceLoader*> m_loaders;
00160 std::string m_name;
00161 };
00162
00163 }
00164
00165 #endif