summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/dive.h2
-rw-r--r--core/divelist.c41
-rw-r--r--core/divelist.h5
3 files changed, 29 insertions, 19 deletions
diff --git a/core/dive.h b/core/dive.h
index aa37eeb46..07223322f 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -418,8 +418,6 @@ extern void add_dive_to_trip(struct dive *, dive_trip_t *);
struct dive *unregister_dive(int idx);
extern void delete_single_dive(int idx);
-extern int dive_get_insertion_index(struct dive *dive);
-extern void add_single_dive(int idx, struct dive *dive);
extern void insert_trip(dive_trip_t *trip);
extern void unregister_trip(dive_trip_t *trip);
diff --git a/core/divelist.c b/core/divelist.c
index 52c724429..986257c4f 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -30,6 +30,7 @@
* dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *trip_b)
* struct dive *unregister_dive(int idx)
* void delete_single_dive(int idx)
+ * void add_dive_to_table(struct dive_table *table, int idx, struct dive *dive)
* void add_single_dive(int idx, struct dive *dive)
* struct dive *merge_two_dives(struct dive *a, struct dive *b)
* void select_dive(struct dive *dive)
@@ -1111,36 +1112,44 @@ struct dive **grow_dive_table(struct dive_table *table)
}
/* get the index where we want to insert the dive so that everything stays
- * ordered reverse-chronologically */
-int dive_get_insertion_index(struct dive *dive)
+ * ordered according to dive_less_than() */
+int dive_get_insertion_index(struct dive_table *table, struct dive *dive)
{
/* we might want to use binary search here */
- for (int i = 0; i < dive_table.nr; i++) {
- if (dive->when <= dive_table.dives[i]->when)
+ for (int i = 0; i < table->nr; i++) {
+ if (dive_less_than(dive, table->dives[i]))
return i;
}
- return dive_table.nr;
+ return table->nr;
}
-/* add a dive at the given index. if the index is negative, the dive will
- * be added according to reverse chronological order */
-void add_single_dive(int idx, struct dive *dive)
+/* add a dive at the given index to a dive table. if the index is negative,
+ * the dive will be added according to dive_less_than() order */
+void add_dive_to_table(struct dive_table *table, int idx, struct dive *dive)
{
int i;
if (idx < 0)
- idx = dive_get_insertion_index(dive);
- grow_dive_table(&dive_table);
- dive_table.nr++;
- if (dive->selected)
- amount_selected++;
+ idx = dive_get_insertion_index(table, dive);
+ grow_dive_table(table);
+ table->nr++;
- for (i = idx; i < dive_table.nr; i++) {
- struct dive *tmp = dive_table.dives[i];
- dive_table.dives[i] = dive;
+ for (i = idx; i < table->nr; i++) {
+ struct dive *tmp = table->dives[i];
+ table->dives[i] = dive;
dive = tmp;
}
}
+/* add a dive at the given index in the global dive table and keep track
+ * of the number of selected dives. if the index is negative, the dive will
+ * be added according to dive_less_than() order */
+void add_single_dive(int idx, struct dive *dive)
+{
+ add_dive_to_table(&dive_table, idx, dive);
+ if (dive->selected)
+ amount_selected++;
+}
+
bool consecutive_selected()
{
struct dive *d;
diff --git a/core/divelist.h b/core/divelist.h
index 94774616e..f98587cff 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -22,7 +22,10 @@ extern void process_loaded_dives();
extern void process_imported_dives(struct dive_table *import_table, bool prefer_imported, bool downloaded);
extern char *get_dive_gas_string(const struct dive *dive);
-struct dive **grow_dive_table(struct dive_table *table);
+extern struct dive **grow_dive_table(struct dive_table *table);
+extern int dive_get_insertion_index(struct dive_table *table, struct dive *dive);
+extern void add_dive_to_table(struct dive_table *table, int idx, struct dive *dive);
+extern void add_single_dive(int idx, struct dive *dive);
extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p);
extern int get_divenr(const struct dive *dive);
extern int get_divesite_idx(const struct dive_site *ds);