core: introduce set_cylinder() function

We have a set_weightsystem() function. For symmetry, introduce
a set_cylinder() function so that we can more-or-less copy&paste
the weightsystem undo code for cylinder undo.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-02-23 11:38:53 +01:00
parent 1ca25ec039
commit f1e08fd470
2 changed files with 10 additions and 0 deletions

View file

@ -291,6 +291,15 @@ void remove_cylinder(struct dive *dive, int idx)
remove_from_cylinder_table(&dive->cylinders, idx);
}
// cyl is cloned.
void set_cylinder(struct dive *dive, int idx, cylinder_t cyl)
{
if (idx < 0 || idx >= dive->cylinders.nr)
return;
free_cylinder(dive->cylinders.cylinders[idx]);
dive->cylinders.cylinders[idx] = clone_cylinder(cyl);
}
void remove_weightsystem(struct dive *dive, int idx)
{
remove_from_weightsystem_table(&dive->weightsystems, idx);

View file

@ -86,6 +86,7 @@ extern void add_weightsystem_description(const weightsystem_t *);
extern bool same_weightsystem(weightsystem_t w1, weightsystem_t w2);
extern bool same_cylinder(cylinder_t cyl1, cylinder_t cyl2);
extern void remove_cylinder(struct dive *dive, int idx);
extern void set_cylinder(struct dive *dive, int idx, cylinder_t ws);
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);