OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
IndirectChannel.h
Go to the documentation of this file.
1 #ifndef CLASSIC_IndirectChannel_HH
2 #define CLASSIC_IndirectChannel_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: IndirectChannel.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: IndirectChannel
13 //
14 // ------------------------------------------------------------------------
15 // Class category: Channels
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2000/03/27 09:32:35 $
19 // $Author: fci $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include "Channels/Channel.h"
24 
25 
26 // Class IndirectChannel
27 // ------------------------------------------------------------------------
29 // Template class IndirectChannel allows access to a [b]double[/b] data
30 // member of an object.
31 
32 template <class T> class IndirectChannel: public Channel {
33 
34 public:
35 
37  // The constructed channel provides access to a member of an object
38  // of class [b]T[/b]. The channel keeps a reference to [b]object[/b]
39  // and the pointers to member [b]getF[/b] and [b]setF[/b].
40  // Values set are transmitted via object.*setF(value)
41  // and read via value = object.*getF().
42  IndirectChannel(T &object, double(T::*getF)() const,
43  void (T::*setF)(double));
44 
46  virtual ~IndirectChannel();
47 
49  virtual IndirectChannel *clone() const;
50 
52  // If the channel can be read, set [b]value[/b] and return true,
53  // otherwise return false.
54  virtual bool get(double &) const;
55 
57  // If the channel can be written,
58  // store [b]value[/b] into it and return true,
59  // otherwise return false.
60  virtual bool set(double);
61 
63  // Return true, if the channel can be written, i.e. if the set
64  // method pointer is not NULL
65  virtual bool isSettable() const;
66 
67 private:
68 
69  // Not implemented.
72 
73  // Reference to the object to be set.
75 
76  // The get and set functions for the channel.
77  double(T::*getF)() const;
78  void (T::*setF)(double);
79 };
80 
81 
82 template <class T>
83 IndirectChannel<T>::IndirectChannel(T &object, double(T::*get)() const,
84  void (T::*set)(double)):
85  itsObject(object), getF(get), setF(set)
86 {}
87 
88 
89 template <class T>
91  Channel(),
92  itsObject(rhs.itsObject), getF(rhs.getF), setF(rhs.setF)
93 {}
94 
95 
96 template <class T>
98 {}
99 
100 
101 template <class T>
103  return new IndirectChannel(*this);
104 }
105 
106 
107 template <class T>
108 bool IndirectChannel<T>::get(double &value) const {
109  value = (itsObject.*getF)();
110  return true;
111 }
112 
113 
114 template <class T>
115 bool IndirectChannel<T>::set(double value) {
116  if(setF != 0) {
117  (itsObject.*setF)(value);
118  return true;
119  } else {
120  return false;
121  }
122 }
123 
124 
125 template <class T> inline
127  return (setF != 0);
128 }
129 
130 #endif // CLASSIC_IndirectChannel_HH
const IndirectChannel & operator=(const IndirectChannel &)
Definition: rbendmap.h:8
double(T::* getF)() const
virtual IndirectChannel * clone() const
Duplicate the channel.
void(T::* setF)(double)
virtual bool isSettable() const
Test if settable.
virtual bool get(double &) const
Fetch from channel.
virtual bool set(double)
Store into channel.
virtual ~IndirectChannel()
Abstract interface for read/write access to variable.
Definition: Channel.h:32
Access to a [b]double[/b] data member.