Since all code can now directly access C++ structures these
accessor functions were not necessary.
Split out the table from the filterconstraint source file
and include it directly into the divelog.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Having this as a pointer is an artifact from the C/C++ split.
The triptable header is small enough so that we can
include it directly
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Having this as a pointer is an artifact from the C/C++ split.
The divesitetable header is small enough so that we can
include it directly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Not strictly necessary, but a "natural" thing to do in a classical
C++ code base.
Move the tiny trip-table into its own source file, since it also
has its own header.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is a humongous commit, because it touches all parts of the
code. It removes the last user of our horrible TABLE macros, which
simulate std::vector<> in a very clumsy way.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Nothing against free-standing functions, but in the case
of dc_watertemp(), dc_airtemp(), endtime() and totaltime(),
it seems natural to move this into the dive class and avoid
polution of the global name space.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since the sorted_owning_table depends on the fact that
different elements never compare as equal, make the
comparison function safer in that respect. If all failes,
compare the pointers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This had to be done simultaneously, because the table macros
do not work properly with C++ objects.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since struct divecomputer is now fully C++ (i.e. cleans up
after itself), we can simply turn the list of divecomputers
into an std::vector<>. This makes the code quite a bit simpler,
because the first divecomputer was actually a subobject.
Yes, this makes the common case of a single divecomputer a
little bit less efficient, but it really shouldn't matter.
If it does, we can still write a special std::vector<>-
like container that keeps the first element inline.
This change makes pointers-to-divecomputers not stable.
So always access the divecomputer via its index. As
far as I can tell, most of the code already does this.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Not strictly necessary, but more idiomatic C++ and less
polution of the global namespace. This one is so trivial
that there seems to be no reason not to do it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is a rather long commit, because it refactors lots of the event
code from pointer to value semantics: pointers to entries in an
std::vector<> are not stable, so better use indexes.
To step through the event-list at diven time stamps, add *_loop classes,
which encapsulate state that had to be manually handled before by
the caller. I'm not happy about the interface, but it tries to
mirror the one we had before.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is a hairy one, because the sample code is rather tricky.
There was a pattern of looping through pairs of adjacent samples,
for interpolation purposes. Add an range adapter to generalize
such loops.
Removes the finish_sample() function: The code would call
prepare_sample() to start parsing of samples and then
finish_sample() to actuall add it. I.e. a kind of commit().
Since, with one exception, all users of prepare_sample()
called finish_sample() in all code paths, we might just add
the sample in the first place. The exception was sample_end()
in parse.cpp. This brings a small change: samples are now
added, even if they could only be parsed partially. I doubt
that this makes any difference, since it will only happen
for broken divelogs anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since everything is C++ now, we can use unique_ptr<>s. This makes
the code significantly shorter, because we can now use the default
move constructor and assignment operators.
This has a semantic change when std::move()-ing the divelog:
now not the contents of the tables are moved, but the pointers.
That is, the moved-from object now has no more tables and
must not be used anymore. This made it necessary to replace
std::move()s by std::swap()s. In that regard, the old code was
in principle broken: it used moved-from objects, which may work
but usually doesn't.
This commit adds a myriad of .get() function calls where the code
expects a C-style pointer. The plan is to remove virtually all of
them, when we move free-standing functions into the class it acts
on. Or, replace C-style pointers by references where we don't support
NULL.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is a long commit, because it introduces a new abstraction:
a general std::vector<> of std::unique_ptrs<>.
Moreover, it replaces a number of pointers by C++ references,
when the callee does not suppoert null objects.
This simplifies memory management and makes ownership more
explicit. It is a proof-of-concept and a test-bed for
the other core data structrures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This the C++ version of membuffer. Since everything is C++, it can
just be made the default.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since this is now in C++, we don't have to use our crazy
TABLE_* macros.
This contains a logic change: the dives associated to a
dive site are now unsorted.
The old code was subtly buggy: dives were added in a sorted
manner, but when the dive was edited the list was not
resorted. Very unlikely that this leads to a serious
problem, still not good.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Allows us to remove the strndup.h header. This code will be
even more simple, once core is fully converted away from C-strings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The old code was leaking memory. Use std::unique_ptr<> for
ownership management.
This is still very primitive and divetags are kept during
application lifetime. There should probably be some form
of reference counting. And the taglist should not be global,
but attached to the divelog.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Quite a bit of fallout in users of this structure.
Conveniently, since git-access.cpp is now C++ we can move
some helpers from the monstrous qthelper.cpp to git-access.cpp.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Remove the options to expand entities and so continue when encountering invalid /
malformed XML, as both of these can be exploited by supplying
maliciously crafted XML.
Signed-off-by: Michael Keller <mikeller@042.ch>
Return an std::string to avoid memory management headaches.
While doing that, convert time.c to C++ so that
format_datetime directly returns an std::string.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This includes using the C++ version of membuffer. There appears
to not have been a leak, because the buffer is freed in
flush_buffer(), but usage was somewhat inconsistent and hard to
follow.
Also, convert some string handling to std::string to avoid free()
madness.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>