OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
IndexedChannel.h
Go to the documentation of this file.
1#ifndef OPALX_IndexedChannel_HH
2#define OPALX_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// Class IndexedChannel
26// ------------------------------------------------------------------------
28// Template class IndirectChannel allows access to an indexed [b]double[/b]
29// data member of an object.
30
31template <class T>
32class IndexedChannel : public Channel {
33public:
35 // The constructed channel provides access to an array of an object
36 // of class [b]T[/b]. The channel keeps a reference to [b]object[/b],
37 // the pointers to member [b]getF[/b] and [b]setF[/b], and the index
38 // [b]index[/b].
39 // [p]
40 // Values set are transmitted via [tt] object.*setF(index,value)[/tt]
41 // and read via [tt]value = object.*getF(index)[/tt].
43 T& object, double (T::*getF)(int) const, void (T::*setF)(int, double), int index);
44
46 T& object, double (T::*getF)(int) const, void (T::*setF)(unsigned int, double),
47 int index);
48
50 virtual ~IndexedChannel();
51
53 virtual IndexedChannel* clone() const;
54
56 // If the channel can be read, set [b]value[/b] and return true,
57 // otherwise return false.
58 virtual bool get(double&) const;
59
61 // If the channel can be written, store [b]value[/b] into it and return true,
62 // otherwise return false.
63 virtual bool set(double);
64
66 // Return true, if the channel can receive values, i.e. if the [b]sefF[/b]
67 // pointer is not nullptr.
68 virtual bool isSettable() const;
69
70private:
71 // Not implemented.
74
75 // Reference to the object to be set.
77
78 // The get and set functions for the channel.
79 double (T::*getF)(int) const;
80 void (T::*setF)(int, double);
81
82 // The bias to be transmitted to the set() or get() method.
83 int bias;
84};
85
86template <class T>
88 T& object, double (T::*get)(int) const, void (T::*set)(int, double), int index)
89 : itsObject(object), getF(get), setF(set), bias(index) {}
90
91template <class T>
93 T& object, double (T::*get)(int) const, void (T::*set)(unsigned int, double), int index)
94 : itsObject(object), getF(get), setF(set), bias(index) {}
95
96template <class T>
98 : Channel(), itsObject(rhs.itsObject), getF(rhs.getF), setF(rhs.setF), bias(rhs.bias) {}
99
100template <class T>
102
103template <class T>
105 return new IndexedChannel(*this);
106}
107
108template <class T>
109bool IndexedChannel<T>::get(double& value) const {
110 value = (itsObject.*getF)(bias);
111 return true;
112}
113
114template <class T>
115bool IndexedChannel<T>::set(double value) {
116 if (setF != 0) {
117 (itsObject.*setF)(bias, value);
118 return true;
119 } else {
120 return false;
121 }
122}
123
124template <class T>
126 return (setF != 0);
127}
128
129#endif // OPALX_IndexedChannel_HH
double T
Definition OPALTypes.h:8
Abstract interface for read/write access to variable.
Definition Channel.h:30
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)