[ox] Correct bad bit_cast uses and improve constexpr-ness

This commit is contained in:
2021-11-28 21:03:29 -06:00
parent 22f08f83c5
commit 1f24912ddd
35 changed files with 247 additions and 214 deletions

View File

@ -50,20 +50,18 @@ struct TestStruct {
int32_t Int7 = 0;
int32_t Int8 = 0;
TestUnion Union;
char *CString = nullptr;
ox::BString<32> String = "";
uint32_t List[4] = {0, 0, 0, 0};
TestStructNest EmptyStruct;
TestStructNest Struct;
~TestStruct() {
delete[] CString;
}
};
template<typename T>
ox::Error model(T *io, TestUnion *obj) {
constexpr ox::Error model(T *io, TestUnion *obj) {
io->template setTypeInfo<TestUnion>();
oxReturnError(io->field("Bool", &obj->Bool));
oxReturnError(io->field("Int", &obj->Int));
@ -72,7 +70,7 @@ ox::Error model(T *io, TestUnion *obj) {
}
template<typename T>
ox::Error model(T *io, TestStructNest *obj) {
constexpr ox::Error model(T *io, TestStructNest *obj) {
io->template setTypeInfo<TestStructNest>();
oxReturnError(io->field("Bool", &obj->Bool));
oxReturnError(io->field("Int", &obj->Int));
@ -81,7 +79,7 @@ ox::Error model(T *io, TestStructNest *obj) {
}
template<typename T>
ox::Error model(T *io, TestStruct *obj) {
constexpr ox::Error model(T *io, TestStruct *obj) {
io->template setTypeInfo<TestStruct>();
oxReturnError(io->field("Bool", &obj->Bool));
oxReturnError(io->field("Int", &obj->Int));
@ -94,7 +92,6 @@ ox::Error model(T *io, TestStruct *obj) {
oxReturnError(io->field("Int7", &obj->Int7));
oxReturnError(io->field("Int8", &obj->Int8));
oxReturnError(io->field("Union", ox::UnionView{&obj->Union, 1}));
oxReturnError(io->field("CString", ox::SerStr(&obj->CString)));
oxReturnError(io->field("String", &obj->String));
oxReturnError(io->field("List", obj->List, 4));
oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct));
@ -146,8 +143,6 @@ std::map<std::string_view, ox::Error(*)()> tests = {
testIn.Int = 42;
testIn.Union.Int = 42;
testIn.String = "Test String 1";
testIn.CString = new char[ox_strlen("c-string") + 1];
ox_strcpy(testIn.CString, "c-string");
testIn.List[0] = 1;
testIn.List[1] = 2;
testIn.List[2] = 3;
@ -171,7 +166,6 @@ std::map<std::string_view, ox::Error(*)()> tests = {
oxAssert(testIn.Int6 == testOut.Int6, "Int6 value mismatch");
oxAssert(testIn.Int7 == testOut.Int7, "Int7 value mismatch");
oxAssert(testIn.Int8 == testOut.Int8, "Int8 value mismatch");
oxAssert(ox_strcmp(testIn.CString, testOut.CString) == 0, "CString value mismatch");
oxAssert(testIn.Union.Int == testOut.Union.Int, "Union.Int value mismatch");
oxAssert(testIn.String == testOut.String, "String value mismatch");
oxAssert(testIn.List[0] == testOut.List[0], "List[0] value mismatch");