From dd87a04515094bdbfa4bfecc6c0e1d07857f41cd Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Date: Sun, 6 Mar 2016 19:40:57 -0300
Subject: [PATCH 02/10] Create a constructor with default parameters to some
 Structs

Since structs and classes in c++ are basically the same thing
and we wanted to create a few zero-initialized values from some
of them, and 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
(wich 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>
---
 subsurface-core/devicedetails.cpp | 31 +++++++++----------------------
 subsurface-core/devicedetails.h   |  2 ++
 2 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/subsurface-core/devicedetails.cpp b/subsurface-core/devicedetails.cpp
index a2da0d5..07f17b2 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 b5e59af..ff3009b 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
-- 
2.5.4 (Apple Git-61)

