ChimeraTK-ApplicationCore 04.07.01
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
38 bool writeDestructively();
39
41
42 protected:
44
45 VoidAccessor(Module* owner, const std::string& name, VariableDirection direction, std::string& unit,
46 UpdateMode mode, const std::string& description, const std::unordered_set<std::string>& tags = {});
47
48 VoidAccessor(Module* owner, const std::string& name, VariableDirection direction, UpdateMode mode,
49 const std::string& description, const std::unordered_set<std::string>& tags = {});
50
52 VoidAccessor() = default;
53 };
54
55 /********************************************************************************************************************/
56
58 class VoidInput : public VoidAccessor {
59 public:
60 VoidInput(Module* owner, const std::string& name, const std::string& description,
61 const std::unordered_set<std::string>& tags = {})
62 : VoidAccessor(owner, name, {VariableDirection::consuming, false}, UpdateMode::push, description, tags) {}
63
64 VoidInput() = default;
65 using VoidAccessor::operator=;
66 };
67
68 /********************************************************************************************************************/
69
71 class VoidOutput : public VoidAccessor {
72 public:
73 VoidOutput(Module* owner, const std::string& name, const std::string& description,
74 const std::unordered_set<std::string>& tags = {})
75 : VoidAccessor(owner, name, {VariableDirection::feeding, false}, UpdateMode::push, description, tags) {}
76
77 VoidOutput() = default;
78 using VoidAccessor::operator=;
79 };
80
81 /********************************************************************************************************************/
82 /********************************************************************************************************************/
83 /* Implementations below this point */
84 /********************************************************************************************************************/
85 /********************************************************************************************************************/
86
87 inline VoidAccessor::VoidAccessor(VoidAccessor&& other) noexcept {
88 try {
90 }
91 catch(ChimeraTK::logic_error& e) {
92 std::cerr << "ChimeraTK::logic_error caught: " << e.what() << std::endl;
93 std::terminate();
94 }
95 }
96
97 /********************************************************************************************************************/
98
100 // Having a move-assignment operator is required to use the move-assignment
101 // operator of a module containing an accessor.
102 try {
104 }
105 catch(ChimeraTK::logic_error& e) {
106 std::cerr << "ChimeraTK::logic_error caught: " << e.what() << std::endl;
107 std::terminate();
108 }
109 return *this;
110 }
111
112 /********************************************************************************************************************/
113
114 inline bool VoidAccessor::write() {
115 auto versionNumber = this->getOwner()->getCurrentVersionNumber();
116 bool dataLoss = ChimeraTK::VoidRegisterAccessor::write(versionNumber);
117 if(dataLoss) {
119 }
120 return dataLoss;
121 }
122
123 /********************************************************************************************************************/
124
126 auto versionNumber = this->getOwner()->getCurrentVersionNumber();
127 bool dataLoss = ChimeraTK::VoidRegisterAccessor::writeDestructively(versionNumber);
128 if(dataLoss) {
130 }
131 return dataLoss;
132 }
133
134 /********************************************************************************************************************/
135
136 inline VoidAccessor::VoidAccessor(Module* owner, const std::string& name, VariableDirection direction,
137 std::string& unit, UpdateMode mode, const std::string& description, const std::unordered_set<std::string>& tags)
139 owner, name, direction, unit, 1, mode, description, &typeid(ChimeraTK::Void), tags) {
141 }
142
143 /********************************************************************************************************************/
144
145 inline VoidAccessor::VoidAccessor(Module* owner, const std::string& name, VariableDirection direction,
146 UpdateMode mode, const std::string& description, const std::unordered_set<std::string>& tags)
148 owner, name, direction, "", 1, mode, description, &typeid(ChimeraTK::Void), tags) {
150 }
151
152 /********************************************************************************************************************/
153
154} /* 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 deinit()
Early deinitialisation of stuff we cannot do in our destructor.
void init()
Late initialisation of stuff we cannot do in our constructor.
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
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={})
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