OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
DirectChannel.h
Go to the documentation of this file.
1 #ifndef CLASSIC_DirectChannel_HH
2 #define CLASSIC_DirectChannel_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: DirectChannel.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: DirectChannel
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 DirectChannel
27 // ------------------------------------------------------------------------
29 // Class DirectChannel allows direct access to a [b]double[/b] variable.
30 
31 class DirectChannel: public Channel {
32 
33 public:
34 
36  // The constructed channel gives read/write access to the variable
37  // [b]value[/b]. The variable [b]value[/b] must not be destroyed as
38  // long as this channel is active.
39  explicit DirectChannel(double &value);
40 
42  virtual ~DirectChannel();
43 
45  virtual DirectChannel *clone() const;
46 
48  // If the channel can be written,
49  // store [b]value[/b] into it and return true,
50  // otherwise return false.
51  virtual bool set(double);
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 
58 private:
59 
60  // Not implemented.
63 
64  // The address of the variable to be read or written.
65  double &reference;
66 };
67 
68 
69 inline DirectChannel::DirectChannel(double &value):
70  reference(value)
71 {}
72 
73 
75  Channel(),
76  reference(rhs.reference)
77 {}
78 
79 
81 {}
82 
83 
85  return new DirectChannel(*this);
86 }
87 
88 
89 inline bool DirectChannel::set(double value) {
90  reference = value;
91  return true;
92 }
93 
94 
95 inline bool DirectChannel::get(double &value) const {
96  value = reference;
97  return true;
98 }
99 
100 
101 #endif // CLASSIC_DirectChannel_HH
Abstract interface for read/write access to variable.
Definition: Channel.h:32
Direct access to a [b]double[/b] variable.
Definition: DirectChannel.h:31
const DirectChannel & operator=(const DirectChannel &)
virtual ~DirectChannel()
Definition: DirectChannel.h:80
virtual DirectChannel * clone() const
Duplicate the channel.
Definition: DirectChannel.h:84
virtual bool set(double)
Store into channel.
Definition: DirectChannel.h:89
double & reference
Definition: DirectChannel.h:65
virtual bool get(double &) const
Fetch from channel.
Definition: DirectChannel.h:95