Watch the modifications of file objects for you. More...
#include <util/watchdog.h>
Signals | |
void | registerFile (std::string) |
void | unregisterFile (std::string) |
Public Member Functions | |
void | addObject (FileObject &obj) |
Watch a new object. | |
void | addObject (FileObject *obj) |
Watch a new object. | |
void | changeFilename (FileObject *obj, std::string fn) |
Change the filename of an object. | |
bool | guarded (FileObject &obj) const |
bool | guarded (FileObject *obj) const |
Test if an object is being watched. | |
void | removeObject (FileObject &obj) |
Do not watch this object anymore. | |
void | removeObject (FileObject *obj) |
Do not watch this object anymore. | |
bool | watch (const std::set< std::string > &filenames) |
Check if any of the file names correspond to one of the watched object. | |
WatchDog (QObject *m) | |
Constructor. | |
Protected Attributes | |
std::set< FileObject * > | fileObjects |
List of file objects to handle. | |
QObject * | model |
Model to guard. | |
std::map< std::string, std::set< FileObject * > > | names |
Map the file names to the file objects. |
Watch the modifications of file objects for you.
Definition at line 134 of file watchdog.h.
util::WatchDog::WatchDog | ( | QObject * | m | ) |
Constructor.
m | Pointer toward the model to watch files for |
Definition at line 25 of file watchdog.cpp.
References QObject::connect().
void util::WatchDog::addObject | ( | FileObject & | obj | ) | [inline] |
Watch a new object.
Definition at line 159 of file watchdog.h.
References addObject().
Referenced by addObject().
00159 { addObject(&obj); }
void util::WatchDog::addObject | ( | FileObject * | obj | ) |
Watch a new object.
Definition at line 33 of file watchdog.cpp.
References fileObjects, util::FileObject::getFilename(), and names.
Referenced by tissue_model::TissueModel< RealModel, TissueClass >::TissueModel(), and bspline_tissue_model::TissueModel< RealModel, TissueClass >::TissueModel().
00034 { 00035 fileObjects.insert(obj); 00036 names[obj->getFilename()].insert(obj); 00037 if(!obj->getFilename().empty()) 00038 emit registerFile(obj->getFilename()); 00039 }
void util::WatchDog::changeFilename | ( | FileObject * | obj, | |
std::string | fn | |||
) |
Change the filename of an object.
Definition at line 46 of file watchdog.cpp.
References util::FileObject::getFilename(), names, and util::FileObject::setFilename().
Referenced by bspline_tissue_model::TissueModel< RealModel, TissueClass >::readTissueParam().
00047 { 00048 // First, unregister the file 00049 std::string oldName = obj->getFilename(); 00050 if(oldName == fn) 00051 return; 00052 std::set<FileObject*>& ns = names[oldName]; 00053 if(!oldName.empty()) 00054 emit unregisterFile(oldName); 00055 ns.erase(obj); 00056 if(ns.empty()) 00057 names.erase(oldName); 00058 // Then add the new file 00059 names[fn].insert(obj); 00060 if(!fn.empty()) 00061 emit registerFile(fn); 00062 obj->setFilename(fn); 00063 }
bool util::WatchDog::guarded | ( | FileObject * | obj | ) | const |
Test if an object is being watched.
Definition at line 41 of file watchdog.cpp.
References fileObjects.
00042 { 00043 return (fileObjects.find(obj) != fileObjects.end()); 00044 }
void util::WatchDog::removeObject | ( | FileObject & | obj | ) | [inline] |
Do not watch this object anymore.
Definition at line 174 of file watchdog.h.
References removeObject().
Referenced by removeObject().
00174 { removeObject(&obj); }
void util::WatchDog::removeObject | ( | FileObject * | obj | ) |
Do not watch this object anymore.
Definition at line 65 of file watchdog.cpp.
References fileObjects, util::FileObject::getFilename(), and names.
00066 { 00067 std::string name = obj->getFilename(); 00068 std::set<FileObject*>& ns = names[name]; 00069 if(!name.empty()) 00070 emit unregisterFile(name); 00071 ns.erase(obj); 00072 if(ns.empty()) 00073 names.erase(name); 00074 fileObjects.erase(obj); 00075 }
bool util::WatchDog::watch | ( | const std::set< std::string > & | filenames | ) |
Check if any of the file names correspond to one of the watched object.
filenames | Set of file names that were recently modified |
If the WatchDog finds a file name it handles in the set, it emits a FileObject::modified() signal for this object.
Definition at line 78 of file watchdog.cpp.
Referenced by tissue_model::TissueModel< RealModel, TissueClass >::modifiedFiles(), and bspline_tissue_model::TissueModel< RealModel, TissueClass >::modifiedFiles().
00079 { 00080 bool result = false; 00081 forall(const std::string& str, filenames) 00082 { 00083 std::map<std::string, std::set<FileObject*> >::iterator found = names.find(str); 00084 if(found != names.end()) 00085 { 00086 result = true; 00087 forall(FileObject* obj, found->second) 00088 { 00089 obj->update(); 00090 } 00091 } 00092 } 00093 return result; 00094 }
std::set<FileObject*> util::WatchDog::fileObjects [protected] |
List of file objects to handle.
Definition at line 198 of file watchdog.h.
Referenced by addObject(), guarded(), and removeObject().
QObject* util::WatchDog::model [protected] |
Model to guard.
Definition at line 194 of file watchdog.h.
std::map<std::string, std::set<FileObject*> > util::WatchDog::names [protected] |
Map the file names to the file objects.
Definition at line 202 of file watchdog.h.
Referenced by addObject(), changeFilename(), removeObject(), and watch().