removed unncessary casts, allow more than one file to match, compiler warnings
This commit is contained in:
@@ -81,7 +81,7 @@ result_t TemParamDataType::readSymbols(size_t offset, size_t length, const Symbo
|
||||
if (outputFormat & OF_JSON) {
|
||||
*output << '"';
|
||||
}
|
||||
*output << setfill('0') << setw(2) << dec << static_cast<int>(grp) << '-' << setw(3) << static_cast<int>(num);
|
||||
*output << setfill('0') << setw(2) << dec << grp << '-' << setw(3) << num;
|
||||
if (outputFormat & OF_JSON) {
|
||||
*output << '"';
|
||||
}
|
||||
@@ -92,7 +92,7 @@ result_t TemParamDataType::readSymbols(size_t offset, size_t length, const Symbo
|
||||
result_t TemParamDataType::writeSymbols(const size_t offset, const size_t length, istringstream* input,
|
||||
SymbolString* output, size_t* usedLength) const {
|
||||
unsigned int value;
|
||||
int grp, num;
|
||||
unsigned int grp, num;
|
||||
|
||||
if (input->str() == NULL_VALUE) {
|
||||
value = m_replacement; // replacement value
|
||||
@@ -122,7 +122,7 @@ result_t TemParamDataType::writeSymbols(const size_t offset, const size_t length
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) {
|
||||
if (grp > 0x1f || num > 0x7f) {
|
||||
return RESULT_ERR_OUT_OF_RANGE; // value out of range
|
||||
}
|
||||
if (output->isMaster()) {
|
||||
|
||||
@@ -193,12 +193,11 @@ result_t DataField::create(bool isWriteMessage, bool isTemplate, bool isBroadcas
|
||||
*errorDescription = "no fields";
|
||||
return RESULT_ERR_EOF;
|
||||
}
|
||||
size_t fieldIndex = -1;
|
||||
size_t fieldIndex = 0;
|
||||
for (auto& row : *rows) {
|
||||
if (result != RESULT_OK) {
|
||||
break;
|
||||
}
|
||||
fieldIndex++;
|
||||
const string name = pluck("name", &row);
|
||||
PartType partType;
|
||||
bool hasPart = false;
|
||||
@@ -377,6 +376,7 @@ result_t DataField::create(bool isWriteMessage, bool isTemplate, bool isBroadcas
|
||||
}
|
||||
firstType = false;
|
||||
}
|
||||
fieldIndex++;
|
||||
}
|
||||
|
||||
if (result != RESULT_OK) {
|
||||
@@ -686,7 +686,7 @@ void ValueListDataField::dump(ostream* output) const {
|
||||
} else {
|
||||
*output << VALUE_SEPARATOR;
|
||||
}
|
||||
*output << static_cast<unsigned>(it.first) << "=" << it.second;
|
||||
*output << it.first << "=" << it.second;
|
||||
}
|
||||
} // else: impossible since divisor is not allowed for ValueListDataField
|
||||
dumpSuffix(output);
|
||||
@@ -703,7 +703,7 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse
|
||||
const auto it = m_values.find(value);
|
||||
if (it == m_values.end() && value != m_dataType->getReplacement()) {
|
||||
// fall back to raw value in input
|
||||
*output << setw(0) << dec << static_cast<unsigned>(value);
|
||||
*output << setw(0) << dec << value;
|
||||
return RESULT_OK;
|
||||
}
|
||||
if (it == m_values.end()) {
|
||||
@@ -713,17 +713,17 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse
|
||||
*output << NULL_VALUE;
|
||||
}
|
||||
} else if (outputFormat & OF_NUMERIC) {
|
||||
*output << setw(0) << dec << static_cast<unsigned>(value);
|
||||
*output << setw(0) << dec << value;
|
||||
} else if (outputFormat & OF_JSON) {
|
||||
if (outputFormat & OF_VALUENAME) {
|
||||
*output << "{\"value\":" << setw(0) << dec << static_cast<unsigned>(value);
|
||||
*output << "{\"value\":" << setw(0) << dec << value;
|
||||
*output << ",\"name\":\"" << it->second << "\"}";
|
||||
} else {
|
||||
*output << '"' << it->second << '"';
|
||||
}
|
||||
} else {
|
||||
if (outputFormat & OF_VALUENAME) {
|
||||
*output << setw(0) << dec << static_cast<unsigned>(value) << '=';
|
||||
*output << setw(0) << dec << value << '=';
|
||||
}
|
||||
*output << it->second;
|
||||
}
|
||||
|
||||
@@ -286,15 +286,15 @@ result_t DateTimeDataType::readSymbols(size_t offset, size_t length, const Symbo
|
||||
last = symbol;
|
||||
continue;
|
||||
}
|
||||
int minutes = symbol*256 + last;
|
||||
unsigned int minutes = symbol*256 + last;
|
||||
if (minutes > 24*60) {
|
||||
return RESULT_ERR_OUT_OF_RANGE; // invalid value
|
||||
}
|
||||
int hour = minutes / 60;
|
||||
if (hour > 24) {
|
||||
unsigned int minutesHour = minutes / 60;
|
||||
if (minutesHour > 24) {
|
||||
return RESULT_ERR_OUT_OF_RANGE; // invalid hour
|
||||
}
|
||||
*output << setw(2) << dec << setfill('0') << static_cast<unsigned>(hour);
|
||||
*output << setw(2) << dec << setfill('0') << minutesHour;
|
||||
symbol = (symbol_t)(minutes % 60);
|
||||
} else if (length == 1) { // truncated time
|
||||
if (m_bitCount < 8) {
|
||||
@@ -513,11 +513,11 @@ bool NumberDataType::dump(size_t length, bool appendSeparatorDivisor, ostream* o
|
||||
}
|
||||
if (m_baseType) {
|
||||
if (m_baseType->m_divisor != m_divisor) {
|
||||
*output << static_cast<int>(m_divisor / m_baseType->m_divisor);
|
||||
*output << (m_divisor / m_baseType->m_divisor);
|
||||
return true;
|
||||
}
|
||||
} else if (m_divisor != 1) {
|
||||
*output << static_cast<int>(m_divisor);
|
||||
*output << m_divisor;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -699,7 +699,7 @@ result_t NumberDataType::readSymbols(size_t offset, size_t length, const SymbolS
|
||||
if (m_divisor < 0) {
|
||||
*output << (static_cast<float>(value) * static_cast<float>(-m_divisor));
|
||||
} else if (m_divisor <= 1) {
|
||||
*output << static_cast<unsigned>(value);
|
||||
*output << value;
|
||||
} else {
|
||||
*output << setprecision(static_cast<int>(m_precision))
|
||||
<< fixed << (static_cast<float>(value) / static_cast<float>(m_divisor));
|
||||
@@ -719,12 +719,12 @@ result_t NumberDataType::readSymbols(size_t offset, size_t length, const SymbolS
|
||||
if (hasFlag(FIX) && hasFlag(BCD)) {
|
||||
if (outputFormat & OF_JSON) {
|
||||
*output << '"' << setw(static_cast<int>(length * 2))
|
||||
<< setfill('0') << static_cast<signed>(signedValue) << setw(0) << '"';
|
||||
<< setfill('0') << signedValue << setw(0) << '"';
|
||||
return RESULT_OK;
|
||||
}
|
||||
*output << setw(static_cast<int>(length * 2)) << setfill('0');
|
||||
}
|
||||
*output << static_cast<signed>(signedValue) << setw(0);
|
||||
*output << signedValue << setw(0);
|
||||
} else {
|
||||
*output << setprecision(static_cast<int>(m_precision))
|
||||
<< fixed << (static_cast<float>(signedValue) / static_cast<float>(m_divisor));
|
||||
@@ -842,7 +842,6 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
}
|
||||
} else {
|
||||
char* strEnd = NULL;
|
||||
double dvalue = strtod(str, &strEnd);
|
||||
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
|
||||
return RESULT_ERR_INVALID_NUM; // invalid value
|
||||
|
||||
@@ -124,7 +124,7 @@ result_t Device::recv(unsigned int timeout, symbol_t* value) {
|
||||
tdiff.tv_nsec = (timeout%1000000)*1000;
|
||||
|
||||
#ifdef HAVE_PPOLL
|
||||
int nfds = 1;
|
||||
nfds_t nfds = 1;
|
||||
struct pollfd fds[nfds];
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
|
||||
@@ -208,7 +208,7 @@ result_t FileReader::formatError(const string& filename, unsigned int lineNo, re
|
||||
if (!errorDescription->empty()) {
|
||||
str << *errorDescription << ", ";
|
||||
}
|
||||
str << filename << ":" << static_cast<unsigned>(lineNo) << ": " << getResultCode(result);
|
||||
str << filename << ":" << lineNo << ": " << getResultCode(result);
|
||||
if (!error.empty()) {
|
||||
str << ", " << error;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,6 @@ class FileReader {
|
||||
* Format the error description with the input data.
|
||||
* @param filename the name of the file.
|
||||
* @param lineNo the line number in the file.
|
||||
* @param row the definition row.
|
||||
* @param result the result code.
|
||||
* @param error the error message.
|
||||
* @param errorDescription a string in which to store the error description.
|
||||
|
||||
+19
-18
@@ -419,7 +419,7 @@ result_t Message::create(const string& filename, const DataFieldTemplates* templ
|
||||
maxLength = 0;
|
||||
} else if (chainPrefixLength > 2) {
|
||||
vector<symbol_t>& front = chainIds.front();
|
||||
for (size_t pos = 2; pos < chainPrefixLength; pos++) {
|
||||
for (pos = 2; pos < chainPrefixLength; pos++) {
|
||||
if (chainId[pos] != front[pos]) {
|
||||
chainPrefixLength = pos;
|
||||
break;
|
||||
@@ -812,10 +812,7 @@ bool Message::isLessPollWeight(const Message* other) const {
|
||||
if (tprio < oprio) {
|
||||
return false;
|
||||
}
|
||||
if (m_lastPollTime > other->m_lastPollTime) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return m_lastPollTime > other->m_lastPollTime;
|
||||
}
|
||||
|
||||
void Message::dumpHeader(const vector<string>* fieldNames, ostream* output) {
|
||||
@@ -930,8 +927,7 @@ void Message::dumpField(const string& fieldName, bool withConditions, ostream* o
|
||||
dumpAttribute(false, fieldName, output);
|
||||
}
|
||||
|
||||
void Message::decode(bool leadingSeparator, const vector<string>* fields,
|
||||
OutputFormat outputFormat, ostringstream* output) const {
|
||||
void Message::decode(bool leadingSeparator, OutputFormat outputFormat, ostringstream* output) const {
|
||||
if (leadingSeparator) {
|
||||
*output << ",";
|
||||
}
|
||||
@@ -1541,9 +1537,7 @@ bool SimpleNumericCondition::checkValue(const Message* message, const string& fi
|
||||
if (result == RESULT_OK) {
|
||||
for (size_t i = 0; i+1 < m_valueRanges.size(); i+=2) {
|
||||
if (m_valueRanges[i] <= value && value <= m_valueRanges[i+1]) {
|
||||
ostringstream out;
|
||||
out << static_cast<unsigned>(value);
|
||||
m_matchedValue = out.str();
|
||||
m_matchedValue = AttributedItem::formatInt(value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1976,14 +1970,14 @@ result_t MessageMap::readConditions(const string& filename, string* types, strin
|
||||
Condition* add = NULL;
|
||||
if (it == m_conditions.end()) {
|
||||
// check for on-the-fly condition
|
||||
size_t pos = key.find_first_of("=<>", filename.length()+1);
|
||||
if (pos != string::npos) {
|
||||
it = m_conditions.find(key.substr(0, pos));
|
||||
size_t sep = key.find_first_of("=<>", filename.length()+1);
|
||||
if (sep != string::npos) {
|
||||
it = m_conditions.find(key.substr(0, sep));
|
||||
if (it != m_conditions.end()) {
|
||||
// derive from another condition
|
||||
add = it->second->derive(key.substr(pos));
|
||||
add = it->second->derive(key.substr(sep));
|
||||
if (add == NULL) {
|
||||
*errorDescription = "derive condition with values "+key.substr(pos)+" failed";
|
||||
*errorDescription = "derive condition with values "+key.substr(sep)+" failed";
|
||||
return RESULT_ERR_INVALID_ARG;
|
||||
}
|
||||
m_conditions[key] = add; // store derived condition
|
||||
@@ -2128,7 +2122,7 @@ result_t MessageMap::addFromFile(const string& filename, unsigned int lineNo, ma
|
||||
}
|
||||
types = types.substr(1);
|
||||
Instruction* instruction = NULL;
|
||||
result_t result = Instruction::create(filename, types, condition, *row, getDefaults()[""], &instruction);
|
||||
result = Instruction::create(filename, types, condition, *row, getDefaults()[""], &instruction);
|
||||
if (instruction == NULL || result != RESULT_OK) {
|
||||
*errorDescription = "invalid instruction";
|
||||
return result;
|
||||
@@ -2330,8 +2324,15 @@ bool MessageMap::getLoadedFileInfo(const string& filename, string* comment, size
|
||||
const auto it = m_loadedFileInfos.find(filename);
|
||||
if (it == m_loadedFileInfos.end()) {
|
||||
*comment = "";
|
||||
hash = size = 0;
|
||||
time = 0;
|
||||
if (hash) {
|
||||
*hash = 0;
|
||||
}
|
||||
if (size) {
|
||||
*size = 0;
|
||||
}
|
||||
if (time) {
|
||||
*time = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*comment = it->second.m_comment;
|
||||
|
||||
@@ -551,12 +551,10 @@ class Message : public AttributedItem {
|
||||
/**
|
||||
* Decode the message from the last stored data.
|
||||
* @param leadingSeparator whether to prepend a separator before the first value.
|
||||
* @param fields the list of message and/or data field fields to write, or NULL for all.
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* @param output the @a ostringstream to append the decoded value(s) to.
|
||||
*/
|
||||
virtual void decode(bool leadingSeparator, const vector<string>* fields,
|
||||
OutputFormat outputFormat, ostringstream* output) const;
|
||||
virtual void decode(bool leadingSeparator, OutputFormat outputFormat, ostringstream* output) const;
|
||||
|
||||
protected:
|
||||
/** the optional circuit name. */
|
||||
|
||||
Reference in New Issue
Block a user