OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
IndexedChannel.h
Go to the documentation of this file.
1 #ifndef CLASSIC_IndexedChannel_HH
2 #define CLASSIC_IndexedChannel_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: IndexedChannel.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: IndexedChannel
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 IndexedChannel
27 // ------------------------------------------------------------------------
29 // Template class IndirectChannel allows access to an indexed [b]double[/b]
30 // data member of an object.
31 
32 template <class T> class IndexedChannel: public Channel {
33 
34 public:
35 
37  // The constructed channel provides access to an array of an object
38  // of class [b]T[/b]. The channel keeps a reference to [b]object[/b],
39  // the pointers to member [b]getF[/b] and [b]setF[/b], and the index
40  // [b]index[/b].
41  // [p]
42  // Values set are transmitted via [tt] object.*setF(index,value)[/tt]
43  // and read via [tt]value = object.*getF(index)[/tt].
44  IndexedChannel(T &object, double(T::*getF)(int) const,
45  void (T::*setF)(int, double), int index);
46 
48  virtual ~IndexedChannel();
49 
51  virtual IndexedChannel *clone() const;
52 
54  // If the channel can be read, set [b]value[/b] and return true,
55  // otherwise return false.
56  virtual bool get(double &) const;
57 
59  // If the channel can be written, store [b]value[/b] into it and return true,
60  // otherwise return false.
61  virtual bool set(double);
62 
64  // Return true, if the channel can receive values, i.e. if the [b]sefF[/b]
65  // pointer is not NULL.
66  virtual bool isSettable() const;
67 
68 private:
69 
70  // Not implemented.
73 
74  // Reference to the object to be set.
76 
77  // The get and set functions for the channel.
78  double(T::*getF)(int) const;
79  void (T::*setF)(int, double);
80 
81  // The bias to be transmitted to the set() or get() method.
82  int bias;
83 };
84 
85 
86 template <class T>
87 IndexedChannel<T>::IndexedChannel(T &object, double(T::*get)(int) const,
88  void (T::*set)(int, double), int index):
89  itsObject(object), getF(get), setF(set), bias(index)
90 {}
91 
92 
93 template <class T>
95  Channel(),
96  itsObject(rhs.itsObject), getF(rhs.getF), setF(rhs.setF), bias(rhs.bias)
97 {}
98 
99 
100 template <class T>
102 {}
103 
104 
105 template <class T>
107  return new IndexedChannel(*this);
108 }
109 
110 
111 template <class T>
112 bool IndexedChannel<T>::get(double &value) const {
113  value = (itsObject.*getF)(bias);
114  return true;
115 }
116 
117 
118 template <class T>
119 bool IndexedChannel<T>::set(double value) {
120  if(setF != 0) {
121  (itsObject.*setF)(bias, value);
122  return true;
123  } else {
124  return false;
125  }
126 }
127 
128 
129 template <class T>
131  return (setF != 0);
132 }
133 
134 #endif // CLASSIC_IndexedChannel_HH
Abstract interface for read/write access to variable.
Definition: Channel.h:32
Access to an indexed [b]double[/b] data member.
virtual IndexedChannel * clone() const
Duplicate the channel.
virtual ~IndexedChannel()
const IndexedChannel & operator=(const IndexedChannel &)
double(T::* getF)(int) const
virtual bool set(double)
Store into channel.
virtual bool isSettable() const
Test if settable.
virtual bool get(double &) const
Fetch from channel.
void(T::* setF)(int, double)