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

JobCDialog.cxx

Go to the documentation of this file.
00001 
00002 // $Id: JobCDialog.cxx,v 1.3 2002/08/22 19:23:14 rhatcher 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 "JobControl/JobCDialog.h"
00011 
00012 //......................................................................
00013 
00014 JobCDialog::JobCDialog() :
00015   fCurrent(),
00016   fDefault(),
00017   fResult()
00018 { }
00019 
00020 //......................................................................
00021 
00022 JobCDialog::JobCDialog(const Registry& cur, const Registry& defl) :
00023   fCurrent(cur),
00024   fDefault(defl),
00025   fResult()
00026 { }
00027 
00028 //......................................................................
00029 
00030 JobCDialog::~JobCDialog() { }
00031 
00032 //......................................................................
00033 
00034 void JobCDialog::SetCurrent(const Registry& r) 
00035 {
00036   fCurrent.UnLockValues();
00037   fCurrent = r;
00038 }
00039 
00040 //......................................................................
00041 
00042 void JobCDialog::SetDefault(const Registry& r)
00043 {
00044   fDefault.UnLockValues();
00045   fDefault = r;
00046 }
00047 
00048 //......................................................................
00049 
00050 Registry& JobCDialog::Querry()
00051 {
00052   Registry::RegistryKey rk = fCurrent.Key();
00053 
00054   // Reset result registry
00055   fResult = fCurrent;
00056   fResult.UnLockValues(); // Random capital 'L' in middle of word...
00057   
00058   const char* k;
00059   while ( (k=rk()) ) {
00060     char        c;
00061     const char* s;
00062     int         i;
00063     double      d;
00064     Registry    r;
00065 
00066     // Use the 'current' registry to divine the types of junk...
00067     // Currently there's no good way to do this and Registry spits
00068     // warnings at you for even trying...
00069     bool isChar   = fCurrent.Get(k, c);
00070     bool isString = fCurrent.Get(k, s);
00071     bool isInt    = fCurrent.Get(k, i);
00072     bool isDouble = fCurrent.Get(k, d);
00073     // bool isRegistry = fCurrent.Get(k, r);
00074     
00075     // OK, now get the user's input. One "if" per type...
00076 #define PROMPT(t,c,d) \
00077     std::cout << " "<<t<<" "<<k<<" = ["<<d<<"] "<<c<<" =? ";
00078     if (isChar) {
00079       char c1;
00080       char c_in;
00081       fDefault.Get(k, c1);
00082       PROMPT("char",c,c1);
00083       std::cin >> c_in;
00084       fResult.Set(k, c_in);
00085     }
00086     else if (isString) {
00087       const char* s1;
00088       std::string s_in;
00089       fDefault.Get(k, s1);
00090       PROMPT("string",s,s1);
00091       std::cin >> s_in;
00092       // This is OK, Registry allocates space and stores a copy
00093       // of the string, not just the pointer
00094       fResult.Set(k, s_in.c_str());
00095     }
00096     else if (isInt) {
00097       int i1;
00098       int i_in;
00099       fDefault.Get(k, i1);
00100       PROMPT("int",i,i1);
00101       std::cin >> i_in;
00102       fResult.Set(k, i_in);
00103     }
00104     else if (isDouble) {
00105       double d1;
00106       double d_in;
00107       fDefault.Get(k, d1);
00108       PROMPT("double",d,d1);
00109       std::cin >> d_in;
00110       fResult.Set(k, d_in);
00111     }
00112 #ifdef REGISTRY_CAN_BE_MADE_FROM_STRING
00113     else if (isRegistry) {
00114       Registry r1;
00115       Registry r_in;
00116       std::string rins;
00117       fDefault.Get(k, r1);
00118       PROMPT("Registry",r,r1);
00119       std::cin >> r_ins;
00120       r_in << r_ins;
00121       fResult.Set(k, r_in);
00122     }
00123 #endif
00124   } // loop over keys
00125   return fResult;
00126 }

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