mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
408b31b6ce
Makes the code much nicer to read. Default initialize cylinder_t to the empty cylinder. This produces lots of warnings, because most structure are now not PODs anymore and shouldn't be erased using memset(). These memset()s will be removed one-by-one and replaced by proper constructors. The whole ordeal made it necessary to add a constructor to struct event. To simplify things the whole optimization of the variable-size event names was removed. In upcoming commits this will be replaced by std::string anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
32 lines
928 B
C++
32 lines
928 B
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;
|
|
|
|
void free_dive(struct dive *);
|
|
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); }
|
|
};
|
|
|
|
// 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>;
|
|
|
|
#endif
|