Newer
Older
Martin Christoph Hierholzer
committed
* ArrayAccessor.h
*
* Created on: Jun 07, 2016
* Author: Martin Hierholzer
*/
#ifndef CHIMERATK_ARRAY_ACCESSOR_H
#define CHIMERATK_ARRAY_ACCESSOR_H
#include <string>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <ChimeraTK/OneDRegisterAccessor.h>
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
#include "InversionOfControlAccessor.h"
Martin Christoph Hierholzer
committed
#include "Application.h"
Martin Christoph Hierholzer
committed
/********************************************************************************************************************/
Martin Christoph Hierholzer
committed
/** Accessor for array variables (i.e. vectors). Note for users: Use the convenience classes
Martin Christoph Hierholzer
committed
* ArrayPollInput, ArrayPushInput, ArrayOutput instead of this class directly. */
class ArrayAccessor : public ChimeraTK::OneDRegisterAccessor<UserType>,
Martin Christoph Hierholzer
committed
public InversionOfControlAccessor<ArrayAccessor<UserType>> {
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
using InversionOfControlAccessor<ArrayAccessor<UserType>>::operator VariableNetworkNode;
using InversionOfControlAccessor<ArrayAccessor<UserType>>::operator>>;
void replace(const ChimeraTK::NDRegisterAccessorAbstractor<UserType> &newAccessor) = delete;
Martin Christoph Hierholzer
committed
using InversionOfControlAccessor<ArrayAccessor<UserType>>::replace;
ArrayAccessor<UserType>& operator=(ArrayAccessor<UserType> &other) = delete;
using ChimeraTK::OneDRegisterAccessor<UserType>::operator=;
/** Move constructor */
ArrayAccessor(ArrayAccessor<UserType> &&other) {
Martin Christoph Hierholzer
committed
InversionOfControlAccessor<ArrayAccessor<UserType>>::replace(std::move(other));
Martin Christoph Hierholzer
committed
}
Martin Christoph Hierholzer
committed
/** Move assignment */
ArrayAccessor<UserType>& operator=(ArrayAccessor<UserType> &&other) {
// Having a move-assignment operator is required to use the move-assignment operator of a module containing
// an accessor.
InversionOfControlAccessor<ArrayAccessor<UserType>>::replace(std::move(other));
return *this;
Martin Christoph Hierholzer
committed
}
Martin Christoph Hierholzer
committed
bool write(ChimeraTK::VersionNumber versionNumber) = delete;
bool write() {
auto versionNumber = this->getOwner()->getCurrentVersionNumber();
bool dataLoss = ChimeraTK::OneDRegisterAccessor<UserType>::write(versionNumber);
Martin Christoph Hierholzer
committed
if(dataLoss) Application::incrementDataLossCounter();
return dataLoss;
}
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
TransferFuture readAsync() {
throw ChimeraTK::logic_error("ArrayAccessor::readAsync() is currently not supported by ApplicationCore!");
}
Martin Christoph Hierholzer
committed
protected:
Martin Christoph Hierholzer
committed
friend class InversionOfControlAccessor<ArrayAccessor<UserType>>;
Martin Christoph Hierholzer
committed
ArrayAccessor(Module *owner, const std::string &name, VariableDirection direction, std::string unit,
Martin Christoph Hierholzer
committed
size_t nElements, UpdateMode mode, const std::string &description,
const std::unordered_set<std::string> &tags={})
Martin Christoph Hierholzer
committed
: InversionOfControlAccessor<ArrayAccessor<UserType>>(owner, name, direction, unit, nElements, mode,
description, &typeid(UserType), tags)
{}
/** Default constructor creates a dysfunctional accessor (to be assigned with a real accessor later) */
Martin Christoph Hierholzer
committed
ArrayAccessor() {}
Martin Christoph Hierholzer
committed
/********************************************************************************************************************/
Martin Christoph Hierholzer
committed
/** Convenience class for input array accessors with UpdateMode::push */
template< typename UserType >
struct ArrayPushInput : public ArrayAccessor<UserType> {
Martin Christoph Hierholzer
committed
ArrayPushInput(Module *owner, const std::string &name, std::string unit, size_t nElements,
const std::string &description, const std::unordered_set<std::string> &tags={})
Martin Christoph Hierholzer
committed
: ArrayAccessor<UserType>(owner, name, {VariableDirection::consuming, false}, unit, nElements, UpdateMode::push,
Martin Christoph Hierholzer
committed
description, tags)
Martin Christoph Hierholzer
committed
{}
ArrayPushInput() : ArrayAccessor<UserType>() {}
using ArrayAccessor<UserType>::operator=;
};
Martin Christoph Hierholzer
committed
/********************************************************************************************************************/
Martin Christoph Hierholzer
committed
/** Convenience class for input array accessors with UpdateMode::poll */
template< typename UserType >
struct ArrayPollInput : public ArrayAccessor<UserType> {
Martin Christoph Hierholzer
committed
ArrayPollInput(Module *owner, const std::string &name, std::string unit, size_t nElements,
const std::string &description, const std::unordered_set<std::string> &tags={})
Martin Christoph Hierholzer
committed
: ArrayAccessor<UserType>(owner, name, {VariableDirection::consuming, false}, unit, nElements, UpdateMode::poll,
Martin Christoph Hierholzer
committed
description, tags)
Martin Christoph Hierholzer
committed
{}
ArrayPollInput() : ArrayAccessor<UserType>() {}
void doReadTransfer() { this->doReadTransferLatest(); }
void read() { this->readLatest(); }
Martin Christoph Hierholzer
committed
using ArrayAccessor<UserType>::operator=;
};
Martin Christoph Hierholzer
committed
/********************************************************************************************************************/
Martin Christoph Hierholzer
committed
/** Convenience class for output array accessors (always UpdateMode::push) */
template< typename UserType >
struct ArrayOutput : public ArrayAccessor<UserType> {
Martin Christoph Hierholzer
committed
ArrayOutput(Module *owner, const std::string &name, std::string unit, size_t nElements,
const std::string &description, const std::unordered_set<std::string> &tags={})
Martin Christoph Hierholzer
committed
: ArrayAccessor<UserType>(owner, name, {VariableDirection::feeding, false}, unit, nElements, UpdateMode::push,
Martin Christoph Hierholzer
committed
description, tags)
Martin Christoph Hierholzer
committed
{}
ArrayOutput() : ArrayAccessor<UserType>() {}
using ArrayAccessor<UserType>::operator=;
};
Martin Christoph Hierholzer
committed
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
/********************************************************************************************************************/
/** Convenience class for input array accessors with return channel ("write back") and UpdateMode::push */
template< typename UserType >
struct ArrayPushInputWB : public ArrayAccessor<UserType> {
ArrayPushInputWB(Module *owner, const std::string &name, std::string unit, size_t nElements,
const std::string &description, const std::unordered_set<std::string> &tags={})
: ArrayAccessor<UserType>(owner, name, {VariableDirection::consuming, true}, unit, nElements, UpdateMode::push,
description, tags)
{}
ArrayPushInputWB() : ArrayAccessor<UserType>() {}
using ArrayAccessor<UserType>::operator=;
};
/********************************************************************************************************************/
/** Convenience class for output array accessors with return channel ("read back") (always UpdateMode::push) */
template< typename UserType >
struct ArrayOutputRB : public ArrayAccessor<UserType> {
ArrayOutputRB(Module *owner, const std::string &name, std::string unit, size_t nElements,
const std::string &description, const std::unordered_set<std::string> &tags={})
: ArrayAccessor<UserType>(owner, name, {VariableDirection::feeding, true}, unit, nElements, UpdateMode::push,
description, tags)
{}
ArrayOutputRB() : ArrayAccessor<UserType>() {}
using ArrayAccessor<UserType>::operator=;
};
/********************************************************************************************************************/
} /* namespace ChimeraTK */
#endif /* CHIMERATK_ARRAY_ACCESSOR_H */