Newer
Older
Martin Christoph Hierholzer
committed
/*
* ScalarAccessor.h
*
* Created on: Jun 07, 2016
* Author: Martin Hierholzer
*/
Martin Christoph Hierholzer
committed
#ifndef CHIMERATK_SCALAR_ACCESSOR_H
#define CHIMERATK_SCALAR_ACCESSOR_H
#include <string>
#include <boost/smart_ptr/shared_ptr.hpp>
Martin Christoph Hierholzer
committed
#include <boost/thread.hpp>
Martin Christoph Hierholzer
committed
#include <ChimeraTK/ScalarRegisterAccessor.h>
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
#include "InversionOfControlAccessor.h"
Martin Christoph Hierholzer
committed
namespace ChimeraTK {
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/********************************************************************************************************************/
/** Accessor for scalar variables (i.e. single values). Note for users: Use the
* convenience classes
* ScalarPollInput, ScalarPushInput, ScalarOutput instead of this class
* directly. */
template <typename UserType>
class ScalarAccessor
: public ChimeraTK::ScalarRegisterAccessor<UserType>,
public InversionOfControlAccessor<ScalarAccessor<UserType>> {
public:
using InversionOfControlAccessor<ScalarAccessor<UserType>>::
operator VariableNetworkNode;
using InversionOfControlAccessor<ScalarAccessor<UserType>>::operator>>;
void replace(const ChimeraTK::NDRegisterAccessorAbstractor<UserType>
&newAccessor) = delete;
using InversionOfControlAccessor<ScalarAccessor<UserType>>::replace;
ScalarAccessor<UserType> &operator=(ScalarAccessor<UserType> &other) = delete;
using ChimeraTK::ScalarRegisterAccessor<UserType>::operator=;
/** Move constructor */
ScalarAccessor(ScalarAccessor<UserType> &&other) {
InversionOfControlAccessor<ScalarAccessor<UserType>>::replace(
std::move(other));
}
/** Move assignment. */
ScalarAccessor<UserType> &operator=(ScalarAccessor<UserType> &&other) {
// Having a move-assignment operator is required to use the move-assignment
// operator of a module containing an accessor.
InversionOfControlAccessor<ScalarAccessor<UserType>>::replace(
std::move(other));
return *this;
}
bool write(ChimeraTK::VersionNumber versionNumber) = delete;
bool write() {
auto versionNumber = this->getOwner()->getCurrentVersionNumber();
bool dataLoss =
ChimeraTK::ScalarRegisterAccessor<UserType>::write(versionNumber);
if (dataLoss)
Application::incrementDataLossCounter();
return dataLoss;
}
protected:
friend class InversionOfControlAccessor<ScalarAccessor<UserType>>;
ScalarAccessor(Module *owner, const std::string &name,
VariableDirection direction, std::string unit, UpdateMode mode,
const std::string &description,
const std::unordered_set<std::string> &tags = {})
: InversionOfControlAccessor<ScalarAccessor<UserType>>(
owner, name, direction, unit, 1, mode, description,
&typeid(UserType), tags) {}
/** Default constructor creates a dysfunctional accessor (to be assigned with
* a real accessor later) */
ScalarAccessor() {}
};
/********************************************************************************************************************/
/** Convenience class for input scalar accessors with UpdateMode::push */
template <typename UserType>
struct ScalarPushInput : public ScalarAccessor<UserType> {
ScalarPushInput(Module *owner, const std::string &name, std::string unit,
const std::string &description,
const std::unordered_set<std::string> &tags = {})
: ScalarAccessor<UserType>(owner, name,
{VariableDirection::consuming, false}, unit,
UpdateMode::push, description, tags) {}
ScalarPushInput() : ScalarAccessor<UserType>() {}
using ScalarAccessor<UserType>::operator=;
};
/********************************************************************************************************************/
/** Convenience class for input scalar accessors with UpdateMode::poll */
template <typename UserType>
struct ScalarPollInput : public ScalarAccessor<UserType> {
ScalarPollInput(Module *owner, const std::string &name, std::string unit,
const std::string &description,
const std::unordered_set<std::string> &tags = {})
: ScalarAccessor<UserType>(owner, name,
{VariableDirection::consuming, false}, unit,
UpdateMode::poll, description, tags) {}
ScalarPollInput() : ScalarAccessor<UserType>() {}
void doReadTransfer() { this->doReadTransferLatest(); }
void read() { this->readLatest(); }
using ScalarAccessor<UserType>::operator=;
};
/********************************************************************************************************************/
/** Convenience class for output scalar accessors (always UpdateMode::push) */
template <typename UserType>
struct ScalarOutput : public ScalarAccessor<UserType> {
ScalarOutput(Module *owner, const std::string &name, std::string unit,
const std::string &description,
const std::unordered_set<std::string> &tags = {})
: ScalarAccessor<UserType>(owner, name,
{VariableDirection::feeding, false}, unit,
UpdateMode::push, description, tags) {}
ScalarOutput() : ScalarAccessor<UserType>() {}
using ScalarAccessor<UserType>::operator=;
};
/********************************************************************************************************************/
/** Convenience class for input scalar accessors with return channel ("write
* back") and UpdateMode::push */
template <typename UserType>
struct ScalarPushInputWB : public ScalarAccessor<UserType> {
ScalarPushInputWB(Module *owner, const std::string &name, std::string unit,
const std::string &description,
const std::unordered_set<std::string> &tags = {})
: ScalarAccessor<UserType>(owner, name,
{VariableDirection::consuming, true}, unit,
UpdateMode::push, description, tags) {}
ScalarPushInputWB() : ScalarAccessor<UserType>() {}
using ScalarAccessor<UserType>::operator=;
};
/********************************************************************************************************************/
/** Convenience class for output scalar accessors with return channel ("read
* back") (always UpdateMode::push) */
template <typename UserType>
struct ScalarOutputPushRB : public ScalarAccessor<UserType> {
ScalarOutputPushRB(Module *owner, const std::string &name, std::string unit,
const std::string &description,
const std::unordered_set<std::string> &tags = {})
: ScalarAccessor<UserType>(owner, name,
{VariableDirection::feeding, true}, unit,
UpdateMode::push, description, tags) {}
ScalarOutputPushRB() : ScalarAccessor<UserType>() {}
using ScalarAccessor<UserType>::operator=;
};
/********************************************************************************************************************/
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
} /* namespace ChimeraTK */
#endif /* CHIMERATK_SCALAR_ACCESSOR_H */