ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
IEEE754_SingleConverter.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
6#include "Exception.h"
7
8namespace ChimeraTK {
9
10 template<>
11 // sorry, linter. We can't change the signature here. This is a template specialisation for std::string.
12 // NOLINTNEXTLINE(performance-unnecessary-value-param)
13 uint32_t IEEE754_SingleConverter::toRaw(std::string cookedValue) const {
14 // step 1: convert string to float
15 float genericRepresentation;
16 try {
17 genericRepresentation = std::stof(cookedValue);
18 }
19 catch(std::exception& e) {
20 // FIXME: VariableName
21 // Note: We cannot do out of range limitations because we don't know if too
22 // large or too small
23 throw ChimeraTK::logic_error(e.what());
24 }
25
26 // step 2 as in the normal template: reinterpret cast
27 void* warningAvoider = &genericRepresentation;
28 // FIXME: Using byte-cast in C++20 should get rid of the linter warning
29 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
30 int32_t rawValue = *(reinterpret_cast<int32_t*>(warningAvoider));
31
32 return rawValue;
33 }
34
35} // namespace ChimeraTK
Exception thrown when a logic error has occured.
Definition Exception.h:51
uint32_t toRaw(CookedType cookedValue) const