There were a number of free standing functions acting on a
dive-site-table. Make them member functions. This allows
for shorter names. Use the get_idx() function of the base
class, which returns a size_t instead of an int (since that
is what the standard, somewhat unfortunately, uses).
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>
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>
To my understanding, declaring empty parameter lists using "(void)"
is an artifact from the bad old K&R times, when functions were
declared without(!) parameters. Which in hindsight was an absolute
recipe for disaster. So for backwards compatibility, functions
without parameters had to be declared using "(void)" as "()"
could also mean "any function".
That was 40 years ago. Meanwhile, C++ introduced references,
which made it a necessity to declare the function parameters.
So "(void)" is redundant and inconsistent in C++ code and
just makes no sense.
Remove it.
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>
Fix loading of the negation of filter conditions. Unlike other
conditions that are persisted as `<key>="<value>"`, this is persisted
to git as `negate`.
This fix remediates this for all cases where the condition has already
been saved to the cloud storage.
Saving to XML takes a different approach and indicates negated
conditions with `negate="1"`, making it identical to all other
attributes. The question is if this approach should be implemented in
addition to the above fix, in order to unify the storage format.
Fixes#4246.
Signed-off-by: Michael Keller <github@ike.ch>
Had to rewrite the thing, because gcc's warnings don't work
with templatized var-args. Since there is no string-format.cpp
and I didn't want to inline it, moved it to format.cpp.
String formatting is distributed around at least four
headers: membuffer.h, subsurface-string.h, format.h
and format-string.h. This really should be unified!
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>
There was a pattern of code like
match_action(line, state, dive_action, ARRAY_SIZE(dive_action));
The doubling of the array might cause copy & paste errors, where
only one array is replaced.
Therefore, determine the length of the array with (hopefully
easily understood) template tricksery.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When iterating over the converted strings of a line, the
first entry of the array would be popped off, leading to
a full copy of the remaining array.
Instead, use an index in the parser state.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The converted strings were stored in a membuffer and later
converted to std::strings. Generate an std::string directly
to avoid unnecessary copying.
Ultimately, when the core structures are converted to
std::string, there should be no copying of the string data
at all (unless formatting is applied or small string
optimization kicks in, of course).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Make the memory management easier to follow. I feel that the old
code was leaking left and right, but not sure because it was so
intractable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Simplifies memory management. Think about unglobalizing this,
once everything is in C++ so that we can put an std::string
into struct divelog.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>