vtf-logo

control-device.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #ifndef NMWR_GB_CONTROLLER_H
00004 #define NMWR_GB_CONTROLLER_H
00005 
00006 
00013 #include "mutator.h"
00014 
00015 #include <iosfwd>
00016 #include <string>
00017 
00024 class control_device_impl : public controlable {
00025 public:
00026   virtual void update() = 0;
00027   virtual void add(const std::string&, Mutator*) = 0;
00028 
00029   // virtual void set(const std::string&, Mutator*) = 0;
00030   // virtual void remove(const std::string&, Mutator*) = 0;
00031 
00032   virtual void print_values(std::ostream&) const = 0;
00033   virtual void print_unrecognized(std::ostream&) const = 0;
00034 
00035   virtual void attach_to(std::istream& in) = 0;
00036   virtual control_device_impl* get_sub_device(const std::string& nm) = 0;
00037 
00038   virtual std::string name() const = 0;
00039   virtual ~control_device_impl() {}
00040 };
00041 
00049 class ControlDevice  {
00050 public:
00051   ControlDevice(control_device_impl* imp = 0) : impl(imp) {}
00052 
00053   void add(const std::string& nm,Mutator* value_ref);
00054   void add(const char*   nm,Mutator* value_ref);
00055   //  void remove(const std::string& name);
00056   //  void set(const std::string& name,Mutator* value_ref);
00057 
00058   void update();
00059   void print_values(std::ostream&) const;
00060   void print_unrecognized(std::ostream&) const;
00061   void attach_to(std::istream& in);
00062 
00063   void register_at(ControlDevice&, const std::string& prefix);
00064 
00065   std::string name() const;
00066 
00067   ControlDevice getSubDevice(const std::string& name);
00068   ControlDevice getSubDevice(const char*   name);
00069 private:
00070   control_device_impl* impl;
00071 };
00072 
00073 
00074 template<class T>
00075 inline void RegisterAt(ControlDevice& Ctrl, const std::string& name, T& t)
00076 { 
00077   TypedMutator<T>* p = new TypedMutator<T>(t);
00078   Ctrl.add(name, p); 
00079 }
00080 
00081 template<class T>
00082 inline void RegisterAt(ControlDevice& Ctrl, const char*   name, T& t)
00083 {  Ctrl.add(name, new TypedMutator<T>(t)); }
00084 
00085 
00086 
00087 // a simple ControlDevice that reads name-value-pairs from a file
00088 extern ControlDevice GetStreamDevice(std::istream* in,
00089     const std::string& name = "");
00090 //extern ControlDevice GetFileControlDevice(const std::string& filename,
00091 //                                          const std::string& name);
00092 extern ControlDevice GetFileControlDevice(const char*   filename,
00093     const std::string& name);
00094 
00095 extern ControlDevice GetCommandlineAndFileControlDevice(int argc, char* argv[],
00096     const std::string& filename, const std::string& name);
00097 
00098 
00099 extern ControlDevice GetDuplexControlDevice(std::istream& in2,
00100     const char* filename, const std::string& name);
00101 extern ControlDevice GetDuplexControlDevice(std::istream& in2,
00102     const std::string& filename, const std::string& name);
00103 #endif

Generated on Fri Aug 24 13:00:30 2007 for AMROC's Parameter IO - by  doxygen 1.4.7