加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sample.cpp 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
#include "sample.h"
#include <QtEndian>
#include <QDebug>
sample::sample()
{
static_assert(Q_BYTE_ORDER == Q_LITTLE_ENDIAN, "Only supports LITTLE ENDIAN");
}
uint32_t sample::getRgb() const
{
typedef decltype(state.val) T;
const decltype(state) s{qFromBigEndian<T>(state.val)};
return s.rgb;
}
uint32_t sample::getBed() const
{
const decltype(state) s {qFromBigEndian<uint32_t>(state.val)};
return s.bed;
}
uint32_t sample::getKitchen() const
{
const decltype(state) s{qFromBigEndian<uint32_t>(state.val)};
return s.kitchen;
}
void sample::setRgb(uint32_t newRgb)
{
decltype(state) s {qFromBigEndian<uint32_t>(state.val)};
s.rgb = newRgb;
state.val = qToBigEndian<uint32_t>(s.val);
// Q_ASSERT(false);
}
namespace
{
constexpr double factor = 8.38190317e-8;
}
double sample::getLongitude() const
{
double ret = qFromBigEndian<decltype(longitude)>(longitude);
ret *= factor;
return ret;
}
void sample::setLongitude(double newLongitude)
{
decltype(longitude) v1 = newLongitude / factor;
auto v2 = qToBigEndian<decltype(longitude)>(v1);
longitude = v2;
}
void sample::print() const
{
qDebug() << "<" << "longtitude=" << getLongitude()
<< ",bed=" << this->getBed()
<< ",kitchen=" << this->getKitchen()
<< ",rgb=" << this->getRgb();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化