73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
#include "convert_basic.h"
|
|
#include "extract_basic.h"
|
|
#include <QVariant>
|
|
|
|
using namespace convert;
|
|
|
|
|
|
AbstractValueConvert::AbstractValueConvert(const QString& nm, DataType in, DataType out)
|
|
: name_store(nm), _in_type(in), _out_type(out) {
|
|
}
|
|
|
|
QString AbstractValueConvert::name() const
|
|
{
|
|
return name_store;
|
|
}
|
|
|
|
DataType AbstractValueConvert::inType() const
|
|
{
|
|
return _in_type;
|
|
}
|
|
|
|
DataType AbstractValueConvert::outType() const
|
|
{
|
|
return _out_type;
|
|
}
|
|
|
|
void AbstractValueConvert::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
|
{
|
|
auto int_in_type = (int)_in_type;
|
|
INT32_PEAK(int_in_type, obj);
|
|
_in_type = (DataType)int_in_type;
|
|
|
|
auto int_out_type = (int)_out_type;
|
|
INT32_PEAK(int_out_type, obj);
|
|
_out_type = (DataType)int_out_type;
|
|
}
|
|
|
|
void AbstractValueConvert::saveTo(QJsonObject& obj) const
|
|
{
|
|
auto int_in_type = (int)_in_type;
|
|
INT32_SAVE(int_in_type, obj);
|
|
|
|
auto int_out_type = (int)_out_type;
|
|
INT32_SAVE(int_out_type, obj);
|
|
}
|
|
|
|
DoubleWithLSB::DoubleWithLSB()
|
|
:AbstractValueConvert(NAME(DoubleWithLSB), DataType::Integer, DataType::Dbl64),
|
|
_lsb_value(1) {
|
|
}
|
|
|
|
void DoubleWithLSB::setLSB(double lsbv)
|
|
{
|
|
this->_lsb_value = lsbv;
|
|
}
|
|
|
|
double DoubleWithLSB::getLSB() const
|
|
{
|
|
return this->_lsb_value;
|
|
}
|
|
|
|
QVariant DoubleWithLSB::convert(const QVariant& value) const
|
|
{
|
|
if (value.canConvert<int64_t>())
|
|
return value.toLongLong() * this->_lsb_value;
|
|
return value.toULongLong() * this->_lsb_value;
|
|
}
|
|
|
|
std::shared_ptr<Serializable> DoubleWithLSB::newDefault() const
|
|
{
|
|
return std::make_shared<DoubleWithLSB>();
|
|
}
|