OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
32template <class T> class IndexedChannel: public Channel {
33
34public:
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 nullptr.
66 virtual bool isSettable() const;
67
68private:
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
86template <class T>
87IndexedChannel<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
93template <class T>
95 Channel(),
96 itsObject(rhs.itsObject), getF(rhs.getF), setF(rhs.setF), bias(rhs.bias)
97{}
98
99
100template <class T>
102{}
103
104
105template <class T>
107 return new IndexedChannel(*this);
108}
109
110
111template <class T>
112bool IndexedChannel<T>::get(double &value) const {
113 value = (itsObject.*getF)(bias);
114 return true;
115}
116
117
118template <class T>
119bool 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
129template <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()
double(T::* getF)(int) const
virtual bool set(double)
Store into channel.
const IndexedChannel & operator=(const IndexedChannel &)
virtual bool isSettable() const
Test if settable.
virtual bool get(double &) const
Fetch from channel.
void(T::* setF)(int, double)