Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #170: C++ HDF5 build error for map fields #171

Merged
merged 6 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions cpp/test/generated/binary/protocols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ struct IsTriviallySerializable<test_model::RecordWithUnionsOfContainers> {
offsetof(__T__, map_or_scalar) < offsetof(__T__, vector_or_scalar) && offsetof(__T__, vector_or_scalar) < offsetof(__T__, array_or_scalar);
};

template <>
struct IsTriviallySerializable<test_model::RecordWithMaps> {
using __T__ = test_model::RecordWithMaps;
static constexpr bool value =
std::is_standard_layout_v<__T__> &&
IsTriviallySerializable<decltype(__T__::set_1)>::value &&
IsTriviallySerializable<decltype(__T__::set_2)>::value &&
(sizeof(__T__) == (sizeof(__T__::set_1) + sizeof(__T__::set_2))) &&
offsetof(__T__, set_1) < offsetof(__T__, set_2);
};

template <>
struct IsTriviallySerializable<test_model::RecordWithNoDefaultEnum> {
using __T__ = test_model::RecordWithNoDefaultEnum;
Expand Down Expand Up @@ -1641,6 +1652,26 @@ namespace {
yardl::binary::ReadNDArray<int32_t, yardl::binary::ReadInteger, 2>(stream, value);
}

[[maybe_unused]] void WriteRecordWithMaps(yardl::binary::CodedOutputStream& stream, test_model::RecordWithMaps const& value) {
if constexpr (yardl::binary::IsTriviallySerializable<test_model::RecordWithMaps>::value) {
yardl::binary::WriteTriviallySerializable(stream, value);
return;
}

yardl::binary::WriteMap<uint32_t, uint32_t, yardl::binary::WriteInteger, yardl::binary::WriteInteger>(stream, value.set_1);
yardl::binary::WriteMap<int32_t, bool, yardl::binary::WriteInteger, yardl::binary::WriteInteger>(stream, value.set_2);
}

[[maybe_unused]] void ReadRecordWithMaps(yardl::binary::CodedInputStream& stream, test_model::RecordWithMaps& value) {
if constexpr (yardl::binary::IsTriviallySerializable<test_model::RecordWithMaps>::value) {
yardl::binary::ReadTriviallySerializable(stream, value);
return;
}

yardl::binary::ReadMap<uint32_t, uint32_t, yardl::binary::ReadInteger, yardl::binary::ReadInteger>(stream, value.set_1);
yardl::binary::ReadMap<int32_t, bool, yardl::binary::ReadInteger, yardl::binary::ReadInteger>(stream, value.set_2);
}

[[maybe_unused]] void WriteFruits(yardl::binary::CodedOutputStream& stream, test_model::Fruits const& value) {
if constexpr (yardl::binary::IsTriviallySerializable<test_model::Fruits>::value) {
yardl::binary::WriteTriviallySerializable(stream, value);
Expand Down Expand Up @@ -3725,6 +3756,10 @@ void MapsWriter::WriteAliasedGenericImpl(basic_types::AliasedMap<std::string, in
basic_types::binary::WriteAliasedMap<std::string, yardl::binary::WriteString, int32_t, yardl::binary::WriteInteger>(stream_, value);
}

void MapsWriter::WriteRecordsImpl(std::vector<test_model::RecordWithMaps> const& value) {
yardl::binary::WriteVector<test_model::RecordWithMaps, test_model::binary::WriteRecordWithMaps>(stream_, value);
}

void MapsWriter::Flush() {
stream_.Flush();
}
Expand All @@ -3749,6 +3784,10 @@ void MapsReader::ReadAliasedGenericImpl(basic_types::AliasedMap<std::string, int
basic_types::binary::ReadAliasedMap<std::string, yardl::binary::ReadString, int32_t, yardl::binary::ReadInteger>(stream_, value);
}

void MapsReader::ReadRecordsImpl(std::vector<test_model::RecordWithMaps>& value) {
yardl::binary::ReadVector<test_model::RecordWithMaps, test_model::binary::ReadRecordWithMaps>(stream_, value);
}

void MapsReader::CloseImpl() {
stream_.VerifyFinished();
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/test/generated/binary/protocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ class MapsWriter : public test_model::MapsWriterBase, yardl::binary::BinaryWrite
void WriteIntToStringImpl(std::unordered_map<int32_t, std::string> const& value) override;
void WriteStringToUnionImpl(std::unordered_map<std::string, std::variant<std::string, int32_t>> const& value) override;
void WriteAliasedGenericImpl(basic_types::AliasedMap<std::string, int32_t> const& value) override;
void WriteRecordsImpl(std::vector<test_model::RecordWithMaps> const& value) override;
void CloseImpl() override;

Version version_;
Expand All @@ -980,6 +981,7 @@ class MapsReader : public test_model::MapsReaderBase, yardl::binary::BinaryReade
void ReadIntToStringImpl(std::unordered_map<int32_t, std::string>& value) override;
void ReadStringToUnionImpl(std::unordered_map<std::string, std::variant<std::string, int32_t>>& value) override;
void ReadAliasedGenericImpl(basic_types::AliasedMap<std::string, int32_t>& value) override;
void ReadRecordsImpl(std::vector<test_model::RecordWithMaps>& value) override;
void CloseImpl() override;

Version version_;
Expand Down
32 changes: 32 additions & 0 deletions cpp/test/generated/hdf5/protocols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,22 @@ struct _Inner_RecordWithUnionsOfContainers {
::InnerUnion2<yardl::hdf5::InnerDynamicNdArray<int32_t, int32_t>, yardl::DynamicNDArray<int32_t>, int32_t, int32_t> array_or_scalar;
};

struct _Inner_RecordWithMaps {
_Inner_RecordWithMaps() {}
_Inner_RecordWithMaps(test_model::RecordWithMaps const& o)
: set_1(o.set_1),
set_2(o.set_2) {
}

void ToOuter (test_model::RecordWithMaps& o) const {
yardl::hdf5::ToOuter(set_1, o.set_1);
yardl::hdf5::ToOuter(set_2, o.set_2);
}

yardl::hdf5::InnerMap<uint32_t, uint32_t, uint32_t, uint32_t> set_1;
yardl::hdf5::InnerMap<int32_t, int32_t, bool, bool> set_2;
};

template <typename _T1_Inner, typename T1, typename _T2_Inner, typename T2>
struct _Inner_GenericRecord {
_Inner_GenericRecord() {}
Expand Down Expand Up @@ -1369,6 +1385,14 @@ struct _Inner_RecordWithOptionalDate {
return t;
}

[[maybe_unused]] H5::CompType GetRecordWithMapsHdf5Ddl() {
using RecordType = test_model::hdf5::_Inner_RecordWithMaps;
H5::CompType t(sizeof(RecordType));
t.insertMember("set1", HOFFSET(RecordType, set_1), yardl::hdf5::InnerMapDdl<uint32_t, uint32_t>(H5::PredType::NATIVE_UINT32, H5::PredType::NATIVE_UINT32));
t.insertMember("set2", HOFFSET(RecordType, set_2), yardl::hdf5::InnerMapDdl<int32_t, bool>(H5::PredType::NATIVE_INT32, H5::PredType::NATIVE_HBOOL));
return t;
}

[[maybe_unused]] H5::CompType GetRecordWithNoDefaultEnumHdf5Ddl() {
using RecordType = test_model::RecordWithNoDefaultEnum;
H5::CompType t(sizeof(RecordType));
Expand Down Expand Up @@ -2771,6 +2795,10 @@ void MapsWriter::WriteAliasedGenericImpl(basic_types::AliasedMap<std::string, in
yardl::hdf5::WriteScalarDataset<yardl::hdf5::InnerMap<yardl::hdf5::InnerVlenString, std::string, int32_t, int32_t>, basic_types::AliasedMap<std::string, int32_t>>(group_, "aliasedGeneric", yardl::hdf5::InnerMapDdl<yardl::hdf5::InnerVlenString, int32_t>(yardl::hdf5::InnerVlenStringDdl(), H5::PredType::NATIVE_INT32), value);
}

void MapsWriter::WriteRecordsImpl(std::vector<test_model::RecordWithMaps> const& value) {
yardl::hdf5::WriteScalarDataset<yardl::hdf5::InnerVlen<test_model::hdf5::_Inner_RecordWithMaps, test_model::RecordWithMaps>, std::vector<test_model::RecordWithMaps>>(group_, "records", yardl::hdf5::InnerVlenDdl(test_model::hdf5::GetRecordWithMapsHdf5Ddl()), value);
}

MapsReader::MapsReader(std::string path)
: yardl::hdf5::Hdf5Reader::Hdf5Reader(path, "Maps", schema_) {
}
Expand All @@ -2791,6 +2819,10 @@ void MapsReader::ReadAliasedGenericImpl(basic_types::AliasedMap<std::string, int
yardl::hdf5::ReadScalarDataset<yardl::hdf5::InnerMap<yardl::hdf5::InnerVlenString, std::string, int32_t, int32_t>, basic_types::AliasedMap<std::string, int32_t>>(group_, "aliasedGeneric", yardl::hdf5::InnerMapDdl<yardl::hdf5::InnerVlenString, int32_t>(yardl::hdf5::InnerVlenStringDdl(), H5::PredType::NATIVE_INT32), value);
}

void MapsReader::ReadRecordsImpl(std::vector<test_model::RecordWithMaps>& value) {
yardl::hdf5::ReadScalarDataset<yardl::hdf5::InnerVlen<test_model::hdf5::_Inner_RecordWithMaps, test_model::RecordWithMaps>, std::vector<test_model::RecordWithMaps>>(group_, "records", yardl::hdf5::InnerVlenDdl(test_model::hdf5::GetRecordWithMapsHdf5Ddl()), value);
}

UnionsWriter::UnionsWriter(std::string path)
: yardl::hdf5::Hdf5Writer::Hdf5Writer(path, "Unions", schema_) {
}
Expand Down
4 changes: 4 additions & 0 deletions cpp/test/generated/hdf5/protocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ class MapsWriter : public test_model::MapsWriterBase, public yardl::hdf5::Hdf5Wr

void WriteAliasedGenericImpl(basic_types::AliasedMap<std::string, int32_t> const& value) override;

void WriteRecordsImpl(std::vector<test_model::RecordWithMaps> const& value) override;

private:
};

Expand All @@ -755,6 +757,8 @@ class MapsReader : public test_model::MapsReaderBase, public yardl::hdf5::Hdf5Re

void ReadAliasedGenericImpl(basic_types::AliasedMap<std::string, int32_t>& value) override;

void ReadRecordsImpl(std::vector<test_model::RecordWithMaps>& value) override;

private:
};

Expand Down
24 changes: 24 additions & 0 deletions cpp/test/generated/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,22 @@ class MockMapsWriter : public MapsWriterBase {
WriteAliasedGenericImpl_expected_values_.push(value);
}

void WriteRecordsImpl (std::vector<test_model::RecordWithMaps> const& value) override {
if (WriteRecordsImpl_expected_values_.empty()) {
throw std::runtime_error("Unexpected call to WriteRecordsImpl");
}
if (WriteRecordsImpl_expected_values_.front() != value) {
throw std::runtime_error("Unexpected argument value for call to WriteRecordsImpl");
}
WriteRecordsImpl_expected_values_.pop();
}

std::queue<std::vector<test_model::RecordWithMaps>> WriteRecordsImpl_expected_values_;

void ExpectWriteRecordsImpl (std::vector<test_model::RecordWithMaps> const& value) {
WriteRecordsImpl_expected_values_.push(value);
}

void Verify() {
if (!WriteStringToIntImpl_expected_values_.empty()) {
throw std::runtime_error("Expected call to WriteStringToIntImpl was not received");
Expand All @@ -2606,6 +2622,9 @@ class MockMapsWriter : public MapsWriterBase {
if (!WriteAliasedGenericImpl_expected_values_.empty()) {
throw std::runtime_error("Expected call to WriteAliasedGenericImpl was not received");
}
if (!WriteRecordsImpl_expected_values_.empty()) {
throw std::runtime_error("Expected call to WriteRecordsImpl was not received");
}
}
};

Expand Down Expand Up @@ -2641,6 +2660,11 @@ class TestMapsWriterBase : public MapsWriterBase {
mock_writer_.ExpectWriteAliasedGenericImpl(value);
}

void WriteRecordsImpl(std::vector<test_model::RecordWithMaps> const& value) override {
writer_->WriteRecords(value);
mock_writer_.ExpectWriteRecordsImpl(value);
}

void CloseImpl() override {
close_called_ = true;
writer_->Close();
Expand Down
33 changes: 33 additions & 0 deletions cpp/test/generated/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,31 @@
}
}
},
{
"record": {
"name": "RecordWithMaps",
"fields": [
{
"name": "set1",
"type": {
"map": {
"keys": "uint32",
"values": "uint32"
}
}
},
{
"name": "set2",
"type": {
"map": {
"keys": "int32",
"values": "bool"
}
}
}
]
}
},
{
"alias": {
"name": "Fruits",
Expand Down Expand Up @@ -4937,6 +4962,14 @@
"int32"
]
}
},
{
"name": "records",
"type": {
"vector": {
"items": "TestModel.RecordWithMaps"
}
}
}
]
},
Expand Down
30 changes: 30 additions & 0 deletions cpp/test/generated/ndjson/protocols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ void from_json(ordered_json const& j, test_model::RecordWithVlenCollections& val
void to_json(ordered_json& j, test_model::RecordWithUnionsOfContainers const& value);
void from_json(ordered_json const& j, test_model::RecordWithUnionsOfContainers& value);

void to_json(ordered_json& j, test_model::RecordWithMaps const& value);
void from_json(ordered_json const& j, test_model::RecordWithMaps& value);

void to_json(ordered_json& j, test_model::UInt64Enum const& value);
void from_json(ordered_json const& j, test_model::UInt64Enum& value);

Expand Down Expand Up @@ -1878,6 +1881,25 @@ void from_json(ordered_json const& j, test_model::RecordWithUnionsOfContainers&
}
}

void to_json(ordered_json& j, test_model::RecordWithMaps const& value) {
j = ordered_json::object();
if (yardl::ndjson::ShouldSerializeFieldValue(value.set_1)) {
j.push_back({"set1", value.set_1});
}
if (yardl::ndjson::ShouldSerializeFieldValue(value.set_2)) {
j.push_back({"set2", value.set_2});
}
}

void from_json(ordered_json const& j, test_model::RecordWithMaps& value) {
if (auto it = j.find("set1"); it != j.end()) {
it->get_to(value.set_1);
}
if (auto it = j.find("set2"); it != j.end()) {
it->get_to(value.set_2);
}
}

namespace {
std::unordered_map<std::string, test_model::UInt64Enum> const __UInt64Enum_values = {
{"a", test_model::UInt64Enum::kA},
Expand Down Expand Up @@ -3402,6 +3424,10 @@ void MapsWriter::WriteAliasedGenericImpl(basic_types::AliasedMap<std::string, in
ordered_json json_value = value;
yardl::ndjson::WriteProtocolValue(stream_, "aliasedGeneric", json_value);}

void MapsWriter::WriteRecordsImpl(std::vector<test_model::RecordWithMaps> const& value) {
ordered_json json_value = value;
yardl::ndjson::WriteProtocolValue(stream_, "records", json_value);}

void MapsWriter::Flush() {
stream_.flush();
}
Expand All @@ -3426,6 +3452,10 @@ void MapsReader::ReadAliasedGenericImpl(basic_types::AliasedMap<std::string, int
yardl::ndjson::ReadProtocolValue(stream_, line_, "aliasedGeneric", true, unused_step_, value);
}

void MapsReader::ReadRecordsImpl(std::vector<test_model::RecordWithMaps>& value) {
yardl::ndjson::ReadProtocolValue(stream_, line_, "records", true, unused_step_, value);
}

void MapsReader::CloseImpl() {
VerifyFinished();
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/test/generated/ndjson/protocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ class MapsWriter : public test_model::MapsWriterBase, yardl::ndjson::NDJsonWrite
void WriteIntToStringImpl(std::unordered_map<int32_t, std::string> const& value) override;
void WriteStringToUnionImpl(std::unordered_map<std::string, std::variant<std::string, int32_t>> const& value) override;
void WriteAliasedGenericImpl(basic_types::AliasedMap<std::string, int32_t> const& value) override;
void WriteRecordsImpl(std::vector<test_model::RecordWithMaps> const& value) override;
void CloseImpl() override;
};

Expand All @@ -888,6 +889,7 @@ class MapsReader : public test_model::MapsReaderBase, yardl::ndjson::NDJsonReade
void ReadIntToStringImpl(std::unordered_map<int32_t, std::string>& value) override;
void ReadStringToUnionImpl(std::unordered_map<std::string, std::variant<std::string, int32_t>>& value) override;
void ReadAliasedGenericImpl(basic_types::AliasedMap<std::string, int32_t>& value) override;
void ReadRecordsImpl(std::vector<test_model::RecordWithMaps>& value) override;
void CloseImpl() override;
};

Expand Down
Loading
Loading