util::WatchDog Class Reference

Watch the modifications of file objects for you. More...

#include <util/watchdog.h>

Inheritance diagram for util::WatchDog:
Inheritance graph
[legend]

List of all members.

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.
QObjectmodel
 Model to guard.
std::map< std::string,
std::set< FileObject * > > 
names
 Map the file names to the file objects.

Detailed Description

Watch the modifications of file objects for you.

Definition at line 134 of file watchdog.h.


Constructor & Destructor Documentation

util::WatchDog::WatchDog ( QObject m  ) 

Constructor.

Parameters:
m Pointer toward the model to watch files for

Definition at line 25 of file watchdog.cpp.

References QObject::connect().

00026     : QObject()
00027     , model(m)
00028   {
00029     connect(this, SIGNAL(registerFile(std::string)), m, SLOT(registerFile(std::string)));
00030     connect(this, SIGNAL(unregisterFile(std::string)), m, SLOT(unregisterFile(std::string)));
00031   }


Member Function Documentation

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.

Note:
When an object is handled by the WatchDog, you have to use this method to change its filename.

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.

Parameters:
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.

References forall, and names.

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   }


Member Data Documentation

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().

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().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:37 2013 for VVE by  doxygen 1.6.3