TDbiCfgConfigurable.cxx

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 // 
00003 //
00004 // A base class for classes configured using registries
00005 //
00006 // messier@huhepl.harvard.edu
00007 ////////////////////////////////////////////////////////////////////////
00008 #include "TDbiCfgConfigurable.hxx"
00009 #include "TDbiCfg.hxx"
00010 #include "TDbiCfgDialog.hxx"
00011 
00012 ClassImp(TDbiCfgConfigurable)
00013 
00014 //......................................................................
00015 
00016 TDbiCfgConfigurable::TDbiCfgConfigurable() : fConfig(false) { }
00017 
00018 //......................................................................
00019 
00020 TDbiCfgConfigurable::~TDbiCfgConfigurable() { }
00021 
00022 //......................................................................
00023 ///
00024 /// Subclass must call this before the Configurable can have
00025 /// meaningful entries
00026 ///
00027 void TDbiCfgConfigurable::CommitDefaultConfig(const TDbiRegistry& r)
00028 {
00029 
00030   fDefConfig = r;
00031 }
00032 
00033 //......................................................................
00034 //
00035 /// Eventually this might go in the database and load the
00036 /// configuration. This would take a name or something. 
00037 //====================================================================
00038 const TDbiRegistry& TDbiCfgConfigurable::DefaultConfig() const 
00039 {
00040   return fDefConfig;
00041 }
00042 //======================================================================
00043 /// Returns the configuration TDbiRegistry, this is non-const as the user
00044 /// is user is free to modify
00045 //======================================================================
00046 TDbiRegistry& TDbiCfgConfigurable::GetConfig()
00047 {
00048 
00049   return fConfig;
00050 }
00051 //======================================================================
00052 /// Returns the configuration TDbiRegistry.  This const version denies
00053 /// the user any freedom to modify it, but does mean that a
00054 /// configurable object can use it in a const method.
00055 //======================================================================
00056 const TDbiRegistry& TDbiCfgConfigurable::GetConfig() const
00057 {
00058 
00059   return fConfig;
00060 }
00061 
00062 //......................................................................
00063 //======================================================================
00064 /// Update the class's state given the current configuration. If there
00065 /// is nothing to do just return w/o taking any action. Return's 0 if
00066 /// no action was taken, >0 if the object was reconfigured.
00067 //======================================================================
00068 int TDbiCfgConfigurable::Update() 
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 }
00076 
00077 //......................................................................
00078 //======================================================================
00079 /// Update the configuration parameters. Allow a TDbiCfgDialog object to be
00080 /// passed in. If none is passed in use the default, text based dialog
00081 // object.
00082 //======================================================================
00083 void TDbiCfgConfigurable::Set(TDbiCfgDialog* d) 
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 }
00105 
00106 //......................................................................
00107 //======================================================================
00108 /// Update the configuration given a text string s. Format:
00109 /// "key1=true, key2=10, key3=11.1, key4='A string'"
00110 //======================================================================
00111 void TDbiCfgConfigurable::Set(const char* s) 
00112 {
00113 
00114   TDbiRegistry r;
00115   TDbiCfg::StringToTDbiRegistry(r,s);
00116   this->GetConfig().UnLockValues();
00117   this->GetConfig().Merge(r);
00118   this->GetConfig().LockValues();
00119 }
00120 
00121 ////////////////////////////////////////////////////////////////////////

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1