//////////////////////////////////////////////////////////////////////// // // // A base class for classes configured using registries // // messier@huhepl.harvard.edu //////////////////////////////////////////////////////////////////////// #include "IDbiCfgConfigurable.hxx" #include "IDbiCfg.hxx" #include "IDbiCfgDialog.hxx" ClassImp(COMET::IDbiCfgConfigurable) //...................................................................... COMET::IDbiCfgConfigurable::IDbiCfgConfigurable() : fConfig(false) { } //...................................................................... COMET::IDbiCfgConfigurable::~IDbiCfgConfigurable() { } //...................................................................... /// /// Subclass must call this before the Configurable can have /// meaningful entries /// void COMET::IDbiCfgConfigurable::CommitDefaultConfig(const IDbiRegistry& r) { fDefConfig = r; } //...................................................................... // /// Eventually this might go in the database and load the /// configuration. This would take a name or something. //==================================================================== const COMET::IDbiRegistry& COMET::IDbiCfgConfigurable::DefaultConfig() const { return fDefConfig; } //====================================================================== /// Returns the configuration IDbiRegistry, this is non-const as the user /// is user is free to modify //====================================================================== COMET::IDbiRegistry& COMET::IDbiCfgConfigurable::GetConfig() { return fConfig; } //====================================================================== /// Returns the configuration IDbiRegistry. 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. //====================================================================== const COMET::IDbiRegistry& COMET::IDbiCfgConfigurable::GetConfig() const { return fConfig; } //...................................................................... //====================================================================== /// 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. //====================================================================== int COMET::IDbiCfgConfigurable::Update() { if (! fConfig.IsDirty()) return 0; // Nothing to do if config is current this->Config(); // Send the "reconfig" message fConfig.SetDirty(false); // Mark the config. as current return 1; } //...................................................................... //====================================================================== /// Update the configuration parameters. Allow a IDbiCfgDialog object to be /// passed in. If none is passed in use the default, text based dialog // object. //====================================================================== void COMET::IDbiCfgConfigurable::Set(IDbiCfgDialog* d) { bool deleteDialog = false; if (d==0) { d = new IDbiCfgDialog(); deleteDialog = true; } // Set up d with the default configuration parameters d->SetDefault(this->DefaultConfig()); d->SetCurrent(this->GetConfig()); // Do the querry IDbiRegistry r = d->Query(); this->GetConfig().UnLockValues(); this->GetConfig().Merge(r); this->GetConfig().LockValues(); // Clean up the dialog if (deleteDialog) { delete d; d = 0; } } //...................................................................... //====================================================================== /// Update the configuration given a text string s. Format: /// "key1=true, key2=10, key3=11.1, key4='A string'" //====================================================================== void COMET::IDbiCfgConfigurable::Set(const char* s) { IDbiRegistry r; COMET::IDbiCfg::StringToTDbiRegistry(r,s); this->GetConfig().UnLockValues(); this->GetConfig().Merge(r); this->GetConfig().LockValues(); } ////////////////////////////////////////////////////////////////////////