00001
00002
00003 #ifndef NMWR_GB_ISTREAM_CONTROL_DEVICE_H
00004 #define NMWR_GB_ISTREAM_CONTROL_DEVICE_H
00005
00006
00012 #include "control-device.h"
00013 #include "read-parameters.h"
00014
00015 #include <iosfwd>
00016 #include <string>
00017
00018 class istream_control_device_impl : public control_device_impl {
00019 typedef istream_control_device_impl self;
00020 public:
00021 istream_control_device_impl(std::istream* i, const std::string& nm,
00022 const std::string& ind = "")
00023 : in(i), name_(nm), indent_(ind) {}
00024
00025 virtual ~istream_control_device_impl() {}
00026
00027 istream_control_device_impl* get_sub_device(const std::string& nm)
00028 { return new istream_control_device_impl(in,nm, indent_+" "); }
00029
00030 virtual std::string name() const { return name_ ;}
00031
00032 virtual void update() { MV.ReadValues(*in);}
00033
00034 virtual void add(const std::string& name,Mutator* value)
00035 { MV.AddVariable(name,value);}
00036
00037 virtual void register_at(ControlDevice& Ctrl) { register_at(Ctrl,"");}
00038 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00039 Ctrl.add( (prefix == "" ? prefix : prefix + "-") +name(),
00040 GetMutator(*this));
00041 }
00042
00043 virtual void attach_to(std::istream& in_new) { in = &in_new;}
00044 virtual void print_values(std::ostream& out) const { MV.PrintValues(out);}
00045 virtual void print_values(std::ostream& out, const std::string& ind) const
00046 { MV.PrintValues(out, ind, " ");}
00047
00048 virtual void read(std::istream& in);
00049 virtual void print(std::ostream& out) const;
00050 virtual void print_unrecognized(std::ostream& out) const;
00051
00052 friend std::istream& operator>>(std::istream& in, self& rhs)
00053 { rhs.read(in); return in;}
00054 friend std::ostream& operator<<(std::ostream& out, const self& rhs)
00055 { rhs.print(out); return out;}
00056
00057 protected:
00058 std::istream* in;
00059 std::string name_;
00060 std::string indent_;
00061 MutableVars MV;
00062 };
00063
00064
00065
00066 #endif