diff options
author | Tomaz Canabrava <tomaz.canabrava@gmail.com> | 2016-03-06 19:40:57 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-03-07 11:13:11 -0800 |
commit | f25dce8511e96e2bda65bd545f74887606152b5e (patch) | |
tree | 06645580c52624f6b86e212282c53b2d2bea092e | |
parent | 2745beca5fd75e073023806189f4fd00774646e2 (diff) | |
download | subsurface-f25dce8511e96e2bda65bd545f74887606152b5e.tar.gz |
Create a constructor with default parameters for some structs
Structs and classes in C++ are basically the same thing and we want to
create a few zero-initialized values for some of them; Sadly, C++ doesn't
have the nice static struct initialization that C has.
One way to deal with that is to create a constructor and pass default
values to it, another is lambda-initialization, but we don't use C++11,
yet.
Since we initializate stuff on the constructor, we don't need to
re-initializate things again on the initialization list (which is also why
I removed the QStrings from the initialization lists, they are
automatically initialized to empty)
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | subsurface-core/configuredivecomputerthreads.cpp | 20 | ||||
-rw-r--r-- | subsurface-core/devicedetails.cpp | 31 | ||||
-rw-r--r-- | subsurface-core/devicedetails.h | 2 |
3 files changed, 16 insertions, 37 deletions
diff --git a/subsurface-core/configuredivecomputerthreads.cpp b/subsurface-core/configuredivecomputerthreads.cpp index 27074c9dc..b229fc808 100644 --- a/subsurface-core/configuredivecomputerthreads.cpp +++ b/subsurface-core/configuredivecomputerthreads.cpp @@ -1131,37 +1131,27 @@ static dc_status_t read_ostc_settings(dc_device_t *device, DeviceDetails *m_devi // Diluent 1 Default (%O2,%He) // Byte98-99: // Diluent 1 Current (%O2,%He) - gas dil1 = {}; - dil1.oxygen = data[97]; - dil1.helium = data[98]; + gas dil1(data[97], data[98]); // Byte100-101: // Gasuent 2 Default (%O2,%He) // Byte102-103: // Gasuent 2 Current (%O2,%He) - gas dil2 = {}; - dil2.oxygen = data[101]; - dil2.helium = data[102]; + gas dil2(data[101], data[102]); // Byte104-105: // Gasuent 3 Default (%O2,%He) // Byte106-107: // Gasuent 3 Current (%O2,%He) - gas dil3 = {}; - dil3.oxygen = data[105]; - dil3.helium = data[106]; + gas dil3(data[105], data[106]); // Byte108-109: // Gasuent 4 Default (%O2,%He) // Byte110-111: // Gasuent 4 Current (%O2,%He) - gas dil4 = {}; - dil4.oxygen = data[109]; - dil4.helium = data[110]; + gas dil4(data[109], data[110]); // Byte112-113: // Gasuent 5 Default (%O2,%He) // Byte114-115: // Gasuent 5 Current (%O2,%He) - gas dil5 = {}; - dil5.oxygen = data[113]; - dil5.helium = data[114]; + gas dil5(data[113], data[114]); // Byte116: // First Diluent (1-5) switch (data[115]) { diff --git a/subsurface-core/devicedetails.cpp b/subsurface-core/devicedetails.cpp index a2da0d5bc..a917a4d0e 100644 --- a/subsurface-core/devicedetails.cpp +++ b/subsurface-core/devicedetails.cpp @@ -1,32 +1,19 @@ #include "devicedetails.h" -// This can probably be done better by someone with better c++-FU -const struct gas zero_gas = {0}; -const struct setpoint zero_setpoint = {0}; +gas::gas(unsigned char oxygen, unsigned char helium, unsigned char type, unsigned char depth) : + oxygen(oxygen), helium(helium), type(type), depth(depth) +{ +} + +setpoint::setpoint(unsigned char sp, unsigned char depth) : + sp(sp), depth(depth) +{ +} DeviceDetails::DeviceDetails(QObject *parent) : QObject(parent), data(0), - serialNo(""), - firmwareVersion(""), - customText(""), - model(""), syncTime(false), - gas1(zero_gas), - gas2(zero_gas), - gas3(zero_gas), - gas4(zero_gas), - gas5(zero_gas), - dil1(zero_gas), - dil2(zero_gas), - dil3(zero_gas), - dil4(zero_gas), - dil5(zero_gas), - sp1(zero_setpoint), - sp2(zero_setpoint), - sp3(zero_setpoint), - sp4(zero_setpoint), - sp5(zero_setpoint), setPointFallback(0), ccrMode(0), calibrationGas(0), diff --git a/subsurface-core/devicedetails.h b/subsurface-core/devicedetails.h index b5e59afe8..ff3009bc5 100644 --- a/subsurface-core/devicedetails.h +++ b/subsurface-core/devicedetails.h @@ -10,11 +10,13 @@ struct gas { unsigned char helium; unsigned char type; unsigned char depth; + gas(unsigned char oxygen = 0, unsigned char helium = 0, unsigned char type = 0, unsigned char depth = 0); }; struct setpoint { unsigned char sp; unsigned char depth; + setpoint(unsigned char sp = 0, unsigned char depth = 0); }; class DeviceDetails : public QObject |