51 offsetBeforeFactor =
true;
65 float defaultValue = std::nanf(
"1"),
66 bool offsetBeforeFactor =
true,
67 const char* nameForDebugging =
"")
81 float defaultValue = std::nanf(
"1"),
82 bool offsetBeforeFactor =
true,
83 const char* nameForDebugging =
"")
86 const auto rawAsInt =
reinterpret_cast<std::uint64_t
>(raw);
88 <<
"\nThe alignment is wrong!\nIt has to be " <<
alignof(
T)
89 <<
", but the data is aligned with " << rawAsInt %
alignof(std::max_align_t)
90 <<
"!\nThis is an offset of " << (rawAsInt %
alignof(
T))
92 <<
sizeof(
T) <<
"\nraw = " << raw <<
" bytes\nThe name is " << nameForDebugging;
94 this->offsetBeforeFactor = offsetBeforeFactor;
95 this->factor = factor;
96 this->offset = offset;
98 if (!std::isnan(defaultValue))
100 value = defaultValue;
113 if (offsetBeforeFactor)
115 value = ((*raw) + offset) * factor;
119 value = (*raw) * factor + offset;
126 if (offsetBeforeFactor)
128 *raw =
static_cast<T>((
value / factor) - offset);
132 *raw =
static_cast<T>((
value)-offset) / factor;
159 return offsetBeforeFactor;
164 float offset, factor;
165 bool offsetBeforeFactor;
void init(T *raw, const hardware_config::types::LinearConfig linearConfig, float defaultValue=std::nanf("1"), bool offsetBeforeFactor=true, const char *nameForDebugging="")
init
bool getOffsetBeforeFactor() const
void init(T *raw, float factor, float offset, float defaultValue=std::nanf("1"), bool offsetBeforeFactor=true, const char *nameForDebugging="")
The LinearConfig class represents a linear conversion and has a factor and offset.
float getFactor() const
Get the factor.
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
std::string GetTypeString(const std::type_info &tinf, bool withoutNamespaceSpecifier=false)