added getDayName(), formatting

This commit is contained in:
john30
2017-02-19 11:37:09 +01:00
parent cfe66cbf6f
commit 1fd682ba51
2 changed files with 15 additions and 1 deletions
+9 -1
View File
@@ -264,6 +264,13 @@ void DataField::dumpString(ostream& output, const string str, const bool prepend
}
}
string DataField::getDayName(int day) {
if (day < 0 || day > 6) {
return "";
}
return dayNames[day];
}
result_t SingleDataField::create(const string id, const unsigned char length,
const string name, const string comment, const string unit,
const PartType partType, int divisor, map<unsigned int, string> values,
@@ -300,8 +307,9 @@ result_t SingleDataField::create(const string id, const unsigned char length,
if (dataType->isNumeric()) {
NumberDataType* numType = reinterpret_cast<NumberDataType*>(dataType);
if (values.empty() && numType->hasFlag(DAY)) {
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++) {
values[numType->getMinValue() + i] = dayNames[i];
}
}
result_t result = numType->derive(divisor, bitCount, numType);
if (result != RESULT_OK) {
+6
View File
@@ -102,6 +102,12 @@ class DataField {
*/
static void dumpString(ostream& output, const string str, const bool prependFieldSeparator = true);
/**
* Return the name of the specified day.
* @return the name of the specified day.
*/
static string getDayName(int day);
/**
* Returns the length of this field (or contained fields) in bytes.
* @param partType the message part of the contained fields to limit the length calculation to.