From dc6f5a098026be29ec99e30cacd5ae1318e6c79d Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 7 Dec 2014 14:44:14 +0100 Subject: [PATCH] removed misleading SymbolString copy constructor --- src/lib/ebus/symbol.cpp | 12 ++++++------ src/lib/ebus/symbol.h | 14 +++++++++++--- src/lib/ebus/test/test_message.cpp | 12 ++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) mode change 100644 => 100755 src/lib/ebus/symbol.cpp diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp old mode 100644 new mode 100755 index 253236d4..49573b9f --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -60,15 +60,15 @@ SymbolString::SymbolString(const string& str) //TODO use a factory method instea push_back(m_crc, false, false); } -SymbolString::SymbolString(const SymbolString& str) - : m_unescapeState(0), m_crc(0) +SymbolString::SymbolString(const SymbolString& str, const bool escape, const bool addCrc) + : m_unescapeState(escape == true ? 0 : 1), m_crc(0) { - // escape for (size_t i = 0; i < str.size(); i++) { - push_back(str[i], false, true); + push_back(str[i], str.m_unescapeState == 0, true); } - // add CRC + escape - push_back(m_crc, false, false); + if (addCrc == true) + // add CRC + push_back(m_crc, false, false); } SymbolString::SymbolString(const string& str, bool isEscaped) diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index b90a51d8..14c2d90d 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -52,10 +52,10 @@ public: */ SymbolString(const string& str); /** - * @brief Creates a new escaped instance from an unescaped @a SymbolString and adds the calculated CRC. - * @param str the unescaped SymbolString. + * @brief Creates a new escaped or unescaped instance from another @a SymbolString and adds the calculated CRC. + * @param str the @a SymbolString top copy from. */ - SymbolString(const SymbolString& str); + SymbolString(const SymbolString& str, const bool escape, const bool addCrc=true); /** * @brief Creates a new unescaped instance from a hex string. * @param isEscaped whether the hex string is escaped and shall be unescaped. @@ -125,6 +125,14 @@ public: void clear() { m_data.clear(); m_unescapeState = m_unescapeState==0 ? 0 : 1; m_crc = 0; } private: + + /** + * @brief Hidden copy constructor. + * @param str the @a SymbolString to copy from. + */ + SymbolString(const SymbolString& str) + : m_data(str.m_data), m_unescapeState(str.m_unescapeState), m_crc(str.m_crc) {} + /** * @brief Updates the calculated CRC in @a m_crc by adding a value. * @param value the (escaped) value to add to the calculated CRC in @a m_crc. diff --git a/src/lib/ebus/test/test_message.cpp b/src/lib/ebus/test/test_message.cpp index 9c8b7cc8..febaaf19 100755 --- a/src/lib/ebus/test/test_message.cpp +++ b/src/lib/ebus/test/test_message.cpp @@ -47,10 +47,10 @@ int main() // field= name;[pos];type[;[divisor|values][;[unit][;[comment]]]] string checks[][5] = { // "message", "flags" - {"u;;first;;;fe;0700;;x;;bda", "26.10.2014", "fffe0700042610061451", "00", "p"}, - {"w;;first;;;15;b509;0400;date;;bda", "26.10.2014", "ff15b5090604002610061445", "00", "m"}, - {"r;ehp;time;;;08;b509;0d2800;;;time", "15:00:17", "ff08b509030d2800ea", "0311000f00", "m"}, - {"r;ehp;date;;;08;b509;0d2900;;;hda:3", "23.11.2014", "ff08b509030d290071", "03170b0e5a", "m"}, + {"u;;first;;;fe;0700;;x;;bda", "26.10.2014", "fffe07000426100614", "00", "p"}, + {"w;;first;;;15;b509;0400;date;;bda", "26.10.2014", "ff15b50906040026100614", "00", "m"}, + {"r;ehp;time;;;08;b509;0d2800;;;time", "15:00:17", "ff08b509030d2800", "0311000f", "m"}, + {"r;ehp;date;;;08;b509;0d2900;;;hda:3", "23.11.2014", "ff08b509030d2900", "03170b0e", "m"}, {"u;ehp;ActualEnvironmentPower;Energiebezug;;08;B509;29BA00;;s;IGN:2;;;;;s;power", "8", "1008b5090329ba00", "03ba0008", "pm"}, {"uw;ehp;test;Test;;08;B5de;ab;;;power;;;;;s;hex:1", "8;39", "1008b5de02ab08", "0139", "pm"}, {"","55.50;ok","1025b50903290000","050000780300",""}, @@ -76,8 +76,8 @@ int main() string check[5] = checks[i]; istringstream isstr(check[0]); string inputStr = check[1]; - SymbolString mstr(check[2], false); - SymbolString sstr(check[3], false); + SymbolString mstr(check[2]); + SymbolString sstr(check[3]); string flags = check[4]; bool dontMap = flags.find('m') != string::npos; bool failedCreate = flags.find('c') != string::npos;