Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

cfg::ConfigEditor Class Reference

A class to modify an existing configuration and publish changes. More...

#include <ConfigEditor.h>

Inheritance diagram for cfg::ConfigEditor:

evdb::CfgEdit TestEditor List of all members.

Public Member Functions

 ConfigEditor (Config *config)
 A class to modify an existing configuration and publish changes.

virtual ~ConfigEditor ()
virtual int EditConfig (Config &cfg)
void Apply ()
void Edit ()
void Reset ()
void Cancel ()

Private Attributes

bool fNewConfig
 Have we created a config. during the edit?

ConfigfConfig
 The configuration to be edited.

ConfigfConfigCopy
 A copy of the original configuration.


Detailed Description

A class to modify an existing configuration and publish changes.

Clients who wish to edit configurations should follow this pattern:

[1] Derive from this class and implement the EditConfig method [2] Conduct the edit like this:

{ cfg::Config* cfg = ...; MyCfgConfigEditor ed(cfg); // Construct your editor ed.Edit(); // Do the edit }

Definition at line 27 of file ConfigEditor.h.


Constructor & Destructor Documentation

cfg::ConfigEditor::ConfigEditor Config config  ) 
 

A class to modify an existing configuration and publish changes.

Definition at line 17 of file ConfigEditor.cxx.

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

cfg::ConfigEditor::~ConfigEditor  )  [virtual]
 

Definition at line 25 of file ConfigEditor.cxx.

References fConfigCopy.

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


Member Function Documentation

void cfg::ConfigEditor::Apply  ) 
 

Reimplemented in evdb::CfgEdit.

Definition at line 72 of file ConfigEditor.cxx.

References cfg::Table::AdoptConfig(), fConfig, fNewConfig, cfg::Config::GetName(), cfg::Table::GetObservers(), cfg::Config::GetVersion(), cfg::Table::Instance(), and cfg::Table::ObsList.

Referenced by Edit().

00073 {
00074   //======================================================================
00075   // Apply the changes made to the configuration.
00076   //======================================================================
00077   cfg::Table& t = cfg::Table::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   cfg::Table::ObsList olist;
00085   t.GetObservers(fConfig->GetName(), fConfig->GetVersion(), olist);
00086   
00087   cfg::Table::ObsList::iterator    itr(olist.begin());
00088   cfg::Table::ObsList::iterator itrEnd(olist.end());
00089   for (; itr!=itrEnd; ++itr) try {(*itr)->Update(*fConfig); }
00090   catch (cfg::Exception e) {
00091     std::cout << " *-> " << fConfig->GetName() << "." 
00092               << fConfig->GetVersion() << " ";
00093     e.Print();
00094     exit(-1);
00095   }
00096 }

void cfg::ConfigEditor::Cancel  ) 
 

Reimplemented in evdb::CfgEdit.

Definition at line 113 of file ConfigEditor.cxx.

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

Referenced by Edit().

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

void cfg::ConfigEditor::Edit  ) 
 

Definition at line 35 of file ConfigEditor.cxx.

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

Referenced by evdb::CfgEdit::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 cfg::Config(fConfig->GetName(),"dummy","dummy");
00046   cfg::Config::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 cfg::ConfigEditor::EditConfig Config 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 evdb::CfgEdit.

Definition at line 61 of file ConfigEditor.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 cfg::ConfigEditor::Reset  ) 
 

Definition at line 100 of file ConfigEditor.cxx.

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

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


Member Data Documentation

Config* cfg::ConfigEditor::fConfig [private]
 

The configuration to be edited.

Definition at line 43 of file ConfigEditor.h.

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

Config* cfg::ConfigEditor::fConfigCopy [private]
 

A copy of the original configuration.

Definition at line 44 of file ConfigEditor.h.

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

bool cfg::ConfigEditor::fNewConfig [private]
 

Have we created a config. during the edit?

Definition at line 42 of file ConfigEditor.h.

Referenced by Apply(), and Cancel().


The documentation for this class was generated from the following files:
Generated on Fri Jul 25 02:05:52 2008 for NOvA Offline by doxygen 1.3.5