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


Main Page   Class Hierarchy   Compound List   File List  

read-parameters.C

Go to the documentation of this file.
00001 
00006 #if defined __KCC
00007 #include "map.h" 
00008 #include "list.h"
00009 #else
00010 #include "map" 
00011 #include "list"
00012 #endif
00013 #include <iostream.h>
00014 
00015 #include "IO/skip-comments.h"
00016 #include "IO/read-parameters.h"
00017 
00018 class string_table_1: public __STL_NSP(map)<string, Mutator*, __STL_NSP(less)<string> > {
00019 public:
00020   string_table_1() {}
00021 };
00022 
00023 class string_list : public __STL_NSP(list)<string> {
00024 public:
00025   string_list() {}
00026 };
00027 
00028 MutableVars::MutableVars()  
00029   : table(new string_table_1), 
00030     unrecognized(new string_list)  {}
00031 MutableVars::~MutableVars() { delete(table); delete(unrecognized);}
00032 
00033 void MutableVars::AddVariable(const string& name, Mutator* m)
00034   { (*table)[name]=m; }
00035 
00036 void MutableVars::AddVariable(const char*  name, Mutator* m)
00037   { (*table)[string(name)]=m; }
00038 
00039 
00040 // read values as long as there are any, 
00041 // unknown names are recorded in "unrecognized".
00042 
00043 // should be virtual members, shouldn't they?
00044 static inline char comment_start() { return '#';}
00045 static inline char comment_end()   { return '\n';}
00046 
00047 void MutableVars::ReadVariable(istream& is)
00048 {
00049   is >> ws;
00050   //  skip_comments_istream in(is,comment_start(),comment_end());
00051   if(is) {
00052     string s; 
00053     is >> s;
00054     
00055     if(table->find(s) != table->end()) {
00056       (*table)[s]->read(is);//.the_istream()); // hier nur istream-Funktionalitaet!
00057     }
00058     else if (s != "\n")
00059       unrecognized->push_back(s);
00060   }
00061 }
00062 
00063 void MutableVars::ReadValues(istream& is)
00064 { 
00065   while (is) { 
00066     skip_comment(is);
00067     ReadVariable(is); 
00068   }
00069 }
00070 
00071 void MutableVars::PrintValues(ostream& out, 
00072                               const string& pre, 
00073                               const string& sep) const
00074 {
00075   table_type::const_iterator item(table->begin());
00076   for(; item != table->end(); item++) {
00077     //    out << pre << (*item).first << sep;
00078     (*item).second->print(out, pre + (*item).first + sep);
00079     if( (*item).second->description() != "")
00080       out << "  " << comment_start() << " " 
00081           << (*item).second->description() << " " 
00082           << comment_end();
00083     out << "\n";
00084   }
00085 }
00086 
00087 bool MutableVars::HasUnrecognized() const { return (unrecognized->size() != 0);} 
00088 
00089 void MutableVars::PrintUnrecognized(ostream& out) const
00090 {
00091   string_list::const_iterator item(unrecognized->begin());
00092   for(; item != unrecognized->end(); ++item)
00093     out << *item << '\n';
00094 }


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



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