TDbiCfgDialog.cxx

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 // $Id: TDbiCfgDialog.cxx,v 1.1 2011/01/18 05:49:19 finch Exp $
00003 //
00004 // Default implementation for a text-based dialog with a user to fill
00005 // a TDbiRegistry object.
00006 //
00007 // messier@huhepl.harvard.edu
00008 ////////////////////////////////////////////////////////////////////////
00009 #include <iostream>
00010 #include "TDbiCfgDialog.hxx"
00011 
00012 //......................................................................
00013 
00014 TDbiCfgDialog::TDbiCfgDialog() :
00015   fCurrent(),
00016   fDefault(),
00017   fResult()
00018 { }
00019 
00020 //......................................................................
00021 
00022 TDbiCfgDialog::TDbiCfgDialog(const TDbiRegistry& cur, const TDbiRegistry& defl) :
00023   fCurrent(cur),
00024   fDefault(defl),
00025   fResult()
00026 { }
00027 
00028 //......................................................................
00029 
00030 TDbiCfgDialog::~TDbiCfgDialog() { }
00031 
00032 //......................................................................
00033 //======================================================================
00034 /// Copy the registry r to the set of values to display as current
00035 /// values
00036 //======================================================================
00037 void TDbiCfgDialog::SetCurrent(const TDbiRegistry& r) 
00038 {
00039 
00040   fCurrent.UnLockValues();
00041   fCurrent = r;
00042   fCurrent.LockValues();
00043 }
00044 
00045 //......................................................................
00046 //======================================================================
00047 /// Copy the registry r to the set of values to display as default values
00048 //======================================================================
00049 void TDbiCfgDialog::SetDefault(const TDbiRegistry& r)
00050 {
00051 
00052   fDefault.UnLockValues();
00053   fDefault = r;
00054   fCurrent.LockValues();
00055 }
00056 
00057 //......................................................................
00058 //======================================================================
00059 /// Conduct the dialog with the user to load new values into the
00060 /// registry. Return the registry stuffed with the new values.
00061 /// Can get one of either char, string, int or double.
00062 //======================================================================
00063 TDbiRegistry& TDbiCfgDialog::Query()
00064 {
00065 
00066   TDbiRegistry::TDbiRegistryKey rk = fCurrent.Key();
00067 
00068   // Setup result registry
00069   fResult = fCurrent;
00070   fResult.UnLockValues();
00071   
00072   const char* k; // Key name
00073   while ( (k=rk()) ) {
00074     // bool      b; // Temp. bool value
00075     char            c; // Temp. char value
00076     const char*     s; // Temp. string value
00077     int             i; // Temp. int value
00078     double          d; // Temp. double value
00079     TDbiRegistry        r; // Temp. TDbiRegistry value
00080 
00081     // Use the 'current' registry to divine the types of junk...
00082     // Currently there's no good way to do this and TDbiRegistry spits
00083     // warnings at you for even trying...
00084     bool isBool   = false;
00085     // bool isBool   = fDefault.Get(k, b);
00086     bool isChar   = fDefault.Get(k, c);
00087     bool isString = fDefault.Get(k, s);
00088     bool isInt    = fDefault.Get(k, i);
00089     bool isDouble = fDefault.Get(k, d);
00090     bool isTDbiRegistry = false;
00091     // bool isTDbiRegistry = fCurrent.Get(k, r);
00092 
00093 #define PROMPT(t,c,d) \
00094 std::cout << " "<<t<<" "<<k<<" = ["<<d<<"] "<<c<<" =? ";
00095     // OK, now get the user's input. One "if" per type...
00096     if (isBool) {
00097       // bool b1, b_in;
00098       // fDefault.Get(k, b1);
00099       // PROMPT("bool",b,b1);
00100       // std::cin >> b_in;
00101       // fResult.Set(k, d_in);
00102     }
00103     else if (isChar) {
00104       char c1, c_in;
00105       fDefault.Get(k, c1);
00106       PROMPT("char",c,c1);
00107       std::cin >> c_in;
00108       fResult.Set(k, c_in);
00109     }
00110     else if (isString) {
00111       const char* s1;
00112       std::string s_in;
00113       fDefault.Get(k, s1);
00114       PROMPT("string",s,s1);
00115       std::cin >> s_in;
00116       // This is OK, TDbiRegistry allocates space and stores a copy
00117       // of the string, not just the pointer
00118       fResult.Set(k, s_in.c_str());
00119     }
00120     else if (isInt) {
00121       int i1, i_in;
00122       fDefault.Get(k, i1);
00123       PROMPT("int",i,i1);
00124       std::cin >> i_in;
00125       fResult.Set(k, i_in);
00126     }
00127     else if (isDouble) {
00128       double d1, d_in;
00129       fDefault.Get(k, d1);
00130       PROMPT("double",d,d1);
00131       std::cin >> d_in;
00132       fResult.Set(k, d_in);
00133     }
00134     else if (isTDbiRegistry) {
00135       // TDbiRegistry r1, r_in;
00136       // std::string rins;
00137       // fDefault.Get(k, r1);
00138       // PROMPT("TDbiRegistry",r,r1);
00139       // std::cin >> r_ins;
00140       // r_in << r_ins;
00141       // fResult.Set(k, r_in);
00142     }
00143   } // loop over keys
00144   return fResult;
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////////

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1