OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
IndirectChannel.h
Go to the documentation of this file.
1#ifndef OPALX_IndirectChannel_HH
2#define OPALX_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// Class IndirectChannel
26// ------------------------------------------------------------------------
28// Template class IndirectChannel allows access to a [b]double[/b] data
29// member of an object.
30
31template <class T>
32class IndirectChannel : public Channel {
33public:
35 // The constructed channel provides access to a member of an object
36 // of class [b]T[/b]. The channel keeps a reference to [b]object[/b]
37 // and the pointers to member [b]getF[/b] and [b]setF[/b].
38 // Values set are transmitted via object.*setF(value)
39 // and read via value = object.*getF().
40 IndirectChannel(T& object, double (T::*getF)() const, void (T::*setF)(double));
41
43 virtual ~IndirectChannel();
44
46 virtual IndirectChannel* clone() const;
47
49 // If the channel can be read, set [b]value[/b] and return true,
50 // otherwise return false.
51 virtual bool get(double&) const;
52
54 // If the channel can be written,
55 // store [b]value[/b] into it and return true,
56 // otherwise return false.
57 virtual bool set(double);
58
60 // Return true, if the channel can be written, i.e. if the set
61 // method pointer is not nullptr
62 virtual bool isSettable() const;
63
64private:
65 // Not implemented.
68
69 // Reference to the object to be set.
71
72 // The get and set functions for the channel.
73 double (T::*getF)() const;
74 void (T::*setF)(double);
75};
76
77template <class T>
78IndirectChannel<T>::IndirectChannel(T& object, double (T::*get)() const, void (T::*set)(double))
79 : itsObject(object), getF(get), setF(set) {}
80
81template <class T>
83 : Channel(), itsObject(rhs.itsObject), getF(rhs.getF), setF(rhs.setF) {}
84
85template <class T>
87
88template <class T>
92
93template <class T>
94bool IndirectChannel<T>::get(double& value) const {
95 value = (itsObject.*getF)();
96 return true;
97}
98
99template <class T>
100bool IndirectChannel<T>::set(double value) {
101 if (setF != 0) {
102 (itsObject.*setF)(value);
103 return true;
104 } else {
105 return false;
106 }
107}
108
109template <class T>
111 return (setF != 0);
112}
113
114#endif // OPALX_IndirectChannel_HH
double T
Definition OPALTypes.h:8
Abstract interface for read/write access to variable.
Definition Channel.h:30
Access to a [b]double[/b] data member.
virtual bool get(double &) const
Fetch from channel.
virtual bool isSettable() const
Test if settable.
virtual IndirectChannel * clone() const
Duplicate the channel.
void(T::* setF)(double)
double(T::* getF)() const
virtual bool set(double)
Store into channel.
const IndirectChannel & operator=(const IndirectChannel &)
virtual ~IndirectChannel()