CfgConfig Class Reference

#include <CfgConfig.h>

List of all members.

Public Types

typedef std::map< std::string,
CfgParam * > 
CfgParamMap

Public Member Functions

const char * GetName () const
const char * GetVersion () const
const char * GetSource () const
const CfgParamoperator() (const char *pname) const
const CfgParamoperator() (const std::string &pname) const
bool IsEditable () const
 CfgConfig (const char *name, const char *version, const char *source)
 ~CfgConfig ()
void AdoptParam (CfgParam *p)
void RemoveParam (const char *which="*")
CfgParamParam (const char *pname)
CfgParamParam (const std::string &pname)
bool EditOK () const
void SetReadOnly (int flag=1)
void SetSource (const char *filename)
CfgParamMapParamMap ()

Static Public Member Functions

static void SetEditAllOK ()
static void Copy (CfgConfig &dest, const CfgConfig &src, const char *destVersion=0, const char *destSource=0)

Private Attributes

bool fEditable
 Allow edits to this config?
std::string fName
 Name of configuration.
std::string fVersion
 Version tag of configuration.
std::string fSource
 Source of config. data (file name eg.).
CfgParamMap fParam
 Collection of parameters.


Detailed Description

Definition at line 26 of file CfgConfig.h.


Member Typedef Documentation

typedef std::map<std::string, CfgParam*> CfgConfig::CfgParamMap

Definition at line 60 of file CfgConfig.h.


Constructor & Destructor Documentation

CfgConfig::CfgConfig ( const char *  name,
const char *  version,
const char *  source 
)

Definition at line 25 of file CfgConfig.cxx.

00027                                  : 
00028   fEditable( true    ),
00029   fName    ( name    ),
00030   fVersion ( version ),
00031   fSource  ( source  )
00032 { }

CfgConfig::~CfgConfig (  ) 

Definition at line 36 of file CfgConfig.cxx.

References fEditable, and RemoveParam().

00036 { fEditable = true; this->RemoveParam("*"); }


Member Function Documentation

void CfgConfig::AdoptParam ( CfgParam p  ) 

Definition at line 196 of file CfgConfig.cxx.

References EditOK(), fParam, p, and s.

Referenced by CfgXMLconfigBuilder::Build(), TestBuilder::BuildCfg1(), TestBuilder::BuildCfg2(), Copy(), EVDCfgEdit::EditConfig(), and main().

00197 {
00198 //======================================================================
00199 // Insert the parameter p into a configuration. If the parameter
00200 // already exists in the configuration then replace it. Ownership of
00201 // the parameter stored at p is transferred to the configuration.
00202 //======================================================================
00203   this->EditOK();
00204   
00205   std::string s = p->GetName();
00206   
00207   // Check the parameter set for one of this name. If one is found
00208   // replace it
00209   CfgParam* param = fParam[s];
00210   if (param==0) delete param;
00211   
00212   fParam[s] = p;
00213 }

void CfgConfig::Copy ( CfgConfig dest,
const CfgConfig src,
const char *  destVersion = 0,
const char *  destSource = 0 
) [static]

Definition at line 243 of file CfgConfig.cxx.

References AdoptParam(), EditOK(), fName, fParam, fSource, fVersion, p, and RemoveParam().

Referenced by CfgXMLconfigBuilder::Build(), CfgConfigEditor::Cancel(), CfgConfigEditor::Edit(), and CfgConfigEditor::Reset().

00247 {
00248 //======================================================================
00249 // Copy one configuration to another
00250 //   dest - configuration to copy to
00251 //   src  - configuration to copy from
00252 //   destVersion - version tag appied to dest (default appends '.copy')
00253 //   destSource  - source tag appied to dest (default appends '(copy)' )
00254 //======================================================================
00255   dest.EditOK();
00256 
00257   dest.fName = src.fName;
00258   if (destVersion==0) { 
00259     dest.fVersion  = src.fVersion;
00260     dest.fVersion += ".copy";
00261   }
00262   else {
00263     dest.fVersion = destVersion;
00264   }
00265   if (destSource==0) {
00266     dest.fSource  = src.fSource;
00267     dest.fSource += "(copy)";
00268   }
00269   else {
00270     dest.fSource = destSource;
00271   }
00272 
00273   // Wipe the parameter map clean and build a new one using the CfgParam
00274   // copy constructor on each element in the source map
00275   dest.RemoveParam("*");
00276   CfgParamMap::const_iterator    itr(src.fParam.begin());
00277   CfgParamMap::const_iterator itrEnd(src.fParam.end());
00278   for (; itr!=itrEnd; ++itr) {
00279     CfgParam* p = new CfgParam(*itr->second);
00280     dest.AdoptParam(p);
00281   }
00282 }

bool CfgConfig::EditOK (  )  const

Definition at line 136 of file CfgConfig.cxx.

References fEditable, GetVersion(), gsAllEditOK, CfgException::kConfigRO, and os.

Referenced by AdoptParam(), Copy(), CfgConfigEditor::Edit(), Param(), RemoveParam(), and SetReadOnly().

00137 {
00138 //======================================================================
00139 // Check if it is OK to edit this configuration. Throws exception is
00140 // edit is not allowed
00141 //======================================================================
00142   if (gsAllEditOK) return true;
00143   if (fEditable==false) {
00144     std::ostringstream os;
00145     os << "Attempt to get read access to read-only config "
00146        << "." << this->GetVersion();
00147     throw CfgException(CfgException::kConfigRO,
00148                os.str().c_str(),
00149                __FILE__,
00150                __LINE__);
00151   }
00152   return fEditable;
00153 }

const char * CfgConfig::GetName (  )  const

Definition at line 40 of file CfgConfig.cxx.

References fName.

Referenced by CfgTable::AdoptConfig(), CfgConfigEditor::Edit(), EVDCfgEdit::EVDCfgEdit(), main(), CfgConfigBuilder::Publish(), TPCBadChannel::Update(), TestObs::Update(), TestObserver::Update(), RunConfig::Update(), and RICHChan::Update().

00040 { return fName.c_str(); }

const char * CfgConfig::GetSource (  )  const

Definition at line 48 of file CfgConfig.cxx.

References fSource.

Referenced by CfgConfigEditor::Cancel(), CfgConfigEditor::Edit(), EVDCfgEdit::EVDCfgEdit(), main(), CfgConfigEditor::Reset(), TPCBadChannel::Update(), RICHExample::Update(), and RICHChan::Update().

00048 { return fSource.c_str(); }

const char * CfgConfig::GetVersion (  )  const

Definition at line 44 of file CfgConfig.cxx.

References fVersion.

Referenced by CfgTable::AdoptConfig(), CfgConfigEditor::Cancel(), CfgConfigEditor::Edit(), EditOK(), EVDCfgEdit::EVDCfgEdit(), main(), CfgConfigBuilder::Publish(), CfgConfigEditor::Reset(), TPCBadChannel::Update(), TestObs::Update(), TestObserver::Update(), and RICHChan::Update().

00044 { return fVersion.c_str(); }

bool CfgConfig::IsEditable (  )  const

Definition at line 52 of file CfgConfig.cxx.

References fEditable.

00052 { return fEditable; }

const CfgParam & CfgConfig::operator() ( const std::string &  pname  )  const

Definition at line 73 of file CfgConfig.cxx.

References fName, fParam, fVersion, CfgException::kParamNotFound, and os.

00074 {
00075 //======================================================================
00076 // Allows read-only access to parameters
00077 //======================================================================
00078   CfgParamMap::iterator itr = fParam.find(pname);
00079   if (itr==fParam.end()) {
00080     std::ostringstream os;
00081     os << "Parameter " << pname    << " not found in configuration " 
00082        << fName << ":" << fVersion << std::endl;
00083     throw CfgException(CfgException::kParamNotFound,
00084                os.str().c_str(),
00085                __FILE__,
00086                __LINE__);
00087   }
00088   return (*itr->second);
00089 }

const CfgParam & CfgConfig::operator() ( const char *  pname  )  const

Definition at line 56 of file CfgConfig.cxx.

References fParam, and CfgException::kParamNotFound.

00057 {
00058 //======================================================================
00059 // Allows read-only access to parameters
00060 //======================================================================
00061   CfgParamMap::iterator itr = fParam.find(pname);
00062   if (itr==fParam.end()) {
00063     throw CfgException(CfgException::kParamNotFound,
00064                pname, 
00065                __FILE__,
00066                __LINE__);
00067   }
00068   return (*itr->second);
00069 }

CfgParam & CfgConfig::Param ( const std::string &  pname  ) 

Definition at line 115 of file CfgConfig.cxx.

References EditOK(), fName, fParam, fVersion, CfgException::kParamNotFound, and os.

00116 {
00117 //======================================================================
00118 // Allows non-const access to parameters
00119 //======================================================================
00120   this->EditOK();
00121   CfgParamMap::iterator itr = fParam.find(pname);
00122   if (itr==fParam.end()) {
00123     std::ostringstream os;
00124     os << "Parameter " << pname    << " not found in configuration " 
00125        << fName << ":" << fVersion << std::endl;
00126     throw CfgException(CfgException::kParamNotFound,
00127                os.str().c_str(),
00128                __FILE__,
00129                __LINE__);
00130   }
00131   return (*itr->second);
00132 }

CfgParam & CfgConfig::Param ( const char *  pname  ) 

Definition at line 93 of file CfgConfig.cxx.

References EditOK(), fName, fParam, fVersion, CfgException::kParamNotFound, os, and p.

Referenced by CfgXMLconfigBuilder::Build(), and TestEditor::EditConfig().

00094 {
00095 //======================================================================
00096 // Allows non-const access to parameters
00097 //======================================================================
00098   this->EditOK();
00099   std::string p(pname);
00100   CfgParamMap::iterator itr = fParam.find(p);
00101   if (itr==fParam.end()) {
00102     std::ostringstream os;
00103     os << "Parameter " << pname    << " not found in configuration " 
00104        << fName << ":" << fVersion << std::endl;
00105     throw CfgException(CfgException::kParamNotFound,
00106                os.str().c_str(),
00107                __FILE__,
00108                __LINE__);
00109   }
00110   return (*itr->second);
00111 }

CfgParamMap& CfgConfig::ParamMap (  )  [inline]

Definition at line 61 of file CfgConfig.h.

References fParam.

00061 { return fParam; }

void CfgConfig::RemoveParam ( const char *  which = "*"  ) 

Definition at line 217 of file CfgConfig.cxx.

References EditOK(), fParam, and s.

Referenced by Copy(), and ~CfgConfig().

00218 {
00219 //======================================================================
00220 // Remove a selected parameter from the configuration. "*" removes all
00221 // parameters
00222 //======================================================================
00223   this->EditOK();
00224 
00225   std::string s(which);
00226   // If which is "*" remove all parameters
00227   if (s=="*") {
00228     CfgParamMap::iterator    itr(fParam.begin());
00229     CfgParamMap::iterator itrEnd(fParam.end());
00230     for (; itr!=itrEnd; ++itr) {
00231       if (itr->second) { delete itr->second; itr->second = 0; }
00232     }
00233     return;
00234   }
00235   
00236   // Otherwise just remove the named set
00237   CfgParam* param = fParam[s];
00238   if (param==0) { delete param; fParam[s] = 0; }
00239 }

void CfgConfig::SetEditAllOK (  )  [static]

Definition at line 21 of file CfgConfig.cxx.

References gsAllEditOK.

Referenced by EVDJobMenu::OpenJobXML().

00021 { gsAllEditOK = true; }

void CfgConfig::SetReadOnly ( int  flag = 1  ) 

Definition at line 157 of file CfgConfig.cxx.

References EditOK(), fEditable, gsNoDefaultEdits, and gsNoEdits.

Referenced by CfgXMLconfigBuilder::Build(), and CfgConfigBuilder::Publish().

00158 {
00159 //======================================================================
00160 // Set the read-only status for this configuration.
00161 //   flag =  0 - allow read/write access
00162 //   flag =  1 - read only access
00163 //   flag = -1 - determine read/write accees based on R/W policies for
00164 //               configurations
00165 //======================================================================
00166   if (flag == 1 && fEditable == false) return; // RO already
00167   
00168   // First make sure we are allowed to change the state. Once set read
00169   // only the configuration is always read only
00170   this->EditOK();
00171 
00172   if (flag ==  0) { fEditable = true;  return; } // RW
00173   if (flag ==  1) { fEditable = false; return; } // RO
00174 
00175   // Apply policy to determine RW status
00176   
00177   // Edits turned off globally
00178   if (gsNoEdits == true) { fEditable = false; return; } // RO
00179   
00180   // Edits turned off globally for default configurations
00181   if ( (gsNoDefaultEdits == true) && (this->fVersion == "default") ) {
00182     fEditable = false; // RO
00183     return;
00184   }
00185   
00186   // Edit allowed
00187   fEditable = true; // RW
00188 }

void CfgConfig::SetSource ( const char *  filename  ) 

Definition at line 192 of file CfgConfig.cxx.

References fSource.

00192 { fSource = filename; }


Member Data Documentation

bool CfgConfig::fEditable [private]

Allow edits to this config?

Definition at line 64 of file CfgConfig.h.

Referenced by EditOK(), IsEditable(), SetReadOnly(), and ~CfgConfig().

std::string CfgConfig::fName [private]

Name of configuration.

Definition at line 65 of file CfgConfig.h.

Referenced by Copy(), GetName(), operator()(), and Param().

CfgParamMap CfgConfig::fParam [mutable, private]

Collection of parameters.

Definition at line 68 of file CfgConfig.h.

Referenced by AdoptParam(), Copy(), operator()(), Param(), ParamMap(), and RemoveParam().

std::string CfgConfig::fSource [private]

Source of config. data (file name eg.).

Definition at line 67 of file CfgConfig.h.

Referenced by Copy(), GetSource(), and SetSource().

std::string CfgConfig::fVersion [private]

Version tag of configuration.

Definition at line 66 of file CfgConfig.h.

Referenced by Copy(), GetVersion(), operator()(), and Param().


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