removed misleading SymbolString copy constructor

This commit is contained in:
john30
2014-12-07 14:44:14 +01:00
parent 2663c0ca76
commit dc6f5a0980
3 changed files with 23 additions and 15 deletions
Regular → Executable
+6 -6
View File
@@ -60,15 +60,15 @@ SymbolString::SymbolString(const string& str) //TODO use a factory method instea
push_back(m_crc, false, false); push_back(m_crc, false, false);
} }
SymbolString::SymbolString(const SymbolString& str) SymbolString::SymbolString(const SymbolString& str, const bool escape, const bool addCrc)
: m_unescapeState(0), m_crc(0) : m_unescapeState(escape == true ? 0 : 1), m_crc(0)
{ {
// escape
for (size_t i = 0; i < str.size(); i++) { 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 if (addCrc == true)
push_back(m_crc, false, false); // add CRC
push_back(m_crc, false, false);
} }
SymbolString::SymbolString(const string& str, bool isEscaped) SymbolString::SymbolString(const string& str, bool isEscaped)
+11 -3
View File
@@ -52,10 +52,10 @@ public:
*/ */
SymbolString(const string& str); SymbolString(const string& str);
/** /**
* @brief Creates a new escaped instance from an unescaped @a SymbolString and adds the calculated CRC. * @brief Creates a new escaped or unescaped instance from another @a SymbolString and adds the calculated CRC.
* @param str the unescaped SymbolString. * @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. * @brief Creates a new unescaped instance from a hex string.
* @param isEscaped whether the hex string is escaped and shall be unescaped. * @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; } void clear() { m_data.clear(); m_unescapeState = m_unescapeState==0 ? 0 : 1; m_crc = 0; }
private: 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. * @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. * @param value the (escaped) value to add to the calculated CRC in @a m_crc.
+6 -6
View File
@@ -47,10 +47,10 @@ int main()
// field= name;[pos];type[;[divisor|values][;[unit][;[comment]]]] // field= name;[pos];type[;[divisor|values][;[unit][;[comment]]]]
string checks[][5] = { string checks[][5] = {
// "message", "flags" // "message", "flags"
{"u;;first;;;fe;0700;;x;;bda", "26.10.2014", "fffe0700042610061451", "00", "p"}, {"u;;first;;;fe;0700;;x;;bda", "26.10.2014", "fffe07000426100614", "00", "p"},
{"w;;first;;;15;b509;0400;date;;bda", "26.10.2014", "ff15b5090604002610061445", "00", "m"}, {"w;;first;;;15;b509;0400;date;;bda", "26.10.2014", "ff15b50906040026100614", "00", "m"},
{"r;ehp;time;;;08;b509;0d2800;;;time", "15:00:17", "ff08b509030d2800ea", "0311000f00", "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", "ff08b509030d290071", "03170b0e5a", "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"}, {"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"}, {"uw;ehp;test;Test;;08;B5de;ab;;;power;;;;;s;hex:1", "8;39", "1008b5de02ab08", "0139", "pm"},
{"","55.50;ok","1025b50903290000","050000780300",""}, {"","55.50;ok","1025b50903290000","050000780300",""},
@@ -76,8 +76,8 @@ int main()
string check[5] = checks[i]; string check[5] = checks[i];
istringstream isstr(check[0]); istringstream isstr(check[0]);
string inputStr = check[1]; string inputStr = check[1];
SymbolString mstr(check[2], false); SymbolString mstr(check[2]);
SymbolString sstr(check[3], false); SymbolString sstr(check[3]);
string flags = check[4]; string flags = check[4];
bool dontMap = flags.find('m') != string::npos; bool dontMap = flags.find('m') != string::npos;
bool failedCreate = flags.find('c') != string::npos; bool failedCreate = flags.find('c') != string::npos;