A base class for classes configured using registries. More...
#include <TDbiCfgConfigurable.hxx>
Public Member Functions | |
TDbiCfgConfigurable () | |
virtual | ~TDbiCfgConfigurable () |
virtual void | Config ()=0 |
Subclass should implement this method:. | |
virtual const TDbiRegistry & | DefaultConfig () const |
Access default and main configuration. | |
TDbiRegistry & | GetConfig () |
const TDbiRegistry & | GetConfig () const |
int | Update () |
void | Set (TDbiCfgDialog *d=0) |
Set config via interactive dialog. | |
void | Set (const char *s) |
Set config via string. | |
Protected Member Functions | |
virtual void | CommitDefaultConfig (const TDbiRegistry &r) |
Private Attributes | |
TDbiRegistry | fDefConfig |
TDbiRegistry | fConfig |
A base class for classes configured using registries.
Configurable classes must implement the "Config" method which in order to make any necessary changes needed to reflect the change in configuration. The "Update" method can be called frequently. It will call Config() if and only if the configuration has changed since the last call to Config(). If no parameters have changed, the method returns very quickly as no actions are taken. To use this class, you *must* do the following in your constructor: class C : public TDbiCfgConfigurable { C:C() { // fill the default config: TDbiRegistry r; r.Set("a",42); r.Set("b",6.9); // etc. And prime the actual configuration: this->CommitDefaultConfig(r); } This ensures that the configuration used in the future starts with the correct defaults. messier@huhepl.harvard.edu 2002/08/23, modifed to inherit from TDbiRegistry and not call Config() in the sub constructor. bv@bnl.gov 2002/08/29, not IsA, but HaveA TDbiRegistry. bv@bnl.gov
Definition at line 57 of file TDbiCfgConfigurable.hxx.
TDbiCfgConfigurable::TDbiCfgConfigurable | ( | ) |
TDbiCfgConfigurable::~TDbiCfgConfigurable | ( | ) | [virtual] |
Definition at line 20 of file TDbiCfgConfigurable.cxx.
void TDbiCfgConfigurable::CommitDefaultConfig | ( | const TDbiRegistry & | r | ) | [protected, virtual] |
Subclass must call this before the Configurable can have meaningful entries
Definition at line 27 of file TDbiCfgConfigurable.cxx.
References fDefConfig.
00028 { 00029 00030 fDefConfig = r; 00031 }
virtual void TDbiCfgConfigurable::Config | ( | ) | [pure virtual] |
Subclass should implement this method:.
Implemented in TDbiDatabaseManager.
Referenced by Update().
const TDbiRegistry & TDbiCfgConfigurable::DefaultConfig | ( | ) | const [virtual] |
Access default and main configuration.
Eventually this might go in the database and load the configuration. This would take a name or something.
Definition at line 38 of file TDbiCfgConfigurable.cxx.
References fDefConfig.
Referenced by Set().
00039 { 00040 return fDefConfig; 00041 }
const TDbiRegistry & TDbiCfgConfigurable::GetConfig | ( | ) | const |
Returns the configuration TDbiRegistry. This const version denies the user any freedom to modify it, but does mean that a configurable object can use it in a const method.
Definition at line 56 of file TDbiCfgConfigurable.cxx.
References fConfig.
00057 { 00058 00059 return fConfig; 00060 }
TDbiRegistry & TDbiCfgConfigurable::GetConfig | ( | ) |
Returns the configuration TDbiRegistry, this is non-const as the user is user is free to modify
Definition at line 46 of file TDbiCfgConfigurable.cxx.
References fConfig.
Referenced by TDbiDatabaseManager::Config(), Set(), and TDbiDatabaseManager::~TDbiDatabaseManager().
00047 { 00048 00049 return fConfig; 00050 }
void TDbiCfgConfigurable::Set | ( | const char * | s | ) |
Set config via string.
Update the configuration given a text string s. Format: "key1=true, key2=10, key3=11.1, key4='A string'"
Definition at line 111 of file TDbiCfgConfigurable.cxx.
References GetConfig(), TDbiRegistry::LockValues(), TDbiRegistry::Merge(), TDbiCfg::StringToTDbiRegistry(), and TDbiRegistry::UnLockValues().
00112 { 00113 00114 TDbiRegistry r; 00115 TDbiCfg::StringToTDbiRegistry(r,s); 00116 this->GetConfig().UnLockValues(); 00117 this->GetConfig().Merge(r); 00118 this->GetConfig().LockValues(); 00119 }
void TDbiCfgConfigurable::Set | ( | TDbiCfgDialog * | d = 0 |
) |
Set config via interactive dialog.
Update the configuration parameters. Allow a TDbiCfgDialog object to be passed in. If none is passed in use the default, text based dialog
Definition at line 83 of file TDbiCfgConfigurable.cxx.
References DefaultConfig(), GetConfig(), TDbiRegistry::LockValues(), TDbiRegistry::Merge(), TDbiCfgDialog::Query(), TDbiCfgDialog::SetCurrent(), TDbiCfgDialog::SetDefault(), and TDbiRegistry::UnLockValues().
Referenced by TDbiDatabaseManager::SetConfigFromEnvironment().
00084 { 00085 00086 bool deleteDialog = false; 00087 if (d==0) { 00088 d = new TDbiCfgDialog(); 00089 deleteDialog = true; 00090 } 00091 00092 // Set up d with the default configuration parameters 00093 d->SetDefault(this->DefaultConfig()); 00094 d->SetCurrent(this->GetConfig()); 00095 00096 // Do the querry 00097 TDbiRegistry r = d->Query(); 00098 this->GetConfig().UnLockValues(); 00099 this->GetConfig().Merge(r); 00100 this->GetConfig().LockValues(); 00101 00102 // Clean up the dialog 00103 if (deleteDialog) { delete d; d = 0; } 00104 }
int TDbiCfgConfigurable::Update | ( | ) |
Call anytime. Triggers Config() only if it has been modifed since last calling.
Update the class's state given the current configuration. If there is nothing to do just return w/o taking any action. Return's 0 if no action was taken, >0 if the object was reconfigured.
Definition at line 68 of file TDbiCfgConfigurable.cxx.
References Config(), fConfig, TDbiRegistry::IsDirty(), and TDbiRegistry::SetDirty().
Referenced by TDbiDatabaseManager::SetConfigFromEnvironment().
00069 { 00070 00071 if (! fConfig.IsDirty()) return 0; // Nothing to do if config is current 00072 this->Config(); // Send the "reconfig" message 00073 fConfig.SetDirty(false); // Mark the config. as current 00074 return 1; 00075 }
TDbiRegistry TDbiCfgConfigurable::fConfig [private] |
Definition at line 87 of file TDbiCfgConfigurable.hxx.
Referenced by GetConfig(), and Update().
TDbiRegistry TDbiCfgConfigurable::fDefConfig [private] |
Definition at line 87 of file TDbiCfgConfigurable.hxx.
Referenced by CommitDefaultConfig(), and DefaultConfig().