CfgTable Class Reference

#include <CfgTable.h>

List of all members.

Public Types

typedef std::list< CfgObserver * > ObsList
 List of observers.
typedef std::list< CfgConfig * > ConfigList
 List of configurations.
typedef std::pair< std::string,
std::string > 
NVPair
 Configuration name/verison pair.
typedef std::list< NVPairNVPairList
 List of configuration name/verison pair.
typedef std::map< CfgObserver *,
NVPairList
ObsTable
 Table of observers.

Public Member Functions

CfgConfigGetConfig (const char *name, const char *version) const
void GetObservers (const char *name, const char *version, ObsList &obslist) const
void Print (std::ostream &os=std::cout) const
void AdoptConfig (CfgConfig *cfg)
ConfigListGetList ()
void SetWatch (const char *cfg, const char *ver, CfgObserver *obs)
void RemoveWatch (const char *config, CfgObserver *obs)
void RemoveAllWatches (CfgObserver *obs)

Static Public Member Functions

static CfgTableInstance ()

Private Attributes

ConfigList fConfigList
 List of configurations defined.
ObsTable fObsTable
 Table of registered clients.

Static Private Attributes

static CfgTablefInstance = 0
 Sole instance of the table class.


Detailed Description

Definition at line 18 of file CfgTable.h.


Member Typedef Documentation

typedef std::list<CfgConfig*> CfgTable::ConfigList

List of configurations.

Definition at line 25 of file CfgTable.h.

typedef std::pair<std::string,std::string> CfgTable::NVPair

Configuration name/verison pair.

Definition at line 28 of file CfgTable.h.

typedef std::list<NVPair> CfgTable::NVPairList

List of configuration name/verison pair.

Definition at line 31 of file CfgTable.h.

typedef std::list<CfgObserver*> CfgTable::ObsList

List of observers.

Definition at line 22 of file CfgTable.h.

typedef std::map<CfgObserver*,NVPairList> CfgTable::ObsTable

Table of observers.

Definition at line 34 of file CfgTable.h.


Member Function Documentation

void CfgTable::AdoptConfig ( CfgConfig cfg  ) 

Definition at line 102 of file CfgTable.cxx.

References fConfigList, CfgConfig::GetName(), and CfgConfig::GetVersion().

Referenced by CfgConfigEditor::Apply(), main(), and CfgConfigBuilder::Publish().

00103 {
00104 //======================================================================
00105 // Place the configuration into the list
00106 //======================================================================
00107   std::string n(cfg->GetName());
00108   std::string v(cfg->GetVersion());
00109   
00110   // Check if a configuration matching this name and version exists.
00111   // If yes, replace it
00112   ConfigList::iterator itr   (fConfigList.begin());
00113   ConfigList::iterator itrEnd(fConfigList.end());
00114   for (; itr!=itrEnd; ++itr) {
00115     CfgConfig* inlist = *itr;
00116     if (n == inlist->GetName() && v == inlist->GetVersion()) {
00117       // replace existing config with new
00118       delete inlist;
00119       *itr = cfg;
00120       return;
00121     }
00122   }
00123   
00124   // Insert the configuration into the list
00125   fConfigList.push_back(cfg);
00126 }

CfgConfig * CfgTable::GetConfig ( const char *  name,
const char *  version 
) const

Definition at line 26 of file CfgTable.cxx.

References fConfigList.

Referenced by CfgXMLconfigBuilder::Build(), main(), and CfgObserver::SetWatch().

00027 {
00028 //======================================================================
00029 // Find and return the configuration that matches the requested name
00030 // and version
00031 //======================================================================
00032   std::string n(name);
00033   std::string v(version);
00034   
00035   // Loop over configurations looking for one that matches
00036   ConfigList::iterator itr   (fConfigList.begin());
00037   ConfigList::iterator itrEnd(fConfigList.end());
00038   for (; itr!=itrEnd; ++itr) {
00039     CfgConfig* cfg = *itr;
00040     if (n == cfg->GetName() && v == cfg->GetVersion()) return cfg;
00041   }
00042 
00043   // Not found
00044   return 0;
00045 }

ConfigList& CfgTable::GetList (  )  [inline]

Definition at line 46 of file CfgTable.h.

References fConfigList.

Referenced by EVDJobMenu::BuildConfigMenu(), and EVDEditMenu::EVDEditMenu().

00046 { return fConfigList; }

void CfgTable::GetObservers ( const char *  name,
const char *  version,
ObsList obslist 
) const

Definition at line 49 of file CfgTable.cxx.

References fObsTable.

Referenced by CfgConfigEditor::Apply(), Print(), and CfgConfigBuilder::Publish().

00052 {
00053 //======================================================================
00054 // Unpack the observers of configuration "name.version" to the list
00055 // obslist
00056 //======================================================================
00057   ObsTable::iterator otItr   (fObsTable.begin());
00058   ObsTable::iterator otItrEnd(fObsTable.end());
00059   for (; otItr!=otItrEnd; ++otItr) {
00060     CfgObserver* obs    = otItr->first;
00061     NVPairList&  nvlist = otItr->second;
00062     
00063     NVPairList::iterator nvItr(nvlist.begin());
00064     NVPairList::iterator nvItrEnd(nvlist.end());
00065     for (; nvItr != nvItrEnd; ++nvItr) {
00066       std::string& n = nvItr->first;
00067       std::string& v = nvItr->second;
00068       
00069       if (n == name && v == version) obslist.push_back(obs);
00070       
00071     } // Loop on configuration name/version pairs
00072   } // Loop on all observers
00073 }

CfgTable & CfgTable::Instance (  )  [static]

Definition at line 15 of file CfgTable.cxx.

References fInstance.

Referenced by CfgConfigEditor::Apply(), CfgXMLconfigBuilder::Build(), EVDJobMenu::BuildConfigMenu(), EVDEditMenu::EVDEditMenu(), main(), CfgConfigBuilder::Publish(), CfgObserver::RemoveAllWatches(), CfgObserver::RemoveWatch(), and CfgObserver::SetWatch().

00016 {
00017 //======================================================================
00018 // Return the sole instance of this class
00019 //======================================================================
00020   if (fInstance == 0) fInstance = new CfgTable;
00021   return (*fInstance);
00022 }

void CfgTable::Print ( std::ostream &  os = std::cout  )  const

Definition at line 77 of file CfgTable.cxx.

References fConfigList, and GetObservers().

Referenced by main().

00078 {
00079 //======================================================================
00080 // Print all the configurations and their watchers
00081 //======================================================================
00082   ConfigList::const_iterator itr(fConfigList.begin());
00083   ConfigList::const_iterator itrEnd(fConfigList.end());
00084   for (; itr!=itrEnd; ++itr) {
00085     CfgConfig* c = *itr;
00086     os << c->GetName() << "." << c->GetVersion() << "\t";
00087 
00088     os << "obs={ ";
00089     ObsList obslist;
00090     this->GetObservers(c->GetName(), c->GetVersion(), obslist);
00091     ObsList::const_iterator itr2(obslist.begin());
00092     ObsList::const_iterator itrEnd2(obslist.end());
00093     for (; itr2!=itrEnd2; ++itr2) {
00094       os << *itr2 << " ";
00095     }
00096     os << "}" << std::endl;
00097   }
00098 }

void CfgTable::RemoveAllWatches ( CfgObserver obs  ) 

Definition at line 179 of file CfgTable.cxx.

References fObsTable.

Referenced by main(), and CfgObserver::RemoveAllWatches().

00180 {
00181   // Erase the configuration list for this observer
00182   NVPairList& nvplist = fObsTable[obs];
00183   nvplist.clear();
00184   
00185   fObsTable.erase(obs);
00186 }

void CfgTable::RemoveWatch ( const char *  config,
CfgObserver obs 
)

Definition at line 157 of file CfgTable.cxx.

References fObsTable.

Referenced by main(), and CfgObserver::RemoveWatch().

00158 {
00159 //======================================================================
00160 // Drop the watch set by observer obs to the configuration named
00161 // "config"
00162 //======================================================================
00163   // Get the list of configuration name/version pairs
00164   NVPairList& nvlist = fObsTable[obs];
00165   
00166   // Erase each entry which matches the config name
00167   NVPairList::iterator    itr(nvlist.begin());
00168   NVPairList::iterator itrEnd(nvlist.end());
00169   for (; itr!=itrEnd; ++itr) {
00170     if (itr->first == config) {
00171       nvlist.erase(itr);
00172       return;
00173     }
00174   }
00175 }

void CfgTable::SetWatch ( const char *  cfg,
const char *  ver,
CfgObserver obs 
)

Definition at line 130 of file CfgTable.cxx.

References fObsTable.

Referenced by CfgObserver::SetWatch().

00133 {
00134 //======================================================================
00135 // Set a watch from observer obs to configuration with name
00136 // config.version
00137 //======================================================================
00138   NVPairList& nvlist = fObsTable[obs];
00139   
00140   NVPairList::iterator itr   (nvlist.begin());
00141   NVPairList::iterator itrEnd(nvlist.end());
00142   
00143   // Look if there is already a watch for this configuration. If yes,
00144   // update the version watched
00145   for (; itr!=itrEnd; ++itr) {
00146     if (itr->first == config) {
00147       itr->second = version;
00148       return;
00149     }
00150   }
00151   // Reach here if no watch was set for this config
00152   nvlist.push_back(NVPair(config,version));
00153 }


Member Data Documentation

ConfigList CfgTable::fConfigList [mutable, private]

List of configurations defined.

Definition at line 53 of file CfgTable.h.

Referenced by AdoptConfig(), GetConfig(), GetList(), and Print().

CfgTable * CfgTable::fInstance = 0 [static, private]

Sole instance of the table class.

Definition at line 52 of file CfgTable.h.

Referenced by Instance().

ObsTable CfgTable::fObsTable [mutable, private]

Table of registered clients.

Definition at line 54 of file CfgTable.h.

Referenced by GetObservers(), RemoveAllWatches(), RemoveWatch(), and SetWatch().


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 08:04:00 2009 for MIPP(E907) by  doxygen 1.4.7