mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-11 03:21:29 +00:00
3f8b4604be
Since the taxonomy is now a real C++ struct with constructor and destructor, dive_site has to be converted to C++ as well. A bit hairy for now, but will ultimately be distinctly simpler. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
// Convenience classes defining owning pointers to C-objects that
|
|
// automatically clean up the objects if the pointers go out of
|
|
// scope. Based on unique_ptr<>.
|
|
// In the future, we should replace these by real destructors.
|
|
#ifndef OWNING_PTR_H
|
|
#define OWNING_PTR_H
|
|
|
|
#include <memory>
|
|
#include <cstdlib>
|
|
|
|
struct dive;
|
|
struct dive_trip;
|
|
struct dive_site;
|
|
struct event;
|
|
|
|
extern "C" void free_dive(struct dive *);
|
|
extern "C" void free_trip(struct dive_trip *);
|
|
|
|
// Classes used to automatically call the appropriate free_*() function for owning pointers that go out of scope.
|
|
struct DiveDeleter {
|
|
void operator()(dive *d) { free_dive(d); }
|
|
};
|
|
struct TripDeleter {
|
|
void operator()(dive_trip *t) { free_trip(t); }
|
|
};
|
|
struct EventDeleter {
|
|
void operator()(event *ev) { free(ev); }
|
|
};
|
|
|
|
// Owning pointers to dive, dive_trip, dive_site and event objects.
|
|
using OwningDivePtr = std::unique_ptr<dive, DiveDeleter>;
|
|
using OwningTripPtr = std::unique_ptr<dive_trip, TripDeleter>;
|
|
using OwningEventPtr = std::unique_ptr<event, EventDeleter>;
|
|
|
|
#endif
|