00001 // Setter.h 00002 // 00003 // Virtual base class for classes that receive a value, maybe transform it and do something with it 00004 // 00005 /// \author Mike McCauley (mikem@open.com.au) 00006 /// 00007 // Copyright (C) 2010 Mike McCauley 00008 // $Id: Setter.h,v 1.3 2010/06/28 00:56:10 mikem Exp $ 00009 00010 #ifndef Setter_h 00011 #define Setter_h 00012 00013 ///////////////////////////////////////////////////////////////////// 00014 /// \class Setter Setter.h <Setter.h> 00015 /// \brief Virtual base class for classes that receive a value, maybe transform it and then 00016 /// do something with it 00017 /// 00018 /// Setters (ie different subclasses of Setter) are designed to be chained together. 00019 /// Each Setter in a chain transforms its input value in some way and then maybe passes it on to 00020 /// its output Setter. 00021 /// Setters can be designed to do almost any transformation with a number, including 00022 /// changing it, sending it to some device, using the value to set a physical output etc. 00023 /// Each setter can accept as input an int (ie a 16 bit signed number) although some Setters 00024 /// may be more constrained as to which value ranges make physical sense. 00025 class Setter 00026 { 00027 public: 00028 /// Constructor. 00029 Setter(); 00030 00031 /// Constructor with setting the target 00032 Setter(Setter* target); 00033 00034 /// This is where incoming values are set. 00035 // This default implementation merely passes its value to the output 00036 /// \param[in] value The input value 00037 virtual void input(int value); 00038 00039 /// Connects this Setter to a downstream Setter 00040 /// \param[in] target Pointer to a sublass of Setter, whose input() function will be called 00041 /// when a new value is available from this Setter. 00042 virtual void setTarget(Setter* target); 00043 00044 /// Called when the source of input data is lost, and the Setter is required to fail in a safe way. 00045 /// Subclasses can override. 00046 /// Default is to send to next Setter in the chain. 00047 virtual void failsafe(); 00048 00049 /// Sets the failsafeValue 00050 void setFailsafeValue(int failsafeValue); 00051 00052 /// Returns the most recently set failsafe value. 00053 /// Base class does not use this 00054 int failsafeValue(); 00055 00056 00057 protected: 00058 /// This is the instance of Setter that will be given the transfotmed output value 00059 Setter* _target; 00060 00061 /// This is the failsafe value, which some setters use to set the output when 00062 /// a failsafe call is made 00063 int _failsafeValue; 00064 00065 private: 00066 }; 00067 00068 #endif