extendd getName with optional field index

This commit is contained in:
john30
2017-01-08 12:07:11 +01:00
parent 42a5d1d0c3
commit 41ac7a5591
2 changed files with 26 additions and 5 deletions
+19 -2
View File
@@ -803,6 +803,22 @@ unsigned char DataFieldSet::getLength(PartType partType, unsigned char maxLength
return length;
}
string DataFieldSet::getName(signed char fieldIndex)
{
if (fieldIndex<0) {
return m_name;
}
if ((unsigned char)fieldIndex>=m_fields.size()) {
return "";
}
if (m_uniqueNames) {
return m_fields[fieldIndex]->getName();
}
ostringstream ostream;
ostream << static_cast<signed>(fieldIndex);
return ostream.str();
}
result_t DataFieldSet::derive(string name, string comment,
string unit, const PartType partType,
int divisor, map<unsigned int, string> values,
@@ -835,10 +851,11 @@ void DataFieldSet::dump(ostream& output)
{
bool first = true;
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
if (first)
if (first) {
first = false;
else
} else {
output << FIELD_SEPARATOR;
}
(*it)->dump(output);
}
}
+7 -3
View File
@@ -128,10 +128,11 @@ public:
vector<SingleDataField*>& fields) = 0;
/**
* Get the field name.
* @return the field name.
* Get the specified field name.
* @param fieldIndex the index of the field, or -1 for this.
* @return the field name, or the index as string if not unique or not available.
*/
string getName() const { return m_name; }
virtual string getName(signed char fieldIndex=-1) const { return m_name; }
/**
* Get the field comment.
@@ -549,6 +550,9 @@ public:
// @copydoc
virtual unsigned char getLength(PartType partType, unsigned char maxLength=MAX_LEN);
// @copydoc
virtual string getName(signed char fieldIndex=-1);
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType,