00001
00002
00003
00004 #include "IO/istream-control-device.h"
00005 #include "IO/skip-comments.h"
00006
00007
00008 istream_control_device_impl::istream_control_device_impl(std::istream* i,
00009 std::string const& nm,
00010 std::string const& ind )
00011 : in(i), name_(nm), indent_(ind) {}
00012
00013 std::string istream_control_device_impl::name() const { return name_ ;}
00014
00015 void istream_control_device_impl::update() { MV.ReadValues(*in);}
00016
00017 void istream_control_device_impl::add(const std::string& name,Mutator* value)
00018 { MV.AddVariable(name,value);}
00019
00020 void istream_control_device_impl::register_at(ControlDevice& Ctrl) { register_at(Ctrl,"");}
00021
00022 void istream_control_device_impl::register_at(ControlDevice& Ctrl,
00023 const std::string& prefix) {
00024 Ctrl.add( ( (prefix == "") || (name() == "") ? prefix : prefix + "-") +name(),
00025 GetMutator(*this));
00026 }
00027
00028 void istream_control_device_impl::attach_to(std::istream& in_new) { in = &in_new;}
00029
00030 void istream_control_device_impl::print_values(std::ostream& out) const { MV.PrintValues(out);}
00031
00032 void istream_control_device_impl::print_values(std::ostream& out,
00033 std::string const& ind) const
00034 { MV.PrintValues(out, ind, " ");}
00035
00036
00037
00038
00039
00040 control_device_impl*
00041 istream_control_device_impl::get_sub_device(std::string const& nm)
00042 {
00043 self* sub = new istream_control_device_impl(in,nm, indent_+" ");
00044 add(nm,GetMutator(*sub));
00045 sub_devices_.push_back(sub);
00046 return sub;
00047 }
00048
00049 void istream_control_device_impl::read(std::istream& in) {
00050 skip_comment(in);
00051 char c;
00052 in >> c;
00053 REQUIRE( (c == '{'),"control-device " << name() << "no leading {!\n",1);
00054
00055 (in >> ws).get(c);
00056 while( c != '}') {
00057 in.putback(c);
00058
00059 skip_comment(in);
00060 (in >> ws).get(c);
00061 if( c== '}') return;
00062 in.putback(c);
00063
00064 MV.ReadVariable(in);
00065 (in >> ws).get(c);
00066 }
00067
00068 print_unrecognized(cerr);
00069
00070 }
00071
00072 void istream_control_device_impl::print(std::ostream& out) const {
00073 out << '\n' << indent_ << "{\n";
00074 print_values(out, indent_);
00075 out << indent_ << "}";
00076 }
00077
00078 void istream_control_device_impl::print_unrecognized(std::ostream& out) const
00079 { print_unrecognized(out,"");}
00080
00081 void istream_control_device_impl::print_unrecognized(std::ostream& out,
00082 std::string const& prefix) const
00083 {
00084 std::string nm = ( prefix == "" ? name() : prefix + "::" + name());
00085 if(MV.HasUnrecognized()) {
00086 out << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"
00087 << "WARNING: Unrecognized Values in ControlDevice " << nm << ":\n";
00088 MV.PrintUnrecognized(out);
00089 out << "END Unrecognized Values in ControlDevice " << nm << '\n';
00090 }
00091 std::list<self*>::const_iterator subs;
00092 for(subs = sub_devices_.begin(); subs != sub_devices_.end(); ++subs)
00093 (*subs)->print_unrecognized(out,nm);
00094 }