00001 00002 // $Id: CfgConfigurable.cxx,v 1.8 2004/03/11 15:34:20 rhatcher Exp $ 00003 // 00004 // A base class for classes configured using registries 00005 // 00006 // messier@huhepl.harvard.edu 00008 #include "Configurable/CfgConfigurable.h" 00009 #include "Configurable/Cfg.h" 00010 #include "Configurable/CfgDialog.h" 00011 00012 ClassImp(CfgConfigurable) 00013 00014 //...................................................................... 00015 00016 CfgConfigurable::CfgConfigurable() : fConfig(false) { } 00017 00018 //...................................................................... 00019 00020 CfgConfigurable::~CfgConfigurable() { } 00021 00022 //...................................................................... 00023 00024 void CfgConfigurable::CommitDefaultConfig(const Registry& r) 00025 { 00030 fDefConfig = r; 00031 } 00032 00033 //...................................................................... 00034 00035 const Registry& CfgConfigurable::DefaultConfig() const 00036 { 00041 return fDefConfig; 00042 } 00043 00044 Registry& CfgConfigurable::GetConfig() 00045 { 00050 return fConfig; 00051 } 00052 00053 const Registry& CfgConfigurable::GetConfig() const 00054 { 00060 return fConfig; 00061 } 00062 00063 //...................................................................... 00064 00065 int CfgConfigurable::Update() 00066 { 00072 if (! fConfig.IsDirty()) return 0; // Nothing to do if config is current 00073 this->Config(); // Send the "reconfig" message 00074 fConfig.SetDirty(false); // Mark the config. as current 00075 return 1; 00076 } 00077 00078 //...................................................................... 00079 00080 void CfgConfigurable::Set(CfgDialog* d) 00081 { 00082 //====================================================================== 00083 // Update the configuration parameters. Allow a CfgDialog object to be 00084 // passed in. If none is passed in use the default, text based dialog 00085 // object. 00086 //====================================================================== 00087 bool deleteDialog = false; 00088 if (d==0) { 00089 d = new CfgDialog(); 00090 deleteDialog = true; 00091 } 00092 00093 // Set up d with the default configuration parameters 00094 d->SetDefault(this->DefaultConfig()); 00095 d->SetCurrent(this->GetConfig()); 00096 00097 // Do the querry 00098 Registry r = d->Query(); 00099 this->GetConfig().UnLockValues(); 00100 this->GetConfig().Merge(r); 00101 this->GetConfig().LockValues(); 00102 00103 // Clean up the dialog 00104 if (deleteDialog) { delete d; d = 0; } 00105 } 00106 00107 //...................................................................... 00108 00109 void CfgConfigurable::Set(const char* s) 00110 { 00115 Registry r; 00116 Cfg::StringToRegistry(r,s); 00117 this->GetConfig().UnLockValues(); 00118 this->GetConfig().Merge(r); 00119 this->GetConfig().LockValues(); 00120 } 00121
1.3.9.1