MObjectManager.h
Go to the documentation of this file.
00001 #ifndef MObjectManager_H
00002 #define MObjectManager_H
00003 
00004 #include <list>
00005 using namespace std;
00006 
00007 #include "MObjectUser.h"
00008 
00009 
00010 using namespace momdp;
00011 namespace momdp 
00012 {
00013 
00014 class MObject;
00015 
00016 template <typename T>
00017 class MObjectManager
00018 {
00019 private:
00020         list<MObjectUser<T> *> userList;
00021 
00022 public:
00023 
00024         MObjectManager(void)
00025         {
00026         }
00027         virtual ~MObjectManager(void)
00028         {
00029         }
00030 
00031         // delete the MObject from everywhere
00032         virtual void strongDelete(T *pointer)
00033         {
00034                 for(typename list<MObjectUser<T> *>::iterator iter = userList.begin(); iter != userList.end(); iter ++)
00035                 {
00036                         (*iter)->forcedDelete(pointer);
00037                 }
00038                 localDelete(pointer);
00039         }
00040 
00041 
00042         // one user deleted the MObject, but the MObject may still be used by other users. Only decrease refCount
00043         virtual void weakDelete(T *pointer)
00044         {
00045                 // TODO: obsolete this by using smart pointers
00046                 //pointer->refCount -- ;
00047                 //if(pointer->refCount == 1)
00048                 //{
00049                 //      // only the manager is using it, may do something here...
00050                 //}
00051                 //else if(pointer->refCount == 0)
00052                 //{
00053                 //      // no one is using it, delete
00054                 //      localDelete(pointer);
00055                 //}
00056 
00057 
00058         }
00059         // this function perform the actual delete, must be instantiated
00060         virtual void localDelete(T *pointer) = 0; 
00061 
00062 
00063         virtual void registerUser(MObjectUser<T> *pointer)
00064         {
00065                 userList.push_back(pointer);
00066         }
00067         virtual void removeUser(MObjectUser<T> *pointer)
00068         {
00069                 userList.remove(pointer);
00070         }
00071 
00072         
00073 };
00074 }
00075 
00076 #endif
00077 


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29