Go to Overview over all GrAL packages.
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

demo/ex1.C

Go to the documentation of this file.
00001 
00002 // $LICENSE
00003 
00004 #include <iostream.h>
00005 #include <string>
00006 
00007 #include "IO/mutator.h"  // only needed for "special" mutators.
00008 #include "IO/control-device.h"
00009 
00010 //----------------------------------------------------------------
00011 //
00012 // Demonstration for nested parameter control via parameter 
00013 // file ("ctrl.in" in this example) and command line.
00014 //
00015 // try something like 
00016 // $ ./ex1.exe   n 77  sub1 { sub1.1 { name1 blabla } x -0.888 }
00017 // on the commandline to see what is happening.
00018 // To see error handling, try:
00019 // $ ./ex1.exe   this is rubbish   n 77  sub1 { sub1.1 { name1 blabla } x -0.888 }
00020 //
00021 //----------------------------------------------------------------
00022 
00023 int main(int argc, char* argv[]) {
00024 
00025   //  read variables from file only: uncomment the following line
00026   //  ControlDevice Ctrl = GetFileControlDevice("ctrl.in","main");
00027  
00028   // read variables from file and then from commandline, 
00029   // such that command-line settings take precedence.
00030   ControlDevice Ctrl = GetCommandlineAndFileControlDevice(argc,argv,"ex1.in","main");
00031 
00032   int n  = 5;
00033   int m = 7;
00034   double x = 1.0, y = 2.0;
00035   std::string name1_1 = "1_1", name1_2 = "1_2";
00036   std::string name2_1 = "2_1", name2_2 = "2_2";
00037 
00038   bool flag = true;
00039   bool print_variables = true;
00040  
00041   Ctrl.add("print",GetCommentedMutator(print_variables,
00042                                        "<bool> : print values of variables?"));
00043   Ctrl.add("n", GetMutator(n));
00044   Ctrl.add("n", GetMutator(m)); // m will be altered, not n!
00045 
00046   // create a nested subdevice of level 1
00047   ControlDevice Ctrl1 = Ctrl.getSubDevice("sub1");
00048   Ctrl1.add("flag-on",  GetTrueOnReadMutator(flag));
00049   Ctrl1.add("flag-off", GetFalseOnReadMutator(flag));
00050   Ctrl1.add("x", GetMutator(x));
00051   Ctrl1.add("y", GetMutator(y));
00052 
00053   // create a nested subdevice of level 2
00054   ControlDevice Ctrl1_1 = Ctrl1.getSubDevice("sub1.1");
00055   Ctrl1_1.add("name1", GetMutator(name1_1));
00056   Ctrl1_1.add("name2", GetMutator(name1_2));
00057 
00058   // create another nested subdevice of level 2
00059   ControlDevice Ctrl1_2 = Ctrl1.getSubDevice("sub1.2");
00060   Ctrl1_2.add("name1", GetMutator(name2_1));
00061   Ctrl1_2.add("name2", GetMutator(name2_2));
00062 
00063 
00064   //---------------------------------------------------------
00065 
00066   // set the parameters registered so long.
00067   // this warns about unrecognized strings in the input.
00068   Ctrl.update();
00069 
00070   // show all name-value pairs of Ctrl 
00071   // (not only those that have been read by update())
00072   Ctrl.print_values(cout);
00073 
00074   // Print warning if any strings did not correspond to valid name-value pairs.
00075   // This is done also by Ctrl.update(), so its superflous in principle.
00076   Ctrl.print_unrecognized(cout); 
00077 
00078 
00079   if(print_variables) {
00080     cerr << "\n"
00081          << "Values of the variables:\n"
00082          << "n: " << n << '\n'
00083          << "m: " << m << '\n'
00084          << "x: " << x << '\n'
00085          << "y: " << y << '\n'
00086          << "flag: " << flag << '\n'
00087          << "name1_1: " << name1_1 << '\n' 
00088          << "name1_2: " << name1_2 << '\n' 
00089          << "name2_1: " << name2_1 << '\n' 
00090          << "name2_2: " << name2_2 << '\n';
00091   }
00092 }

Copyright (c) Guntram Berti 1997-2002. See the GrAL Homepage for up-to-date information.

Generated at Tue Feb 26 15:57:06 2002 for External control by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000