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

src/IO/read-parameters.C

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

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