00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef VRS_CONTAINER_RESOURCEMANAGER_H
00044 #define VRS_CONTAINER_RESOURCEMANAGER_H
00045
00046 #include <vrs/sharedobj.h>
00047 #include <list>
00048
00049 namespace VRS {
00050
00051 template<
00052 class RESOURCE_TYPE = VRS::SharedObj,
00053 typename RESOURCE_SIZE_TYPE = unsigned int
00054 >
00055 class ResourceManager :
00056 public VRS::SharedObj
00057 {
00058 public:
00059 VRS_TYPEINFO(ResourceManager, VRS::SharedObj);
00060
00061 ResourceManager(
00062 const RESOURCE_SIZE_TYPE maxSize
00063 );
00064
00065 void add(
00066 const SO<const RESOURCE_TYPE> resourceObject,
00067 const RESOURCE_SIZE_TYPE resourceSize
00068 );
00069
00070 bool use(
00071 const SO<const RESOURCE_TYPE> resourceObject
00072 );
00073
00074 bool remove(
00075 const SO<const RESOURCE_TYPE> resourceObject
00076 );
00077
00078 bool contains(
00079 const SO<const RESOURCE_TYPE> resourceObject
00080 ) const;
00081
00082 void lock();
00083 void unlock();
00084
00085 bool clear();
00086
00087 void maxSize(
00088 const RESOURCE_SIZE_TYPE newMaxSize
00089 );
00090
00091 RESOURCE_SIZE_TYPE maxSize() const;
00092
00093 RESOURCE_SIZE_TYPE usedSize() const;
00094
00095 private:
00096 void update();
00097
00098 typedef std::list<std::pair<SO<const RESOURCE_TYPE>, RESOURCE_SIZE_TYPE> > ResourceUsageList;
00099 ResourceUsageList m_objects;
00100
00101 RESOURCE_SIZE_TYPE m_maxSize;
00102 RESOURCE_SIZE_TYPE m_usedSize;
00103
00104 unsigned int m_lockCount;
00105 SO<const RESOURCE_TYPE> m_locked;
00106 typedef std::vector<SO<const RESOURCE_TYPE> > ResourceRemoveAfterUnlockList;
00107 ResourceRemoveAfterUnlockList m_removeAfterUnlock;
00108 };
00109
00110 }
00111
00112 #include <vrs/container/resourcemanager.tli>
00113
00114 #endif // VRS_CONTAINER_RESOURCEMANAGER_H