Feels natural in a C++ code base.
Change the function to return a weight_t. Sadly, use of the
units.h types is very inconsistent and many parts of the code
use int or double instead. So let's try to make this consistent.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It is unclear why this was declared in divelist.h.
Moreover, rename it to get_maximal_gas() to better reflect
what it does.
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>
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>
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>
Mostly irrelevant std::move() stuff of copy-on-write Qt objects,
a few real bugs, a timestamp_t downconversion and some codingsyle
adaptation.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Unfortunately Coverity doesn't understand that most Qt data
structures are copy-on-write. It's a mis-feature of Qt, but
it is the way it is. Thus, passing by value is not an issue.
Out of ca. 25 warnings only two were legit. Let's silence
the others by either std::move()ing or passing by reference,
as would be idiomatic C++, which Qt is not.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In general, replace "dive master" by "dive guide".
However, do not change written dive logs for now. On reading,
accept both versions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We have a dive-site variable, therefore we probably should also
have a dive-trip variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
'constexpr' implies 'const' since it is a stronger guarantee,
so let's remove the redundant 'const'.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
And while doing that, have all the cases where we already include
qthelper.h simply use a define in that header file - but keep the two
other instances of the define where the C++ source don't need qthelper.h
otherwise.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Air is a special gas that does not contain oxygen according
to gasmix.o2.fraction. If you want to use the fo2, you
need to use get_o2() to treat this special case correctly.
This fixes a bug when setting the MND of a gas containing
21% oxygen when o2 is considered not narcotic.
Reported-by: Christoph Gruen <gruen.christoph@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
To make box-and-whiskers charts selectable (select corresponding
dives when clicking on box), save the dive list with the quartile
data.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If we want to make bar charts selectable (when clicking on a
bar select the dives the bar represents), then we must store
the dives behind bars. Therefore, use dive-based bins instead
of count based bins in bar charts and pie charts. This gave
some churn because every structure where a count is stored
has to be changed to store a vector of dives. Try to use
move semantics where possible to avoid duplication of dive
lists.
On a positive note, the count_dives() function of the
binners can now be removed, since it is unused.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The people binner (called "buddies") is too coarse. Split into
buddies, dive guide and people (the old "buddies", which is
a combination of buddies and dive guide).
Reported-by: Peter Zaal <peter.zaal@gmail.com>
Reported-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Copy&paste error: the 20 m binner binned to 10 m.
Reported-by: Peter Zaal <peter.zaal@gmail.com>
Reported-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When calculating the quartiles, we need the count of dives
anyway, which makes it trivial to export this value to
the frontend.
Fixes an erroneous "mean", which should be "median".
Suggested-by: Peter Zaal <peter.zaal@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive sites where sorted by location in RAM, which is just
silly. Add a DiveSiteWrapper that sorts by name, though that
should probably be improved.
Suggested-by: Peter Zaal <peter.zaal@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This makes sense and is easy to implement.
Suggested-by: Peter Zaal <peter.zaal@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was requested on the mailing list and it makes sense to
have it. Of course, not all charts make sense: e.g. a plot dive-#
vs. count is a bit redundant...
Sadly, this can't use the generic IntRangeBinner, because dive-#s
start at 1, not 0.
Suggested-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was requested on the mailing list. Reduce code size somewhat
by deriving the binner and the variable classes from common
base classes with a mean-vs-max flag.
Suggested-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The StatisticVariable class hierarchy encapsulates the concept
of a dive-variable, which can be plotted in charts either as
dependend or independend variable.
There are three types of these variables:
1) discrete: For example dive buddies or suit type.
2) continuous: Has a notion of linear metric - can be
used as histogram or scatter plot axis.
3) numeric: Like continuous, but allows for operations
such as calculating the mean or the sum over numerous
dives.
All variables support binning. The bins are defined per
variable.
Continuous variables can be converted into an arbitrary
double value, which is used to be plotted on a continuous
axis.
Moreover, numeric variables support a number of operations,
which depend on the variable.
Since binning is based on different types, the code is rather
template-heavy. Of course, this could be solved with
unions/variants and runtime-polymorphism, but using templates
was just much quicker. Notably, this uses the CRTP
(curiously recurring template pattern) where a subclass
passes itself as argument to the baseclass. This is a weird
kind of "reverse inheritance".
The StatsTranslations class is a dummy class which will
be used to collect all translations of the statistics
module.
This includes changes by Dirk to fix compilation of the
downloader.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>