core: move set_weightsystem() to weightsystem_table

Feels natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-07-01 22:55:39 +02:00 committed by bstoeger
parent 650fda3221
commit b5a4e7eb0b
3 changed files with 5 additions and 7 deletions

View file

@ -1061,7 +1061,7 @@ void EditWeight::redo()
{
for (size_t i = 0; i < dives.size(); ++i) {
add_weightsystem_description(new_ws); // This updates the weightsystem info table
set_weightsystem(dives[i], indices[i], new_ws);
dives[i]->weightsystems.set(indices[i], new_ws);
emit diveListNotifier.weightEdited(dives[i], indices[i]);
dives[i]->invalidate_cache(); // Ensure that dive is written in git_save()
}

View file

@ -318,11 +318,11 @@ void weightsystem_table::add(int idx, weightsystem_t ws)
insert(begin() + idx, std::move(ws));
}
void set_weightsystem(struct dive *dive, int idx, weightsystem_t ws)
void weightsystem_table::set(int idx, weightsystem_t ws)
{
if (idx < 0 || static_cast<size_t>(idx) >= dive->weightsystems.size())
if (idx < 0 || static_cast<size_t>(idx) >= size())
return;
dive->weightsystems[idx] = std::move(ws);
(*this)[idx] = std::move(ws);
}
/* when planning a dive we need to make sure that all cylinders have a sane depth assigned

View file

@ -70,13 +70,13 @@ struct weightsystem_t
*/
struct weightsystem_table : public std::vector<weightsystem_t> {
void add(int idx, weightsystem_t ws);
void set(int idx, weightsystem_t ws);
};
extern enum cylinderuse cylinderuse_from_text(const char *text);
extern void copy_cylinder_types(const struct dive *s, struct dive *d);
extern void remove_cylinder(struct dive *dive, int idx);
extern void remove_weightsystem(struct dive *dive, int idx);
extern void set_weightsystem(struct dive *dive, int idx, weightsystem_t ws);
extern void reset_cylinders(struct dive *dive, bool track_gas);
extern int gas_volume(const cylinder_t *cyl, pressure_t p); /* Volume in mliter of a cylinder at pressure 'p' */
extern int find_best_gasmix_match(struct gasmix mix, const struct cylinder_table &cylinders);
@ -89,8 +89,6 @@ extern int first_hidden_cylinder(const struct dive *d);
extern void dump_cylinders(struct dive *dive, bool verbose);
#endif
/* Weightsystem table functions */
/* Cylinder table functions */
extern void add_cylinder(struct cylinder_table *, int idx, cylinder_t cyl);