ChimeraTK-DeviceAccess 03.27.00
Loading...
Searching...
No Matches
DummyRegisterAccessor.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
4
5namespace ChimeraTK::proxies {
6
7 /********************************************************************************************************************/
8
9 template<typename UserType, typename RawConverter>
11 public:
12 explicit RawConverterCapsuleImpl(RawConverter converter) : _converter(converter) {}
13
14 UserType toCooked(std::byte* raw) override;
15
16 void toRaw(UserType cooked, std::byte* raw) override;
17
18 private:
19 RawConverter _converter;
20 };
21
22 /********************************************************************************************************************/
23
24 template<typename UserType, typename RawConverter>
26 using RawType = RawConverter::raw_type;
27 RawType rawValue;
28 std::memcpy(&rawValue, raw, sizeof(RawType));
29 return _converter.toCooked(rawValue);
30 }
31
32 /********************************************************************************************************************/
33
34 template<typename UserType, typename RawConverter>
36 using RawType = RawConverter::raw_type;
37 RawType rawValue = _converter.toRaw(cooked);
38 std::memcpy(raw, &rawValue, sizeof(RawType));
39 }
40
41 /********************************************************************************************************************/
42 /********************************************************************************************************************/
43
44 template<typename UserType>
45 std::shared_ptr<RawConverterCapsule<UserType>> RawConverterCapsule<UserType>::makeCapsule(
46 const ChimeraTK::NumericAddressedRegisterInfo& info, size_t channelIndex) {
47 std::shared_ptr<RawConverterCapsule<UserType>> rv;
48
49 callForRawType(info.channels[channelIndex].getRawType(), [&]([[maybe_unused]] auto dummy) {
50 using RawType = std::make_unsigned_t<decltype(dummy)>;
51 ChimeraTK::RawConverter::withConverter<UserType, RawType>(info, channelIndex, [&](auto converter) {
52 rv = std::make_shared<RawConverterCapsuleImpl<UserType, decltype(converter)>>(converter);
53 });
54 });
55
56 return rv;
57 }
58
59 /********************************************************************************************************************/
60
62
63 /********************************************************************************************************************/
64
65} // namespace ChimeraTK::proxies
#define INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES_NO_VOID(TemplateClass)
std::vector< ChannelInfo > channels
Define per-channel information (bit interpretation etc.), 1D/scalars have exactly one entry.
This abstract class encapsulates a RawConverter to erase the exact RawConverter type (with all its te...
static std::shared_ptr< RawConverterCapsule< UserType > > makeCapsule(const ChimeraTK::NumericAddressedRegisterInfo &info, size_t channelIndex)
void toRaw(UserType cooked, std::byte *raw) override
We are using temporary proxy classes to realise element access with fixed point conversion.
void callForRawType(const DataType &type, LAMBDATYPE lambda)
callForRawType() is similar to callForType(), just with a subset of supported data types which can be...
@ raw
Raw access: disable any possible conversion from the original hardware data type into the given UserT...