AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

control-device.C

Go to the documentation of this file.
00001 
00007 #if defined __KCC
00008 #include "map.h" 
00009 #else
00010 #include "map" 
00011 #endif
00012 #include <fstream.h>
00013 #include "string_CompConf.h"
00014 
00015 /* #include "Iso-std/sstream" */
00016 #include <strstream.h> 
00017 
00018 #include "IO/control-device.h"
00019 #include "IO/istream-control-device.h"
00020 #include "IO/skip-comments.h"
00021 
00022 string Mutator::description() const { return string("");}
00023 
00024 
00025 
00026 void ControlDevice::update() { impl->update(); print_unrecognized(cerr);}
00027 
00028 void ControlDevice::print_values(ostream& out) const { impl->print_values(out);}
00029 void ControlDevice::print_unrecognized(ostream& out) const { impl->print_unrecognized(out);}
00030 
00031 void ControlDevice::attach_to(istream& in) { impl->attach_to(in);}
00032 
00033 void ControlDevice::add(const string& name,Mutator* value_ref) 
00034 { impl->add(name,value_ref);}
00035 
00036 void ControlDevice::add(const char*   nm,Mutator* value_ref)
00037 { add(string(nm),value_ref);}
00038 
00039 void ControlDevice::register_at(ControlDevice& Ctrl, const string& prefix)
00040 { impl->register_at(Ctrl,prefix);}
00041 
00042 string ControlDevice::name() const { return impl->name();}
00043 
00044 ControlDevice ControlDevice::getSubDevice(const string& nm) 
00045 { 
00046   ControlDevice sub(impl->get_sub_device(nm));
00047   sub.register_at(*this,"");
00048   return sub;
00049 }
00050 
00051 ControlDevice ControlDevice::getSubDevice(const char*   name) 
00052 { return getSubDevice(string(name));}
00053 
00054 
00055 
00056 
00057 void istream_control_device_impl::read(istream& in) {
00058   char c;
00059   in >> c;
00060   if( c == '{') {
00061     (in >> ws).get(c);
00062     while( c != '}') {
00063       in.putback(c);
00064     
00065       skip_comment(in);
00066       (in >> ws).get(c); 
00067       if( c== '}') return;
00068       in.putback(c);
00069 
00070       MV.ReadVariable(in);
00071       (in >> ws).get(c); 
00072      }
00073   }
00074 }
00075 
00076 void istream_control_device_impl::print(ostream& out) const {
00077   out <<  '\n' << indent_ << "{\n";
00078   print_values(out, indent_);
00079   out << indent_ << "}";
00080 }
00081 
00082 void istream_control_device_impl::print_unrecognized(ostream& out) const {
00083   if(MV.HasUnrecognized()) {
00084     out << "WARNING: Unrecognized Values in ControlDevice " << name() << ":\n";
00085     MV.PrintUnrecognized(out);
00086     out << "END Unrecognized Values in ControlDevice " << name() << '\n';
00087   }
00088 }
00089 
00090 
00091 class multi_istream_control_device : public istream_control_device_impl {
00092   typedef istream_control_device_impl base;
00093 public:
00094   multi_istream_control_device(istream* i1, istream* i2,
00095                                const string& nm, const string& ind = "")
00096     : base(i1,nm,ind), in2(i2)  {}
00097   virtual void update() {
00098     base::update();  
00099     MV.ReadValues(*in2);
00100   }
00101 private:
00102  istream* in2;
00103 };
00104 
00105 
00106 ControlDevice GetStreamDevice(istream* in, const string& name)
00107 { return ControlDevice( new istream_control_device_impl(in,name));}
00108 
00109 ControlDevice GetFileControlDevice(const string& filename, const string& name) 
00110 { return GetFileControlDevice(filename.c_str(),name);} 
00111 
00112 ControlDevice GetFileControlDevice(const char* filename, const string& name) {
00113  ifstream * infile = new ifstream(filename);
00114  return ControlDevice(new istream_control_device_impl(infile, name));
00115 }
00116 
00117 
00118 #include "IO/command-line.h"
00119 
00120 
00121 ControlDevice GetDuplexControlDevice(istream& in2,
00122                                      const char* filename, const string& name) {
00123  ifstream * in1 = new ifstream(filename);
00124   return ControlDevice(new multi_istream_control_device(in1,&in2,name));
00125 }
00126 
00127 ControlDevice GetDuplexControlDevice(istream* in2,
00128                                      const char* filename, const string& name) {
00129  ifstream * in1 = new ifstream(filename);
00130   return ControlDevice(new multi_istream_control_device(in1,in2,name));
00131 }
00132 
00133 ControlDevice GetDuplexControlDevice(istream& in2,
00134                                      const string& filename, const string& name) {
00135   return GetDuplexControlDevice(in2,filename.c_str(),name);
00136 }
00137 
00138 ControlDevice GetCommandlineAndFileControlDevice(int argc, char* argv[],
00139                                                  const string& filename, 
00140                                                  const string& name) 
00141 {
00142   Commandline cmd(argc,argv);
00143   //  istringstream* in = new istringstream(cmd.get().str());
00144   istrstream* in = new istrstream(cmd.c_str());
00145   return GetDuplexControlDevice(in,
00146                                 filename.c_str(),
00147                                 name);
00148 }


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04