OPAL (Object Oriented Parallel Accelerator Library)  2024.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 
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 nullptr.
66  virtual bool isSettable() const;
67 
68 private:
69 
70  // Not implemented.
72  const IndexedChannel &operator=(const IndexedChannel &);
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
void(T::* setF)(int, double)
virtual bool get(double &) const
Fetch from channel.
virtual bool isSettable() const
Test if settable.
virtual bool set(double)
Store into channel.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE:162
virtual ~IndexedChannel()
virtual IndexedChannel * clone() const
Duplicate the channel.
double(T::* getF)(int) const
set(_SRCS Action.cpp Attribute.cpp AttributeBase.cpp AttributeHandler.cpp BeamSequence.cpp Definition.cpp Directory.cpp Element.cpp Invalidator.cpp OpalData.cpp Object.cpp ObjectFunction.cpp PlaceRep.cpp RangeRep.cpp Table.cpp TableRowRep.cpp ValueDefinition.cpp) include_directories($
Definition: CMakeLists.txt:1
Abstract interface for read/write access to variable.
Definition: Channel.h:32
const IndexedChannel & operator=(const IndexedChannel &)
Access to an indexed [b]double[/b] data member.