ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
VoidAccessor.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include "Application.h"
7
8#include <ChimeraTK/VoidRegisterAccessor.h>
9
10#include <string>
11
12namespace ChimeraTK {
13
14 /********************************************************************************************************************/
15
18 class VoidAccessor : public ChimeraTK::VoidRegisterAccessor, public InversionOfControlAccessor<VoidAccessor> {
19 public:
21 void replace(const ChimeraTK::NDRegisterAccessorAbstractor<ChimeraTK::Void>& newAccessor) = delete;
24 using ChimeraTK::VoidRegisterAccessor::operator=;
25
27 VoidAccessor(VoidAccessor&& other) noexcept;
28
31
32 bool write(ChimeraTK::VersionNumber versionNumber) = delete;
33 bool writeDestructively(ChimeraTK::VersionNumber versionNumber) = delete;
34 // void writeIfDifferent(UserType newValue, VersionNumber versionNumber) = delete;
35
36 bool write();
37
39
40 protected:
42
43 VoidAccessor(Module* owner, const std::string& name, VariableDirection direction, std::string& unit,
44 UpdateMode mode, const std::string& description, const std::unordered_set<std::string>& tags = {});
45
46 VoidAccessor(Module* owner, const std::string& name, VariableDirection direction, UpdateMode mode,
47 const std::string& description, const std::unordered_set<std::string>& tags = {});
48
50 VoidAccessor() = default;
51 };
52
53 /********************************************************************************************************************/
54
56 struct VoidInput : public VoidAccessor {
57 VoidInput(Module* owner, const std::string& name, const std::string& description,
58 const std::unordered_set<std::string>& tags = {})
59 : VoidAccessor(owner, name, {VariableDirection::consuming, false}, UpdateMode::push, description, tags) {}
60
61 VoidInput() = default;
62 using VoidAccessor::operator=;
63 };
64
65 /********************************************************************************************************************/
66
68 struct VoidOutput : public VoidAccessor {
69 VoidOutput(Module* owner, const std::string& name, const std::string& description,
70 const std::unordered_set<std::string>& tags = {})
71 : VoidAccessor(owner, name, {VariableDirection::feeding, false}, UpdateMode::push, description, tags) {}
72
73 VoidOutput() = default;
74 using VoidAccessor::operator=;
75 };
76
77 /********************************************************************************************************************/
78 /********************************************************************************************************************/
79 /* Implementations below this point */
80 /********************************************************************************************************************/
81 /********************************************************************************************************************/
82
83 inline VoidAccessor::VoidAccessor(VoidAccessor&& other) noexcept {
84 try {
86 }
87 catch(ChimeraTK::logic_error& e) {
88 std::cerr << "ChimeraTK::logic_error caught: " << e.what() << std::endl;
89 std::terminate();
90 }
91 }
92
93 /********************************************************************************************************************/
94
96 // Having a move-assignment operator is required to use the move-assignment
97 // operator of a module containing an accessor.
98 try {
100 }
101 catch(ChimeraTK::logic_error& e) {
102 std::cerr << "ChimeraTK::logic_error caught: " << e.what() << std::endl;
103 std::terminate();
104 }
105 return *this;
106 }
107
108 /********************************************************************************************************************/
109
110 inline bool VoidAccessor::write() {
111 auto versionNumber = this->getOwner()->getCurrentVersionNumber();
112 bool dataLoss = ChimeraTK::VoidRegisterAccessor::write(versionNumber);
113 if(dataLoss) {
115 }
116 return dataLoss;
117 }
118
119 /********************************************************************************************************************/
120
122 auto versionNumber = this->getOwner()->getCurrentVersionNumber();
123 bool dataLoss = ChimeraTK::VoidRegisterAccessor::writeDestructively(versionNumber);
124 if(dataLoss) {
126 }
127 return dataLoss;
128 }
129
130 /********************************************************************************************************************/
131
132 inline VoidAccessor::VoidAccessor(Module* owner, const std::string& name, VariableDirection direction,
133 std::string& unit, UpdateMode mode, const std::string& description, const std::unordered_set<std::string>& tags)
135 owner, name, direction, unit, 1, mode, description, &typeid(ChimeraTK::Void), tags) {}
136
137 /********************************************************************************************************************/
138
139 inline VoidAccessor::VoidAccessor(Module* owner, const std::string& name, VariableDirection direction,
140 UpdateMode mode, const std::string& description, const std::unordered_set<std::string>& tags)
142 owner, name, direction, "", 1, mode, description, &typeid(ChimeraTK::Void), tags) {}
143
144 /********************************************************************************************************************/
145
146} /* namespace ChimeraTK */
static void incrementDataLossCounter(const std::string &name)
Increment counter for how many write() operations have overwritten unread data.
virtual VersionNumber getCurrentVersionNumber() const =0
Return the current version number which has been received with the last push-type read operation.
Adds features required for inversion of control to an accessor.
void replace(Derived &&other)
Replace with other accessor.
EntityOwner * getOwner() const
Return the owning module.
Base class for ApplicationModule and DeviceModule, to have a common interface for these module types.
Definition Module.h:21
Class describing a node of a variable network.
Accessor for void variables (i.e.
VoidAccessor & operator=(VoidAccessor &other)=delete
void replace(const ChimeraTK::NDRegisterAccessorAbstractor< ChimeraTK::Void > &newAccessor)=delete
VoidAccessor()=default
Default constructor creates a dysfunctional accessor (to be assigned with a real accessor later)
bool writeDestructively(ChimeraTK::VersionNumber versionNumber)=delete
bool write(ChimeraTK::VersionNumber versionNumber)=delete
InvalidityTracer application module.
UpdateMode
Enum to define the update mode of variables.
Definition Flags.h:31
Struct to define the direction of variables.
Definition Flags.h:13
Convenience class for input accessors.
VoidInput(Module *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})
Convenience class for output void (always UpdateMode::push)
VoidOutput(Module *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})