ChimeraTK-DeviceAccess 03.27.00
Loading...
Searching...
No Matches
SubdeviceConvertingRawDecorator.cc
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
5
6namespace ChimeraTK {
7
8 /********************************************************************************************************************/
9
10 template<typename TargetUserType>
12 const boost::shared_ptr<ChimeraTK::NDRegisterAccessor<TargetUserType>>& target,
13 NumericAddressedRegisterInfo const& registerInfo)
14 : NDRegisterAccessorDecorator<TargetUserType>(target), _registerInfo(registerInfo) {
15 static_assert(isRawType<std::make_unsigned_t<TargetUserType>>);
18 }
19
20 /********************************************************************************************************************/
21
22 template<typename TargetUserType>
23 template<typename COOKED_TYPE>
24 // NOLINTNEXTLINE(readability-identifier-naming)
25 COOKED_TYPE ConvertingRawDecorator<TargetUserType>::getAsCooked_impl(unsigned int channel, unsigned int sample) {
26 COOKED_TYPE rv;
27 RawConverter::withConverter<COOKED_TYPE, std::make_unsigned_t<TargetUserType>>(
28 _registerInfo, 0, [&](auto converter) {
29 rv = converter.toCooked(
30 std::make_unsigned_t<TargetUserType>(NDRegisterAccessor<TargetUserType>::buffer_2D[channel][sample]));
31 });
32 return rv;
33 }
34
35 /********************************************************************************************************************/
36
37 template<typename TargetUserType>
38 template<typename COOKED_TYPE>
39 // NOLINTNEXTLINE(readability-identifier-naming)
41 unsigned int channel, unsigned int sample, COOKED_TYPE value) {
42 RawConverter::withConverter<COOKED_TYPE, std::make_unsigned_t<TargetUserType>>(
43 _registerInfo, 0, [&](auto converter) {
44 NDRegisterAccessor<TargetUserType>::buffer_2D[channel][sample] = TargetUserType(converter.toRaw(value));
45 });
46 }
47
48 /********************************************************************************************************************/
49
50 template<typename TargetUserType>
52 const boost::shared_ptr<ChimeraTK::TransferElement const>& other) const {
53 auto casted = boost::dynamic_pointer_cast<ConvertingRawDecorator<TargetUserType> const>(other);
54 if(!casted) {
55 return false;
56 }
57 if(_registerInfo != casted->_registerInfo) {
58 return false;
59 }
60
61 return _target->mayReplaceOther(casted->_target);
62 }
63
64 /********************************************************************************************************************/
65
67
68 // FIXME: get rid of the deprecated signed raw
69 template class ConvertingRawDecorator<int8_t>;
73
74} // namespace ChimeraTK
#define INSTANTIATE_TEMPLATE_FOR_CHIMERATK_RAW_TYPES(TemplateClass)
#define FILL_VIRTUAL_FUNCTION_TEMPLATE_VTABLE(functionName)
Fill the vtable of a virtual function template defined with DEFINE_VIRTUAL_FUNCTION_TEMPLATE.
COOKED_TYPE getAsCooked_impl(unsigned int channel, unsigned int sample)
void setAsCooked_impl(unsigned int channel, unsigned int sample, COOKED_TYPE value)
bool mayReplaceOther(const boost::shared_ptr< ChimeraTK::TransferElement const > &other) const override
ConvertingRawDecorator(const boost::shared_ptr< ChimeraTK::NDRegisterAccessor< TargetUserType > > &target, NumericAddressedRegisterInfo const &registerInfo)
Base class for decorators of the NDRegisterAccessor.
N-dimensional register accessor.