mirror of https://github.com/SeanOMik/libki.git
dml: Specialize floating point types
(also, fixed a typo in the tests for DBL fields)
This commit is contained in:
parent
2dad97aded
commit
7903e23d90
|
@ -1,4 +1,5 @@
|
|||
#include "ki/dml/Field.h"
|
||||
#include "ki/util/ValueBytes.h"
|
||||
|
||||
namespace ki
|
||||
{
|
||||
|
@ -7,19 +8,28 @@ namespace dml
|
|||
template <>
|
||||
void DblField::write_to(std::ostream &ostream) const
|
||||
{
|
||||
|
||||
const ValueBytes<USHRT> endianness_check = { 0x0102 };
|
||||
ValueBytes<DBL> data = { m_value };
|
||||
if (endianness_check.buff[0] == 0x01)
|
||||
std::reverse(&data.buff[0], &data.buff[7]);
|
||||
ostream.write(data.buff, sizeof(DBL));
|
||||
}
|
||||
|
||||
template <>
|
||||
void DblField::read_from(std::istream &istream)
|
||||
{
|
||||
|
||||
const ValueBytes<USHRT> endianness_check = { 0x0102 };
|
||||
ValueBytes<DBL> data;
|
||||
istream.read(data.buff, sizeof(DBL));
|
||||
if (endianness_check.buff[0] == 0x01)
|
||||
std::reverse(&data.buff[0], &data.buff[3]);
|
||||
m_value = data.value;
|
||||
}
|
||||
|
||||
template <>
|
||||
size_t DblField::get_size() const
|
||||
{
|
||||
return 0;
|
||||
return sizeof(DBL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "ki/dml/Field.h"
|
||||
#include "ki/util/ValueBytes.h"
|
||||
|
||||
namespace ki
|
||||
{
|
||||
|
@ -7,19 +8,28 @@ namespace dml
|
|||
template <>
|
||||
void FltField::write_to(std::ostream &ostream) const
|
||||
{
|
||||
|
||||
const ValueBytes<USHRT> endianness_check = { 0x0102 };
|
||||
ValueBytes<FLT> data = { m_value };
|
||||
if (endianness_check.buff[0] == 0x01)
|
||||
std::reverse(&data.buff[0], &data.buff[3]);
|
||||
ostream.write(data.buff, sizeof(FLT));
|
||||
}
|
||||
|
||||
template <>
|
||||
void FltField::read_from(std::istream &istream)
|
||||
{
|
||||
|
||||
const ValueBytes<USHRT> endianness_check = { 0x0102 };
|
||||
ValueBytes<FLT> data;
|
||||
istream.read(data.buff, sizeof(FLT));
|
||||
if (endianness_check.buff[0] == 0x01)
|
||||
std::reverse(&data.buff[0], &data.buff[3]);
|
||||
m_value = data.value;
|
||||
}
|
||||
|
||||
template <>
|
||||
size_t FltField::get_size() const
|
||||
{
|
||||
return 0;
|
||||
return sizeof(FLT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ TEST_CASE("Field Serialization", "[dml]")
|
|||
{
|
||||
record->add_field<DBL>("TestDbl")->set_value(152.4);
|
||||
record->write_to(ss);
|
||||
REQUIRE(ss.str() == "\xCD\xCC\xCC\xCC\xCC\x0C\x64\x40");
|
||||
REQUIRE(ss.str() == "\xCD\xCC\xCC\xCC\xCC\x0C\x63\x40");
|
||||
}
|
||||
|
||||
SECTION("GID Fields")
|
||||
|
@ -245,7 +245,7 @@ TEST_CASE("Field Deserialization", "[dml]")
|
|||
|
||||
SECTION("DBL Fields")
|
||||
{
|
||||
ss.write("\xCD\xCC\xCC\xCC\xCC\x0C\x64\x40", 8);
|
||||
ss.write("\xCD\xCC\xCC\xCC\xCC\x0C\x63\x40", 8);
|
||||
ss.seekg(std::stringstream::beg);
|
||||
|
||||
auto *field = record->add_field<DBL>("TestDbl");
|
||||
|
|
Loading…
Reference in New Issue