Skip to content

Commit

Permalink
avoid class member with same name as base class
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-h committed Mar 8, 2024
1 parent 202f4ee commit 36c69d2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions libsave/include/SatisfactorySave/GameTypes/Sets/Base/SetImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ namespace SatisfactorySave {
v.visit(static_cast<Impl&>(*this));
}

std::vector<T> Set;
std::vector<T> Values;
};

template<typename Impl, typename T>
class SetImplBase<Impl, std::unique_ptr<T>> : public Set {
public:
SetImplBase() = default;

SetImplBase(const SetImplBase& other) : ::SatisfactorySave::Set(other) {
Set.reserve(other.Set.size());
for (const auto& s : other.Set) {
Set.push_back(std::move(s->clone()));
SetImplBase(const SetImplBase& other) : Set(other) {
Values.reserve(other.Values.size());
for (const auto& s : other.Values) {
Values.push_back(std::move(s->clone()));
}
}

SetImplBase& operator=(const SetImplBase& other) {
if (this != &other) {
Set::operator=(other);
Set.clear();
Set.reserve(other.Set.size());
for (const auto& s : other.Set) {
Set.push_back(std::move(s->clone()));
Values.clear();
Values.reserve(other.Values.size());
for (const auto& s : other.Values) {
Values.push_back(std::move(s->clone()));
}
}
return *this;
Expand All @@ -56,14 +56,14 @@ namespace SatisfactorySave {
v.visit(static_cast<Impl&>(*this));
}

std::vector<std::unique_ptr<T>> Set;
std::vector<std::unique_ptr<T>> Values;
};

template<typename Impl, typename T>
class SetImpl : public SetImplBase<Impl, T> {
public:
void serialize(Archive& ar) override {
ar << this->Set;
ar << this->Values;
}
};
} // namespace SatisfactorySave
6 changes: 3 additions & 3 deletions libsave/src/GameTypes/Sets/StructSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ void SatisfactorySave::StructSet::serialize(Archive& ar) {
const auto count = inAr.read<int32_t>();

for (int32_t i = 0; i < count; i++) {
Set.emplace_back(Struct::create(struct_name_, inAr));
Values.emplace_back(Struct::create(struct_name_, inAr));
}
} else {
auto& outAr = dynamic_cast<OStreamArchive&>(ar);

outAr.write(static_cast<int32_t>(Set.size()));
outAr.write(static_cast<int32_t>(Values.size()));

for (auto& s : Set) {
for (auto& s : Values) {
outAr << *s;
}
}
Expand Down
4 changes: 2 additions & 2 deletions libsavepy/GameTypes/Sets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ void init_GameTypes_Sets(py::module_& m) {

py::class_<s::StructSet, s::Set>(m, "StructSet")
.def(py::init<s::FName>())
.def_readonly("Set", &s::StructSet::Set) // TODO write
.def_readonly("Values", &s::StructSet::Values) // TODO write
.def_property_readonly("structName",
[](s::StructSet& s) -> const s::FName& { return s.getStructName(); });

py::class_<s::UInt32Set, s::Set>(m, "UInt32Set")
.def(py::init<>())
.def_readwrite("Set", &s::UInt32Set::Set);
.def_readwrite("Values", &s::UInt32Set::Values);
}
8 changes: 4 additions & 4 deletions map/src/MapWindow/UI/PropertyTableGuiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,19 @@ namespace {
ImGui::Text("%s", s.getStructName().toString().c_str());
StructValueGuiRenderer r(callback_);
if (tableHead()) {
for (std::size_t i = 0; i < s.Set.size(); i++) {
for (std::size_t i = 0; i < s.Values.size(); i++) {
tableIndexCol(i);
s.Set[i]->accept(r);
s.Values[i]->accept(r);
}
ImGui::EndTable();
}
}

void visit(SatisfactorySave::UInt32Set& s) override {
if (tableHead()) {
for (std::size_t i = 0; i < s.Set.size(); i++) {
for (std::size_t i = 0; i < s.Values.size(); i++) {
tableIndexCol(i);
ImGui::Text("%" PRIu32, s.Set[i]);
ImGui::Text("%" PRIu32, s.Values[i]);
}
ImGui::EndTable();
}
Expand Down

0 comments on commit 36c69d2

Please sign in to comment.