From 7bcc4a9ff016ad19dc607514dd5f0eedbe148b0e Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <grigpavl@ece.auth.gr>
Date: Sat, 31 Aug 2019 21:38:19 +0300
Subject: [PATCH] Move template definitions in the header file to avoid link
 errors

---
 inc/Services/Parameter.hpp | 62 +++++++++++++++++++++++++++-----------
 src/Services/Parameter.cpp | 32 --------------------
 2 files changed, 45 insertions(+), 49 deletions(-)

diff --git a/inc/Services/Parameter.hpp b/inc/Services/Parameter.hpp
index 5e90a72b..9cf9a015 100644
--- a/inc/Services/Parameter.hpp
+++ b/inc/Services/Parameter.hpp
@@ -59,29 +59,57 @@ typedef etl::bitset<NUM_OF_FLAGS> Flags;
  */
 
 class ParameterBase {
-	protected:
-		uint8_t ptc;
-		uint8_t pfc;
-		uint8_t sizeInBytes;
-		void* valuePtr;
-		Flags flags;
-	public:
-		uint8_t getPTC();
-		void setFlags(const char* flags);
-		uint8_t getPFC();
-		virtual String<MAX_STRING_LENGTH> getValueAsString() = 0;
-		template <typename ValueType> void setCurrentValue(ValueType newVal);
+protected:
+	uint8_t ptc;
+	uint8_t pfc;
+	uint8_t sizeInBytes;
+	void* valuePtr;
+	Flags flags;
+public:
+	uint8_t getPTC();
+
+	void setFlags(const char* flags);
+
+	uint8_t getPFC();
+
+	virtual String<MAX_STRING_LENGTH> getValueAsString() = 0;
+
+	template <typename ValueType>
+	void setCurrentValue(ValueType newVal) {
+		// set the value only if the parameter can be updated manually
+		if (flags[1]) {
+			*reinterpret_cast<ValueType*>(valuePtr) = newVal;
+		}
+	}
 };
 
 template <typename ValueType>
 class Parameter : public ParameterBase {
-	void(*ptr)(ValueType*);
+	void (* ptr)(ValueType*);
+
 	ValueType currentValue;
 
-	public:
-		Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue = 0,  void(*newPtr)
-		(ValueType*) = nullptr);
-		String<MAX_STRING_LENGTH> getValueAsString() override;
+public:
+	Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue = 0, void(* newPtr)(ValueType*) = nullptr) {
+		ptc = newPtc;
+		pfc = newPfc;
+		ptr = newPtr;
+		sizeInBytes = sizeof(initialValue);
+		valuePtr = static_cast<void*>(&currentValue);
+		// see Parameter.hpp for explanation on flags
+		// by default: no update priority, manual and automatic update available
+
+		if (ptr != nullptr) {
+			(*ptr)(&currentValue);  // call the update function for the initial value
+		} else {
+			currentValue = initialValue;
+		}
+	}
+
+	String<MAX_STRING_LENGTH> getValueAsString() override {
+		String<MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(&currentValue), sizeInBytes);
+		return contents;
+	}
 };
 
 
diff --git a/src/Services/Parameter.cpp b/src/Services/Parameter.cpp
index 8bf1603f..f1410d91 100644
--- a/src/Services/Parameter.cpp
+++ b/src/Services/Parameter.cpp
@@ -1,37 +1,5 @@
 #include "Services/Parameter.hpp"
 
-template <typename ValueType>
-Parameter<ValueType>::Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue, void (*
-newPtr)(ValueType*)) {
-	ptc = newPtc;
-	pfc = newPfc;
-	ptr = newPtr;
-	sizeInBytes = sizeof(initialValue);
-	valuePtr = static_cast<void *>(&currentValue);
-	// see Parameter.hpp for explanation on flags
-	// by default: no update priority, manual and automatic update available
-
-	if (ptr != nullptr) {
-		(*ptr)(&currentValue);  // call the update function for the initial value
-	} else {
-		currentValue = initialValue;
-	}
-}
-
-template <typename ValueType>
-void ParameterBase::setCurrentValue(ValueType newVal) {
-	// set the value only if the parameter can be updated manually
-	if (flags[1]) {
-		*reinterpret_cast<ValueType>(valuePtr) = newVal;
-	}
-}
-
-template <typename ValueType>
-String<MAX_STRING_LENGTH> Parameter<ValueType>::getValueAsString() {
-	String<MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(&currentValue), sizeInBytes);
-	return contents;
-}
-
 uint8_t ParameterBase::getPTC() {
 	return ptc;
 }
-- 
GitLab