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

testCfgTable.cc

Go to the documentation of this file.
00001 
00002 // $Id: testCfgTable.cc,v 1.1 2007/02/09 05:38:28 fmwk Exp $
00003 //
00005 //
00006 // messier@indiana.edu
00008 #include "Config/Table.h"
00009 #include "Config/Config.h"
00010 #include "Config/Observer.h"
00011 
00012 class TestObs : public cfg::Observer 
00013 {
00014 public:
00015   TestObs(const char* name, const char* config, const char* version) 
00016   {
00017     fName = name;
00018     this->SetWatch(config,version);
00019   }
00020   //....................................................................
00021   void Update(const cfg::Config& c) 
00022   {
00023     std::cout << 
00024       "TestObs: " << fName <<
00025       " received update from " << c.GetName() << 
00026       "." << c.GetVersion() << std::endl;
00027   }
00028   std::string fName;
00029 };
00030 
00031 int main(void) 
00032 {
00033   cfg::Table& cfgTable = cfg::Table::Instance();
00034 
00035   cfg::Config* c1 = new cfg::Config("ConfigA","default", __FILE__);
00036   cfg::Config* c2 = new cfg::Config("ConfigA","test",    __FILE__);
00037   cfg::Config* c3 = new cfg::Config("ConfigB","default", __FILE__);
00038   cfg::Config* c4 = new cfg::Config("ConfigB","test",    __FILE__);
00039   
00040   cfgTable.AdoptConfig(c1);
00041   cfgTable.AdoptConfig(c2);
00042   cfgTable.AdoptConfig(c3);
00043   cfgTable.AdoptConfig(c4);
00044   cfgTable.Print();
00045 
00046   // Two clients watching the same configuration
00047   TestObs o1("o1","ConfigA","default");
00048   TestObs o2("o2","ConfigA","default");
00049 
00050   // One client watching two configurations
00051   TestObs o3 ("o3","ConfigA","test");
00052   o3.SetWatch("ConfigB","test");
00053   
00054   // Client changes version of configuration
00055   TestObs o4("o4","ConfigB","default");
00056   o4.SetWatch("ConfigB","test");
00057 
00058   std::cout << "Table w/ observers added\n";
00059   cfgTable.Print();
00060 
00061   std::cout << "Table w/ observers removed\n";
00062   cfgTable.RemoveWatch("ConfigA",&o1);
00063   cfgTable.RemoveAllWatches(&o2);
00064   cfgTable.Print();
00065 }
00066 
00068 

Generated on Wed Oct 15 02:35:27 2008 for NOvA Offline by  doxygen 1.3.9.1