ChimeraTK-DeviceAccess
03.18.00
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
4
#include "
IEEE754_SingleConverter.h
"
5
6
#include "
Exception.h
"
7
8
namespace
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
IEEE754_SingleConverter.h
Exception.h
ChimeraTK
Definition:
DummyBackend.h:16
ChimeraTK::IEEE754_SingleConverter::toRaw
uint32_t toRaw(CookedType cookedValue) const
Definition:
IEEE754_SingleConverter.h:100
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition:
Exception.h:51
sources
ChimeraTK-DeviceAccess
src
IEEE754_SingleConverter.cc
Generated by
1.8.17