Skip to content
Snippets Groups Projects
Commit 024c2758 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

fixed replacing Array and ScalarAccessors, which was broken after moving to...

fixed replacing Array and ScalarAccessors, which was broken after moving to the NDRegisterAccessorBridge-based accessors
parent 1ab6262f
No related branches found
No related tags found
No related merge requests found
......@@ -19,20 +19,11 @@
namespace ChimeraTK {
/** Accessor for array variables (i.e. vectors). Note for users: Preferrably use the convenience classes
/** Accessor for array variables (i.e. vectors). Note for users: Use the convenience classes
* ArrayPollInput, ArrayPushInput, ArrayOutput instead of this class directly. */
template< typename UserType >
class ArrayAccessor : public mtca4u::OneDRegisterAccessor<UserType> {
public:
ArrayAccessor(Module *owner, const std::string &name, VariableDirection direction, std::string unit,
size_t nElements, UpdateMode mode, const std::string &description)
: node(this, name, direction, unit, nElements, mode, description, &typeid(UserType))
{
owner->registerAccessor(*this);
}
/** Default constructor creates a dysfunction accessor (to be assigned with a real accessor later) */
ArrayAccessor() {}
/** Convert into VariableNetworkNode */
operator VariableNetworkNode() {
......@@ -43,13 +34,42 @@ namespace ChimeraTK {
VariableNetworkNode operator>>(const VariableNetworkNode &otherNode) {
return node >> otherNode;
}
/** Replace with other ScalarRegisterAccessor */
void replace(const ArrayAccessor<UserType> &newAccessor) {
mtca4u::NDRegisterAccessorBridge<UserType>::replace(newAccessor);
node = VariableNetworkNode(this, newAccessor.node.getName(), newAccessor.node.getDirection(), newAccessor.node.getUnit(),
newAccessor.node.getNumberOfElements(), newAccessor.node.getMode(), newAccessor.node.getDescription(),
&newAccessor.node.getValueType());
if(_owner != newAccessor._owner) {
if(_owner != nullptr) _owner->unregisterAccessor(*this);
_owner = newAccessor._owner;
_owner->registerAccessor(*this);
}
}
void replace(const NDRegisterAccessorBridge<UserType> &newAccessor) = delete;
using mtca4u::OneDRegisterAccessor<UserType>::operator=;
~ArrayAccessor() {
if(_owner != nullptr) _owner->unregisterAccessor(*this);
}
protected:
ArrayAccessor(Module *owner, const std::string &name, VariableDirection direction, std::string unit,
size_t nElements, UpdateMode mode, const std::string &description)
: node(this, name, direction, unit, nElements, mode, description, &typeid(UserType)), _owner(owner)
{
owner->registerAccessor(*this);
}
/** Default constructor creates a dysfunction accessor (to be assigned with a real accessor later) */
ArrayAccessor() {}
VariableNetworkNode node;
Module *_owner{nullptr};
};
/** Convenience class for input array accessors with UpdateMode::push */
......
......@@ -20,20 +20,11 @@
namespace ChimeraTK {
/** Accessor for scalar variables (i.e. single values). Note for users: Preferrably use the convenience classes
/** 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 mtca4u::ScalarRegisterAccessor<UserType> {
public:
ScalarAccessor(Module *owner, const std::string &name, VariableDirection direction, std::string unit,
UpdateMode mode, const std::string &description)
: node(this, name, direction, unit, 1, mode, description, &typeid(UserType))
{
owner->registerAccessor(*this);
}
/** Default constructor creates a dysfunctional accessor (to be assigned with a real accessor later) */
ScalarAccessor() {}
/** Convert into VariableNetworkNode */
operator VariableNetworkNode() {
......@@ -45,12 +36,43 @@ namespace ChimeraTK {
return node >> otherNode;
}
/** Replace with other ScalarRegisterAccessor */
void replace(const ScalarAccessor<UserType> &newAccessor) {
mtca4u::NDRegisterAccessorBridge<UserType>::replace(newAccessor);
node = VariableNetworkNode(this, newAccessor.node.getName(), newAccessor.node.getDirection(), newAccessor.node.getUnit(),
newAccessor.node.getNumberOfElements(), newAccessor.node.getMode(), newAccessor.node.getDescription(),
&newAccessor.node.getValueType());
if(_owner != newAccessor._owner) {
if(_owner != nullptr) _owner->unregisterAccessor(*this);
_owner = newAccessor._owner;
_owner->registerAccessor(*this);
}
}
void replace(const NDRegisterAccessorBridge<UserType> &newAccessor) = delete;
using mtca4u::ScalarRegisterAccessor<UserType>::operator=;
~ScalarAccessor() {
if(_owner != nullptr) _owner->unregisterAccessor(*this);
}
protected:
ScalarAccessor(Module *owner, const std::string &name, VariableDirection direction, std::string unit,
UpdateMode mode, const std::string &description)
: node(this, name, direction, unit, 1, mode, description, &typeid(UserType)), _owner(owner)
{
owner->registerAccessor(*this);
}
/** Default constructor creates a dysfunctional accessor (to be assigned with a real accessor later) */
ScalarAccessor() {}
VariableNetworkNode node;
Module *_owner{nullptr};
};
/** Convenience class for input scalar accessors with UpdateMode::push */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment