CfgConfigEditor Class Reference

#include <CfgConfigEditor.h>

Inheritance diagram for CfgConfigEditor:

EVDCfgEdit TestEditor List of all members.

Public Member Functions

 CfgConfigEditor (CfgConfig *cfg)
 A class to modify an existing configuration and publish changes.
virtual ~CfgConfigEditor ()
virtual int EditConfig (CfgConfig &cfg)
 The user edit function.
void Apply ()
void Edit ()
void Reset ()
void Cancel ()

Private Attributes

bool fNewConfig
 Have we created a config. during the edit?
CfgConfigfConfig
 The configuration to be edited.
CfgConfigfConfigCopy
 A copy of the original configuration.

Detailed Description

Definition at line 22 of file CfgConfigEditor.h.


Constructor & Destructor Documentation

CfgConfigEditor::CfgConfigEditor ( CfgConfig cfg  ) 

A class to modify an existing configuration and publish changes.

Definition at line 17 of file CfgConfigEditor.cxx.

00017                                                :
00018   fNewConfig ( false ),
00019   fConfig    ( cfg   ), 
00020   fConfigCopy( 0 )  
00021 { }

CfgConfigEditor::~CfgConfigEditor (  )  [virtual]

Definition at line 25 of file CfgConfigEditor.cxx.

References fConfigCopy.

00026 {
00027 //======================================================================
00028 // Free memory used during edit
00029 //======================================================================
00030   if (fConfigCopy) { delete fConfigCopy; fConfigCopy = 0; }
00031 }


Member Function Documentation

void CfgConfigEditor::Apply (  ) 

Reimplemented in EVDCfgEdit.

Definition at line 72 of file CfgConfigEditor.cxx.

References CfgTable::AdoptConfig(), fConfig, fNewConfig, CfgTable::GetObservers(), CfgTable::Instance(), and CfgException::Print().

Referenced by Edit().

00073 {
00074 //======================================================================
00075 // Apply the changes made to the configuration.
00076 //======================================================================
00077   CfgTable& t = CfgTable::Instance();
00078   
00079   // Insert the configuration into the table of configurations 
00080   if (fNewConfig) t.AdoptConfig(fConfig);
00081   
00082   // Alert observers of this configuration to the change it its
00083   // state
00084   CfgTable::ObsList olist;
00085   t.GetObservers(fConfig->GetName(), fConfig->GetVersion(), olist);
00086 
00087   CfgTable::ObsList::iterator    itr(olist.begin());
00088   CfgTable::ObsList::iterator itrEnd(olist.end());
00089   for (; itr!=itrEnd; ++itr) try {(*itr)->Update(*fConfig); }
00090   catch (CfgException e) {
00091     std::cout << " *-> " << fConfig->GetName() << "." 
00092           << fConfig->GetVersion() << " ";
00093     e.Print();
00094     exit(-1);
00095   }
00096 }

void CfgConfigEditor::Cancel (  ) 

Reimplemented in EVDCfgEdit.

Definition at line 113 of file CfgConfigEditor.cxx.

References CfgConfig::Copy(), fConfig, fConfigCopy, fNewConfig, CfgConfig::GetSource(), and CfgConfig::GetVersion().

Referenced by Edit().

00114 {
00115 //======================================================================
00116 // Cancel the edit operation
00117 //======================================================================
00118   CfgConfig::Copy(*fConfig,
00119           *fConfigCopy,
00120           fConfigCopy->GetVersion(),
00121           fConfigCopy->GetSource());
00122   if (fNewConfig) { delete fConfig; fConfig = 0; }
00123 }

void CfgConfigEditor::Edit (  ) 

Definition at line 35 of file CfgConfigEditor.cxx.

References Apply(), Cancel(), CfgConfig::Copy(), EditConfig(), CfgConfig::EditOK(), fConfig, fConfigCopy, CfgConfig::GetName(), CfgConfig::GetSource(), and CfgConfig::GetVersion().

Referenced by EVDCfgEdit::Apply(), and main().

00036 {
00037 //======================================================================
00038 // Actually do the edit
00039 //======================================================================
00040 
00041   // Test if the edit of the configuration is OK
00042   if (fConfig->EditOK()==false) return;
00043 
00044   // Make a copy of the configuration prior to any changes
00045   fConfigCopy = new CfgConfig(fConfig->GetName(),"dummy","dummy");
00046   CfgConfig::Copy(*fConfigCopy,
00047           *fConfig,
00048           fConfig->GetVersion(),
00049           fConfig->GetSource());
00050   
00051   // Make the edit
00052   int apply = this->EditConfig(*fConfig);
00053 
00054   // Apply any changes
00055   if (apply==0) this->Cancel();
00056   else          this->Apply();
00057 }

int CfgConfigEditor::EditConfig ( CfgConfig cfg  )  [virtual]

The user edit function.

Modify cfg at by some means. Return 1 to apply changes made to cfg, 0 to discard them

Reimplemented in TestEditor, and EVDCfgEdit.

Definition at line 61 of file CfgConfigEditor.cxx.

Referenced by Edit().

00062 {
00063 //======================================================================
00064 // User edit routine. Modify the configuration cfg.
00065 //======================================================================
00066   return 0; // Do not apply edits
00067   // return 1; // Apply edits
00068 }

void CfgConfigEditor::Reset (  ) 

Definition at line 100 of file CfgConfigEditor.cxx.

References CfgConfig::Copy(), fConfig, fConfigCopy, CfgConfig::GetSource(), and CfgConfig::GetVersion().

00101 {
00102 //======================================================================
00103 // Set the state of the configuration back to what it was prior to edit
00104 //======================================================================
00105   CfgConfig::Copy(*fConfig,
00106           *fConfigCopy,
00107           fConfigCopy->GetVersion(),
00108           fConfigCopy->GetSource());
00109 }


Member Data Documentation

CfgConfig* CfgConfigEditor::fConfig [private]

The configuration to be edited.

Definition at line 39 of file CfgConfigEditor.h.

Referenced by Apply(), Cancel(), Edit(), and Reset().

CfgConfig* CfgConfigEditor::fConfigCopy [private]

A copy of the original configuration.

Definition at line 40 of file CfgConfigEditor.h.

Referenced by Cancel(), Edit(), Reset(), and ~CfgConfigEditor().

bool CfgConfigEditor::fNewConfig [private]

Have we created a config. during the edit?

Definition at line 38 of file CfgConfigEditor.h.

Referenced by Apply(), and Cancel().


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