Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cfg::Table Class Reference

Tables of configurations defined in the program and their clients. More...

#include <Table.h>

List of all members.

Public Types

typedef std::list< Observer * > ObsList
 List of observers.
typedef std::list< Config * > 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< Observer *,
NVPairList
ObsTable
 Table of observers.

Public Member Functions

ConfigGetConfig (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 (Config *cfg)
ConfigListGetList ()
void SetWatch (const char *cfg, const char *ver, Observer *obs)
void RemoveWatch (const char *config, Observer *obs)
void RemoveAllWatches (Observer *obs)

Static Public Member Functions

TableInstance ()

Private Attributes

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

Static Private Attributes

TablefInstance = 0
 Sole instance of the table class.


Detailed Description

Tables of configurations defined in the program and their clients.

Definition at line 21 of file fmwk/Config/Table.h.


Member Typedef Documentation

typedef std::list<Config*> cfg::Table::ConfigList
 

List of configurations.

Definition at line 27 of file fmwk/Config/Table.h.

typedef std::pair<std::string,std::string> cfg::Table::NVPair
 

Configuration name/verison pair.

Definition at line 30 of file fmwk/Config/Table.h.

Referenced by SetWatch().

typedef std::list<NVPair> cfg::Table::NVPairList
 

List of configuration name/verison pair.

Definition at line 33 of file fmwk/Config/Table.h.

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

typedef std::list<Observer*> cfg::Table::ObsList
 

List of observers.

Definition at line 24 of file fmwk/Config/Table.h.

Referenced by Print().

typedef std::map<Observer*,NVPairList> cfg::Table::ObsTable
 

Table of observers.

Definition at line 36 of file fmwk/Config/Table.h.


Member Function Documentation

void cfg::Table::AdoptConfig Config cfg  ) 
 

Definition at line 103 of file fmwk/Config/Table.cxx.

References fConfigList, cfg::Config::GetName(), and cfg::Config::GetVersion().

Referenced by cfg::ConfigEditor::Apply(), main(), and cfg::ConfigBuilder::Publish().

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

cfg::Config * cfg::Table::GetConfig const char *  name,
const char *  version
const
 

Definition at line 26 of file fmwk/Config/Table.cxx.

References fConfigList, cfg::Config::GetName(), and cfg::Config::GetVersion().

Referenced by cfg::configBuilder::Build(), and cfg::Observer::SetWatch().

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

ConfigList& cfg::Table::GetList  )  [inline]
 

Definition at line 48 of file fmwk/Config/Table.h.

Referenced by hdr::JobRecord::Reco().

00048 { return fConfigList; }

void cfg::Table::GetObservers const char *  name,
const char *  version,
ObsList obslist
const
 

Definition at line 50 of file fmwk/Config/Table.cxx.

References fObsTable, and NVPairList.

Referenced by cfg::ConfigEditor::Apply(), Print(), and cfg::ConfigBuilder::Publish().

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

cfg::Table & cfg::Table::Instance  )  [static]
 

Definition at line 15 of file fmwk/Config/Table.cxx.

References fInstance.

Referenced by cfg::ConfigEditor::Apply(), cfg::configBuilder::Build(), evdb::JobMenu::BuildConfigMenu(), evdb::EditMenu::EditMenu(), main(), cfg::ConfigBuilder::Publish(), hdr::JobRecord::Reco(), cfg::Observer::RemoveAllWatches(), cfg::Observer::RemoveWatch(), cfg::Observer::SetWatch(), and jobc::XMLConfiguration().

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

void cfg::Table::Print std::ostream &  os = std::cout  )  const
 

Definition at line 78 of file fmwk/Config/Table.cxx.

References fConfigList, cfg::Config::GetName(), GetObservers(), cfg::Config::GetVersion(), and ObsList.

Referenced by main().

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

void cfg::Table::RemoveAllWatches Observer obs  ) 
 

Definition at line 180 of file fmwk/Config/Table.cxx.

References fObsTable, and NVPairList.

Referenced by main(), and cfg::Observer::RemoveAllWatches().

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

void cfg::Table::RemoveWatch const char *  config,
Observer obs
 

Definition at line 158 of file fmwk/Config/Table.cxx.

References fObsTable, and NVPairList.

Referenced by main(), and cfg::Observer::RemoveWatch().

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

void cfg::Table::SetWatch const char *  cfg,
const char *  ver,
Observer obs
 

Definition at line 131 of file fmwk/Config/Table.cxx.

References fObsTable, NVPair, and NVPairList.

Referenced by cfg::Observer::SetWatch().

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


Member Data Documentation

ConfigList cfg::Table::fConfigList [mutable, private]
 

List of configurations defined.

Definition at line 55 of file fmwk/Config/Table.h.

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

cfg::Table * cfg::Table::fInstance = 0 [static, private]
 

Sole instance of the table class.

Definition at line 11 of file fmwk/Config/Table.cxx.

Referenced by Instance().

ObsTable cfg::Table::fObsTable [mutable, private]
 

Table of registered clients.

Definition at line 56 of file fmwk/Config/Table.h.

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


The documentation for this class was generated from the following files:
Generated on Sun Mar 15 04:45:25 2009 for NOvA Offline by  doxygen 1.3.9.1