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

CfgDialog.cxx

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

Generated on Mon Feb 15 11:06:31 2010 for loon by  doxygen 1.3.9.1