changed code style
This commit is contained in:
+54
-54
@@ -119,7 +119,7 @@ void printErrorPos(vector<string>::iterator begin, const vector<string>::iterato
|
||||
bool first = true;
|
||||
int cnt = 0;
|
||||
while (begin != end) {
|
||||
if (first == true)
|
||||
if (first)
|
||||
first = false;
|
||||
else {
|
||||
cout << FIELD_SEPARATOR;
|
||||
@@ -166,22 +166,22 @@ result_t DataField::create(vector<string>::iterator& it,
|
||||
if (it == end)
|
||||
break;
|
||||
|
||||
if (isTemplate == true)
|
||||
if (isTemplate)
|
||||
partType = pt_any;
|
||||
else {
|
||||
const char* partStr = (*it++).c_str();
|
||||
hasPartStr = partStr[0] != 0;
|
||||
if (it == end) {
|
||||
if (name.empty() == false || hasPartStr == true)
|
||||
if (!name.empty() || hasPartStr)
|
||||
result = RESULT_ERR_MISSING_TYPE;
|
||||
break;
|
||||
}
|
||||
if (dstAddress == BROADCAST || isMaster(dstAddress) == true
|
||||
|| (isWriteMessage == true && hasPartStr == false)
|
||||
if (dstAddress == BROADCAST || isMaster(dstAddress)
|
||||
|| (isWriteMessage && !hasPartStr)
|
||||
|| strcasecmp(partStr, "M") == 0) { // master data
|
||||
partType = pt_masterData;
|
||||
}
|
||||
else if ((isWriteMessage == false && hasPartStr == false)
|
||||
else if ((!isWriteMessage && !hasPartStr)
|
||||
|| strcasecmp(partStr, "S") == 0) { // slave data
|
||||
partType = pt_slaveData;
|
||||
}
|
||||
@@ -191,14 +191,14 @@ result_t DataField::create(vector<string>::iterator& it,
|
||||
}
|
||||
}
|
||||
|
||||
if (fields.empty() == true) {
|
||||
if (fields.empty()) {
|
||||
firstName = name;
|
||||
firstComment = comment;
|
||||
}
|
||||
|
||||
const string typeStr = *it++;
|
||||
if (typeStr.empty() == true) {
|
||||
if (name.empty() == false || hasPartStr == true)
|
||||
if (typeStr.empty()) {
|
||||
if (!name.empty() || hasPartStr)
|
||||
result = RESULT_ERR_MISSING_TYPE;
|
||||
break;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ result_t DataField::create(vector<string>::iterator& it,
|
||||
map<unsigned int, string> values;
|
||||
if (it != end) {
|
||||
const string divisorStr = *it++;
|
||||
if (divisorStr.empty() == false) {
|
||||
if (!divisorStr.empty()) {
|
||||
if (divisorStr.find('=') == string::npos)
|
||||
divisor = parseInt(divisorStr.c_str(), 10, 1, 10000, result);
|
||||
else {
|
||||
@@ -265,7 +265,7 @@ result_t DataField::create(vector<string>::iterator& it,
|
||||
while (result == RESULT_OK && getline(stream, token, VALUE_SEPARATOR) != 0) {
|
||||
DataField* templ = templates->get(token);
|
||||
if (templ == NULL) {
|
||||
if (found == false)
|
||||
if (!found)
|
||||
break; // fallback to direct definition
|
||||
result = RESULT_ERR_NOTFOUND; // cannot mix reference and direct definition
|
||||
}
|
||||
@@ -276,7 +276,7 @@ result_t DataField::create(vector<string>::iterator& it,
|
||||
}
|
||||
if (result != RESULT_OK)
|
||||
break;
|
||||
if (found == true)
|
||||
if (found)
|
||||
continue; // go to next definition
|
||||
}
|
||||
typeName = typeStr;
|
||||
@@ -329,11 +329,11 @@ result_t DataField::create(vector<string>::iterator& it,
|
||||
add = new StringDataField(name, comment, unit, *dataType, partType, byteCount);
|
||||
break;
|
||||
case bt_num:
|
||||
if (values.empty() == true && (dataType->flags & DAY) != 0) {
|
||||
if (values.empty() && (dataType->flags & DAY) != 0) {
|
||||
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
|
||||
values[dataType->minValueOrLength + i] = dayNames[i];
|
||||
}
|
||||
if (values.empty() == true || (dataType->flags & LST) == 0) {
|
||||
if (values.empty() || (dataType->flags & LST) == 0) {
|
||||
if (divisor == 0)
|
||||
divisor = 1;
|
||||
if ((dataType->bitCount % 8) == 0)
|
||||
@@ -361,7 +361,7 @@ result_t DataField::create(vector<string>::iterator& it,
|
||||
} while (it != end && result == RESULT_OK);
|
||||
|
||||
if (result != RESULT_OK) {
|
||||
while (fields.empty() == false) { // cleanup already created fields
|
||||
while (!fields.empty()) { // cleanup already created fields
|
||||
delete fields.back();
|
||||
fields.pop_back();
|
||||
}
|
||||
@@ -407,17 +407,17 @@ result_t SingleDataField::read(const PartType partType,
|
||||
default:
|
||||
return RESULT_ERR_INVALID_PART;
|
||||
}
|
||||
if (isIgnored() == true || (filterName != NULL && m_name != filterName)) {
|
||||
if (isIgnored() || (filterName != NULL && m_name != filterName)) {
|
||||
if (offset + m_length > data.size()) {
|
||||
return RESULT_ERR_INVALID_POS;
|
||||
}
|
||||
return RESULT_EMPTY;
|
||||
}
|
||||
|
||||
if (leadingSeparator == true)
|
||||
if (leadingSeparator)
|
||||
output << separator;
|
||||
|
||||
if (verbose == true)
|
||||
if (verbose)
|
||||
output << m_name << "=";
|
||||
|
||||
result_t result = readSymbols(data, offset, output);
|
||||
@@ -461,13 +461,13 @@ result_t StringDataField::derive(string name, string comment,
|
||||
{
|
||||
if (m_partType != pt_any && partType == pt_any)
|
||||
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
|
||||
if (divisor != 0 || values.empty() == false)
|
||||
if (divisor != 0 || !values.empty())
|
||||
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
|
||||
if (name.empty() == true)
|
||||
if (name.empty())
|
||||
name = m_name;
|
||||
if (comment.empty() == true)
|
||||
if (comment.empty())
|
||||
comment = m_comment;
|
||||
if (unit.empty() == true)
|
||||
if (unit.empty())
|
||||
unit = m_unit;
|
||||
|
||||
fields.push_back(new StringDataField(name, comment, unit, m_dataType, partType, m_length));
|
||||
@@ -590,7 +590,7 @@ result_t StringDataField::writeSymbols(istringstream& input,
|
||||
incr = -1;
|
||||
}
|
||||
|
||||
if (isIgnored() == true && (m_dataType.flags & REQ) == 0) {
|
||||
if (isIgnored() && (m_dataType.flags & REQ) == 0) {
|
||||
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
|
||||
output[baseOffset + offset] = m_dataType.replacement; // fill up with replacement
|
||||
}
|
||||
@@ -602,17 +602,17 @@ result_t StringDataField::writeSymbols(istringstream& input,
|
||||
switch (m_dataType.type)
|
||||
{
|
||||
case bt_hexstr:
|
||||
while (input.eof() == false && input.peek() == ' ')
|
||||
while (!input.eof() && input.peek() == ' ')
|
||||
input.get();
|
||||
if (input.eof() == true) // no more digits
|
||||
if (input.eof()) // no more digits
|
||||
value = m_dataType.replacement; // fill up with replacement
|
||||
else {
|
||||
token.clear();
|
||||
token.push_back(input.get());
|
||||
if (input.eof() == true)
|
||||
if (input.eof())
|
||||
return RESULT_ERR_INVALID_NUM; // too short hex value
|
||||
token.push_back(input.get());
|
||||
if (input.eof() == true)
|
||||
if (input.eof())
|
||||
return RESULT_ERR_INVALID_NUM; // too short hex value
|
||||
|
||||
value = parseInt(token.c_str(), 16, 0, 0xff, result);
|
||||
@@ -623,7 +623,7 @@ result_t StringDataField::writeSymbols(istringstream& input,
|
||||
case bt_dat:
|
||||
if (m_length == 4 && i == 2)
|
||||
continue; // skip weekday in between
|
||||
if (input.eof() == true || getline(input, token, '.') == 0)
|
||||
if (input.eof() || getline(input, token, '.') == 0)
|
||||
return RESULT_ERR_EOF; // incomplete
|
||||
if ((m_dataType.flags & REQ) == 0 && strcmp(token.c_str(), NULL_VALUE) == 0) {
|
||||
value = m_dataType.replacement;
|
||||
@@ -659,7 +659,7 @@ result_t StringDataField::writeSymbols(istringstream& input,
|
||||
return RESULT_ERR_OUT_OF_RANGE; // invalid date part
|
||||
break;
|
||||
case bt_tim:
|
||||
if (input.eof() == true || getline(input, token, LENGTH_SEPARATOR) == 0)
|
||||
if (input.eof() || getline(input, token, LENGTH_SEPARATOR) == 0)
|
||||
return RESULT_ERR_EOF; // incomplete
|
||||
if ((m_dataType.flags & REQ) == 0 && strcmp(token.c_str(), NULL_VALUE) == 0) {
|
||||
value = m_dataType.replacement;
|
||||
@@ -695,11 +695,11 @@ result_t StringDataField::writeSymbols(istringstream& input,
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (input.eof() == true)
|
||||
if (input.eof())
|
||||
value = m_dataType.replacement;
|
||||
else {
|
||||
value = input.get();
|
||||
if (input.eof() == true || value < 0x20)
|
||||
if (input.eof() || value < 0x20)
|
||||
value = m_dataType.replacement;
|
||||
}
|
||||
break;
|
||||
@@ -726,7 +726,7 @@ result_t StringDataField::writeSymbols(istringstream& input,
|
||||
bool NumericDataField::hasFullByteOffset(bool after)
|
||||
{
|
||||
return m_length > 1 || (m_bitCount % 8) == 0
|
||||
|| (after == true && m_bitOffset + (m_bitCount % 8) >= 8);
|
||||
|| (after && m_bitOffset + (m_bitCount % 8) >= 8);
|
||||
}
|
||||
|
||||
void NumericDataField::dump(ostream& output)
|
||||
@@ -848,17 +848,17 @@ result_t NumberDataField::derive(string name, string comment,
|
||||
{
|
||||
if (m_partType != pt_any && partType == pt_any)
|
||||
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
|
||||
if (name.empty() == true)
|
||||
if (name.empty())
|
||||
name = m_name;
|
||||
if (comment.empty() == true)
|
||||
if (comment.empty())
|
||||
comment = m_comment;
|
||||
if (unit.empty() == true)
|
||||
if (unit.empty())
|
||||
unit = m_unit;
|
||||
if (divisor == 0)
|
||||
divisor = m_divisor;
|
||||
else if ((m_dataType.bitCount % 8) == 0)
|
||||
divisor *= m_dataType.divisorOrFirstBit;
|
||||
if (values.empty() == false) {
|
||||
if (!values.empty()) {
|
||||
if (divisor != 1)
|
||||
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
|
||||
|
||||
@@ -896,7 +896,7 @@ result_t NumberDataField::readSymbols(SymbolString& input,
|
||||
|
||||
bool negative = (m_dataType.flags & SIG) != 0 && (value & (1 << (m_bitCount - 1))) != 0;
|
||||
if (m_bitCount == 32) {
|
||||
if (negative == false) {
|
||||
if (!negative) {
|
||||
if (m_divisor <= 1)
|
||||
output << static_cast<unsigned>(value);
|
||||
else
|
||||
@@ -906,7 +906,7 @@ result_t NumberDataField::readSymbols(SymbolString& input,
|
||||
}
|
||||
signedValue = (int) value; // negative signed value
|
||||
}
|
||||
else if (negative == true) // negative signed value
|
||||
else if (negative) // negative signed value
|
||||
signedValue = (int) value - (1 << m_bitCount);
|
||||
else
|
||||
signedValue = (int) value;
|
||||
@@ -929,7 +929,7 @@ result_t NumberDataField::writeSymbols(istringstream& input,
|
||||
unsigned int value;
|
||||
|
||||
const char* str = input.str().c_str();
|
||||
if ((m_dataType.flags & REQ) == 0 && (isIgnored() == true || strcasecmp(str, NULL_VALUE) == 0))
|
||||
if ((m_dataType.flags & REQ) == 0 && (isIgnored() || strcasecmp(str, NULL_VALUE) == 0))
|
||||
value = m_dataType.replacement; // replacement value
|
||||
else if (str == NULL || *str == 0)
|
||||
return RESULT_ERR_EOF; // input too short
|
||||
@@ -992,16 +992,16 @@ result_t ValueListDataField::derive(string name, string comment,
|
||||
{
|
||||
if (m_partType != pt_any && partType == pt_any)
|
||||
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
|
||||
if (name.empty() == true)
|
||||
if (name.empty())
|
||||
name = m_name;
|
||||
if (comment.empty() == true)
|
||||
if (comment.empty())
|
||||
comment = m_comment;
|
||||
if (unit.empty() == true)
|
||||
if (unit.empty())
|
||||
unit = m_unit;
|
||||
if (divisor != 0 && divisor != 1)
|
||||
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
|
||||
|
||||
if (values.empty() == false) {
|
||||
if (!values.empty()) {
|
||||
if (values.begin()->first < m_dataType.minValueOrLength
|
||||
|| values.rbegin()->first > m_dataType.maxValueOrLength)
|
||||
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
|
||||
@@ -1019,7 +1019,7 @@ void ValueListDataField::dump(ostream& output)
|
||||
NumericDataField::dump(output);
|
||||
bool first = true;
|
||||
for (map<unsigned int, string>::iterator it = m_values.begin(); it != m_values.end(); it++) {
|
||||
if (first == true)
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
output << VALUE_SEPARATOR;
|
||||
@@ -1057,7 +1057,7 @@ result_t ValueListDataField::readSymbols(SymbolString& input,
|
||||
result_t ValueListDataField::writeSymbols(istringstream& input,
|
||||
unsigned char baseOffset, SymbolString& output)
|
||||
{
|
||||
if (isIgnored() == true)
|
||||
if (isIgnored())
|
||||
return writeRawValue(m_dataType.replacement, baseOffset, output); // replacement value
|
||||
|
||||
const char* str = input.str().c_str();
|
||||
@@ -1110,7 +1110,7 @@ DataFieldSet* DataFieldSet::createIdentFields()
|
||||
|
||||
DataFieldSet::~DataFieldSet()
|
||||
{
|
||||
while (m_fields.empty() == false) {
|
||||
while (!m_fields.empty()) {
|
||||
delete m_fields.back();
|
||||
m_fields.pop_back();
|
||||
}
|
||||
@@ -1125,7 +1125,7 @@ unsigned char DataFieldSet::getLength(PartType partType)
|
||||
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
|
||||
SingleDataField* field = *it;
|
||||
if (field->getPartType() == partType) {
|
||||
if (previousFullByteOffset[partType] == false && field->hasFullByteOffset(false) == false)
|
||||
if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false))
|
||||
length--;
|
||||
|
||||
length += field->getLength(partType);
|
||||
@@ -1142,7 +1142,7 @@ result_t DataFieldSet::derive(string name, string comment,
|
||||
unsigned int divisor, map<unsigned int, string> values,
|
||||
vector<SingleDataField*>& fields)
|
||||
{
|
||||
if (values.empty() == false)
|
||||
if (!values.empty())
|
||||
return RESULT_ERR_INVALID_ARG; // value list not allowed in set derive
|
||||
|
||||
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
|
||||
@@ -1172,7 +1172,7 @@ result_t DataFieldSet::read(const PartType partType,
|
||||
if (partType != pt_any && field->getPartType() != partType)
|
||||
continue;
|
||||
|
||||
if (previousFullByteOffset == false && field->hasFullByteOffset(false) == false)
|
||||
if (!previousFullByteOffset && !field->hasFullByteOffset(false))
|
||||
offset--;
|
||||
|
||||
result_t result = field->read(partType, data, offset, output, leadingSeparator, verbose, filterName, separator);
|
||||
@@ -1188,12 +1188,12 @@ result_t DataFieldSet::read(const PartType partType,
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose == true) {
|
||||
if (verbose) {
|
||||
if (m_comment.length() > 0)
|
||||
output << " [" << m_comment << "]";
|
||||
}
|
||||
|
||||
return found == true ? RESULT_OK : RESULT_EMPTY;
|
||||
return found ? RESULT_OK : RESULT_EMPTY;
|
||||
}
|
||||
|
||||
result_t DataFieldSet::write(istringstream& input,
|
||||
@@ -1208,12 +1208,12 @@ result_t DataFieldSet::write(istringstream& input,
|
||||
if (partType != pt_any && field->getPartType() != partType)
|
||||
continue;
|
||||
|
||||
if (previousFullByteOffset == false && field->hasFullByteOffset(false) == false)
|
||||
if (!previousFullByteOffset && !field->hasFullByteOffset(false))
|
||||
offset--;
|
||||
|
||||
result_t result;
|
||||
if (m_fields.size() > 1) {
|
||||
if (field->isIgnored() == true)
|
||||
if (field->isIgnored())
|
||||
token.clear();
|
||||
else if (getline(input, token, separator) == 0)
|
||||
token.clear();
|
||||
@@ -1249,7 +1249,7 @@ result_t DataFieldTemplates::add(DataField* field, bool replace)
|
||||
string name = field->getName();
|
||||
map<string, DataField*>::iterator it = m_fieldsByName.find(name);
|
||||
if (it != m_fieldsByName.end()) {
|
||||
if (replace == false)
|
||||
if (!replace)
|
||||
return RESULT_ERR_DUPLICATE; // duplicate key
|
||||
|
||||
delete it->second;
|
||||
|
||||
@@ -87,7 +87,7 @@ bool Device::isValid()
|
||||
if (m_fd == -1)
|
||||
return false;
|
||||
|
||||
if (m_checkDevice == true)
|
||||
if (m_checkDevice)
|
||||
checkDevice();
|
||||
|
||||
return m_fd != -1;
|
||||
@@ -95,13 +95,13 @@ bool Device::isValid()
|
||||
|
||||
result_t Device::send(const unsigned char value)
|
||||
{
|
||||
if (isValid() == false)
|
||||
if (!isValid())
|
||||
return RESULT_ERR_DEVICE;
|
||||
|
||||
if (write(m_fd, &value, 1) != 1)
|
||||
return RESULT_ERR_SEND;
|
||||
|
||||
if (m_logRaw == true && m_logRawFunc != NULL)
|
||||
if (m_logRaw && m_logRawFunc != NULL)
|
||||
(*m_logRawFunc)(value, false);
|
||||
|
||||
return RESULT_OK;
|
||||
@@ -109,7 +109,7 @@ result_t Device::send(const unsigned char value)
|
||||
|
||||
result_t Device::recv(const long timeout, unsigned char& value)
|
||||
{
|
||||
if (isValid() == false)
|
||||
if (!isValid())
|
||||
return RESULT_ERR_DEVICE;
|
||||
|
||||
if (timeout > 0) {
|
||||
@@ -153,10 +153,10 @@ result_t Device::recv(const long timeout, unsigned char& value)
|
||||
if (nbytes < 0)
|
||||
return RESULT_ERR_DEVICE;
|
||||
|
||||
if (m_logRaw == true && m_logRawFunc != NULL)
|
||||
if (m_logRaw && m_logRawFunc != NULL)
|
||||
(*m_logRawFunc)(value, true);
|
||||
|
||||
if (m_dumpRaw == true && m_dumpRawStream.is_open() == true) {
|
||||
if (m_dumpRaw && m_dumpRawStream.is_open()) {
|
||||
m_dumpRawStream.write((char*)&value, 1);
|
||||
m_dumpRawFileSize++;
|
||||
if ((m_dumpRawFileSize%1024) == 0)
|
||||
@@ -182,7 +182,7 @@ void Device::setDumpRaw(bool dumpRaw)
|
||||
|
||||
m_dumpRaw = dumpRaw;
|
||||
|
||||
if (dumpRaw == false || m_dumpRawFile == NULL)
|
||||
if (!dumpRaw || m_dumpRawFile == NULL)
|
||||
m_dumpRawStream.close();
|
||||
else {
|
||||
m_dumpRawStream.open(m_dumpRawFile, ios::out | ios::binary | ios::app);
|
||||
@@ -197,7 +197,7 @@ void Device::setDumpRawFile(const char* dumpFile) {
|
||||
m_dumpRawStream.close();
|
||||
m_dumpRawFile = dumpFile;
|
||||
|
||||
if (m_dumpRaw == true && m_dumpRawFile != NULL) {
|
||||
if (m_dumpRaw && m_dumpRawFile != NULL) {
|
||||
m_dumpRawStream.open(m_dumpRawFile, ios::out | ios::binary | ios::app);
|
||||
m_dumpRawFileSize = 0;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
{
|
||||
ifstream ifs;
|
||||
ifs.open(filename.c_str(), ifstream::in);
|
||||
if (ifs.is_open() == false)
|
||||
if (!ifs.is_open())
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
|
||||
string line;
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
switch (ch)
|
||||
{
|
||||
case FIELD_SEPARATOR:
|
||||
if (quotedText == true)
|
||||
if (quotedText)
|
||||
field << ch;
|
||||
else {
|
||||
row.push_back(field.str());
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
}
|
||||
break;
|
||||
case TEXT_SEPARATOR:
|
||||
if (quotedText == true) {
|
||||
if (quotedText) {
|
||||
quotedText = false;
|
||||
}
|
||||
else if (prev == TEXT_SEPARATOR) { // double dquote
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
result_t result;
|
||||
vector<string>::iterator it = row.begin();
|
||||
const vector<string>::iterator end = row.end();
|
||||
if (m_supportsDefaults == true) {
|
||||
if (m_supportsDefaults) {
|
||||
if (line[0] == '*') {
|
||||
row[0] = row[0].substr(1);
|
||||
defaults.push_back(row);
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
result = addFromFile(it, end, arg, NULL, filename, lineNo);
|
||||
|
||||
if (result != RESULT_OK) {
|
||||
if (verbose == false) {
|
||||
if (!verbose) {
|
||||
ifs.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
+19
-19
@@ -45,7 +45,7 @@ Message::Message(const string clazz, const string name, const bool isWrite,
|
||||
{
|
||||
int exp = 7;
|
||||
unsigned long long key = (unsigned long long)(id.size()-2) << (8 * exp + 5);
|
||||
if (isPassive == true)
|
||||
if (isPassive)
|
||||
key |= (unsigned long long)getMasterNumber(srcAddress) << (8 * exp--); // 0..25
|
||||
else
|
||||
key |= 0x1fLL << (8 * exp--); // special value for active
|
||||
@@ -159,7 +159,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
|
||||
srcAddress = parseInt(str, 16, 0, 0xff, result);
|
||||
if (result != RESULT_OK)
|
||||
return result;
|
||||
if (isMaster(srcAddress) == false)
|
||||
if (!isMaster(srcAddress))
|
||||
return RESULT_ERR_INVALID_ADDR;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
|
||||
dstAddress = parseInt(str, 16, 0, 0xff, result);
|
||||
if (result != RESULT_OK)
|
||||
return result;
|
||||
if (isValidAddress(dstAddress) == false)
|
||||
if (!isValidAddress(dstAddress))
|
||||
return RESULT_ERR_INVALID_ADDR;
|
||||
}
|
||||
|
||||
@@ -190,14 +190,14 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
|
||||
istringstream input(token);
|
||||
if (it == end)
|
||||
return RESULT_ERR_EOF;
|
||||
while (input.eof() == false) {
|
||||
while (!input.eof()) {
|
||||
while (input.peek() == ' ')
|
||||
input.get();
|
||||
if (input.eof() == true) // no more digits
|
||||
if (input.eof()) // no more digits
|
||||
break;
|
||||
token.clear();
|
||||
token.push_back(input.get());
|
||||
if (input.eof() == true) {
|
||||
if (input.eof()) {
|
||||
return RESULT_ERR_INVALID_ARG; // too short hex
|
||||
}
|
||||
token.push_back(input.get());
|
||||
@@ -249,7 +249,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
|
||||
|
||||
result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& masterData, istringstream& input, char separator, const unsigned char dstAddress)
|
||||
{
|
||||
if (m_isPassive == true)
|
||||
if (m_isPassive)
|
||||
return RESULT_ERR_INVALID_ARG; // prepare not possible
|
||||
|
||||
SymbolString master(false);
|
||||
@@ -289,7 +289,7 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
|
||||
|
||||
result_t Message::prepareSlave(SymbolString& slaveData)
|
||||
{
|
||||
if (m_isPassive == false || m_isWrite == true)
|
||||
if (!m_isPassive || m_isWrite)
|
||||
return RESULT_ERR_INVALID_ARG; // prepare not possible
|
||||
|
||||
SymbolString slave(false);
|
||||
@@ -398,7 +398,7 @@ result_t MessageMap::add(Message* message)
|
||||
|
||||
m_messagesByName[nameKey] = message;
|
||||
m_messageCount++;
|
||||
if (isPassive == true)
|
||||
if (isPassive)
|
||||
m_passiveMessageCount++;
|
||||
|
||||
nameKey = string(isPassive ? "-P" : (isWrite ? "-W" : "-R")) + name; // also store without class
|
||||
@@ -483,28 +483,28 @@ deque<Message*> MessageMap::findAll(const string& clazz, const string& name, con
|
||||
if (it->first[0] == '-') // avoid duplicates: instances stored multiple times have a key starting with "-"
|
||||
continue;
|
||||
Message* message = it->second;
|
||||
if (checkClass == true) {
|
||||
if (checkClass) {
|
||||
string check = strtolower(message->getClass());
|
||||
if (completeMatch ? (check != lclass) : (check.find(lclass) == check.npos))
|
||||
continue;
|
||||
}
|
||||
if (checkName == true) {
|
||||
if (checkName) {
|
||||
string check = strtolower(message->getName());
|
||||
if (completeMatch ? (check != lname) : (check.find(lname) == check.npos))
|
||||
continue;
|
||||
}
|
||||
if (checkPb == true && message->getId()[0] != pb)
|
||||
if (checkPb && message->getId()[0] != pb)
|
||||
continue;
|
||||
if (message->isPassive() == true) {
|
||||
if (withPassive == false)
|
||||
if (message->isPassive()) {
|
||||
if (!withPassive)
|
||||
continue;
|
||||
}
|
||||
else if (message->isWrite() == true) {
|
||||
if (withWrite == false)
|
||||
else if (message->isWrite()) {
|
||||
if (!withWrite)
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if (withRead == false)
|
||||
if (!withRead)
|
||||
continue;
|
||||
}
|
||||
ret.push_back(message);
|
||||
@@ -556,7 +556,7 @@ Message* MessageMap::find(SymbolString& master)
|
||||
void MessageMap::clear()
|
||||
{
|
||||
// clear poll messages
|
||||
while (m_pollMessages.empty() == false) {
|
||||
while (!m_pollMessages.empty()) {
|
||||
m_pollMessages.top();
|
||||
m_pollMessages.pop();
|
||||
}
|
||||
@@ -578,7 +578,7 @@ void MessageMap::clear()
|
||||
|
||||
Message* MessageMap::getNextPoll()
|
||||
{
|
||||
if (m_pollMessages.empty() == true)
|
||||
if (m_pollMessages.empty())
|
||||
return NULL;
|
||||
Message* ret = m_pollMessages.top();
|
||||
m_pollMessages.pop();
|
||||
|
||||
+13
-13
@@ -86,7 +86,7 @@ const string SymbolString::getDataStr(const bool unescape)
|
||||
|
||||
for (size_t i = 0; i < m_data.size(); i++) {
|
||||
unsigned char value = m_data[i];
|
||||
if (m_unescapeState == 0 && unescape == true && previousEscape == true) {
|
||||
if (m_unescapeState == 0 && unescape && previousEscape) {
|
||||
if (value == 0x00)
|
||||
sstr << "a9"; // ESC
|
||||
else if (value == 0x01)
|
||||
@@ -96,7 +96,7 @@ const string SymbolString::getDataStr(const bool unescape)
|
||||
|
||||
previousEscape = false;
|
||||
}
|
||||
else if (m_unescapeState == 0 && unescape == true && value == ESC) {
|
||||
else if (m_unescapeState == 0 && unescape && value == ESC) {
|
||||
previousEscape = true; // escape sequence not yet finished
|
||||
}
|
||||
else {
|
||||
@@ -111,35 +111,35 @@ const string SymbolString::getDataStr(const bool unescape)
|
||||
result_t SymbolString::push_back(const unsigned char value, const bool isEscaped, const bool updateCRC)
|
||||
{
|
||||
if (m_unescapeState == 0) { // store escaped data
|
||||
if (isEscaped == false && value == ESC) {
|
||||
if (!isEscaped && value == ESC) {
|
||||
m_data.push_back(ESC);
|
||||
m_data.push_back(0x00);
|
||||
if (updateCRC == true) {
|
||||
if (updateCRC) {
|
||||
addCRC(ESC);
|
||||
addCRC(0x00);
|
||||
}
|
||||
}
|
||||
else if (isEscaped == false && value == SYN) {
|
||||
else if (!isEscaped && value == SYN) {
|
||||
m_data.push_back(ESC);
|
||||
m_data.push_back(0x01);
|
||||
if (updateCRC == true) {
|
||||
if (updateCRC) {
|
||||
addCRC(ESC);
|
||||
addCRC(0x01);
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_data.push_back(value);
|
||||
if (updateCRC == true)
|
||||
if (updateCRC)
|
||||
addCRC(value);
|
||||
|
||||
}
|
||||
return RESULT_OK;
|
||||
}
|
||||
else if (isEscaped == false) {
|
||||
else if (!isEscaped) {
|
||||
if (m_unescapeState != 1)
|
||||
return RESULT_ERR_ESC; // invalid unescape state
|
||||
m_data.push_back(value);
|
||||
if (updateCRC == true) {
|
||||
if (updateCRC) {
|
||||
if (value == ESC) {
|
||||
addCRC(ESC);
|
||||
addCRC(0x00);
|
||||
@@ -155,7 +155,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
|
||||
return RESULT_OK;
|
||||
}
|
||||
else if (m_unescapeState != 1) {
|
||||
if (updateCRC == true)
|
||||
if (updateCRC)
|
||||
addCRC(value);
|
||||
|
||||
if (value == 0x00) {
|
||||
@@ -171,13 +171,13 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
|
||||
return RESULT_ERR_ESC; // invalid escape sequence
|
||||
}
|
||||
else if (value == ESC) {
|
||||
if (updateCRC == true)
|
||||
if (updateCRC)
|
||||
addCRC(value);
|
||||
|
||||
m_unescapeState = 2;
|
||||
return RESULT_IN_ESC;
|
||||
}
|
||||
if (updateCRC == true)
|
||||
if (updateCRC)
|
||||
addCRC(value);
|
||||
|
||||
m_data.push_back(value);
|
||||
@@ -242,6 +242,6 @@ unsigned char getMasterNumber(unsigned char addr) {
|
||||
}
|
||||
|
||||
bool isValidAddress(unsigned char addr, bool allowBroadcast) {
|
||||
return addr != SYN && addr != ESC && (allowBroadcast == true || addr != BROADCAST);
|
||||
return addr != SYN && addr != ESC && (allowBroadcast || addr != BROADCAST);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
* Creates a new empty escaped or unescaped instance.
|
||||
* @param escaped whether to create an escaped instance.
|
||||
*/
|
||||
SymbolString(const bool escaped=true) : m_unescapeState(escaped == true ? 0 : 1), m_crc(0) {}
|
||||
SymbolString(const bool escaped=true) : m_unescapeState(escaped ? 0 : 1), m_crc(0) {}
|
||||
|
||||
/**
|
||||
* Add all symbols from the other @a SymbolString and the calculated CRC if escaped.
|
||||
|
||||
@@ -26,14 +26,14 @@ using namespace std;
|
||||
void verify(bool expectFailMatch, string type, string input,
|
||||
bool match, string expectStr, string gotStr)
|
||||
{
|
||||
if (expectFailMatch == true) {
|
||||
if (match == true)
|
||||
if (expectFailMatch) {
|
||||
if (match)
|
||||
cout << " failed " << type << " match >" << input
|
||||
<< "< error: unexpectedly succeeded" << endl;
|
||||
else
|
||||
cout << " failed " << type << " match >" << input << "< OK" << endl;
|
||||
}
|
||||
else if (match == true)
|
||||
else if (match)
|
||||
cout << " " << type << " match >" << input << "< OK" << endl;
|
||||
else
|
||||
cout << " " << type << " match >" << input << "< error: got >"
|
||||
@@ -248,7 +248,7 @@ int main()
|
||||
}
|
||||
vector<string>::iterator it = entries.begin();
|
||||
result = DataField::create(it, entries.end(), templates, fields, isSet, isTemplate ? SYN : mstr[1]);
|
||||
if (failedCreate == true) {
|
||||
if (failedCreate) {
|
||||
if (result == RESULT_OK)
|
||||
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
|
||||
else
|
||||
@@ -294,9 +294,9 @@ int main()
|
||||
}
|
||||
result = fields->read(pt_masterData, mstr, 0, output, false, verbose);
|
||||
if (result >= RESULT_OK) {
|
||||
result = fields->read(pt_slaveData, sstr, 0, output, output.str().empty() == false, verbose);
|
||||
result = fields->read(pt_slaveData, sstr, 0, output, !output.str().empty(), verbose);
|
||||
}
|
||||
if (failedRead == true)
|
||||
if (failedRead)
|
||||
if (result >= RESULT_OK)
|
||||
cout << " failed read " << fields->getName() << " >"
|
||||
<< check[2] << "< error: unexpectedly succeeded" << endl;
|
||||
@@ -312,12 +312,12 @@ int main()
|
||||
verify(failedReadMatch, "read", check[2], match, expectStr, output.str());
|
||||
}
|
||||
|
||||
if (verbose == false) {
|
||||
if (!verbose) {
|
||||
istringstream input(expectStr);
|
||||
result = fields->write(input, pt_masterData, writeMstr, 0);
|
||||
if (result >= RESULT_OK)
|
||||
result = fields->write(input, pt_slaveData, writeSstr, 0);
|
||||
if (failedWrite == true) {
|
||||
if (failedWrite) {
|
||||
if (result >= RESULT_OK)
|
||||
cout << " failed write " << fields->getName() << " >"
|
||||
<< expectStr << "< error: unexpectedly succeeded" << endl;
|
||||
|
||||
@@ -34,7 +34,7 @@ int main ()
|
||||
if (result != RESULT_OK) {
|
||||
cout << "open failed: " << getResultCode(result) << endl;
|
||||
} else {
|
||||
if (device->isValid() == false)
|
||||
if (!device->isValid())
|
||||
cout << "device not available." << endl;
|
||||
|
||||
int count = 0;
|
||||
@@ -52,7 +52,7 @@ int main ()
|
||||
|
||||
device->close();
|
||||
|
||||
if(device->isValid() == false)
|
||||
if (!device->isValid())
|
||||
cout << "close successful." << endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,14 +27,14 @@ using namespace std;
|
||||
void verify(bool expectFailMatch, string type, string input,
|
||||
bool match, string expectStr, string gotStr)
|
||||
{
|
||||
if (expectFailMatch == true) {
|
||||
if (match == true)
|
||||
if (expectFailMatch) {
|
||||
if (match)
|
||||
cout << " failed " << type << " match >" << input
|
||||
<< "< error: unexpectedly succeeded" << endl;
|
||||
else
|
||||
cout << " failed " << type << " match >" << input << "< OK" << endl;
|
||||
}
|
||||
else if (match == true)
|
||||
else if (match)
|
||||
cout << " " << type << " match >" << input << "< OK" << endl;
|
||||
else
|
||||
cout << " " << type << " match >" << input << "< error: got >"
|
||||
@@ -104,7 +104,7 @@ int main()
|
||||
delete deleteMessage;
|
||||
deleteMessage = NULL;
|
||||
}
|
||||
if (isTemplate == true) {
|
||||
if (isTemplate) {
|
||||
// store new template
|
||||
DataField* fields = NULL;
|
||||
vector<string>::iterator it = entries.begin();
|
||||
@@ -136,7 +136,7 @@ int main()
|
||||
else {
|
||||
vector<string>::iterator it = entries.begin();
|
||||
result = Message::create(it, entries.end(), NULL, templates, deleteMessage);
|
||||
if (failedCreate == true) {
|
||||
if (failedCreate) {
|
||||
if (result == RESULT_OK)
|
||||
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
|
||||
else
|
||||
@@ -158,7 +158,7 @@ int main()
|
||||
continue;
|
||||
}
|
||||
cout << "\"" << check[0] << "\": create OK" << endl;
|
||||
if (dontMap == false) {
|
||||
if (!dontMap) {
|
||||
result_t result = messages->add(deleteMessage);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": add error: "
|
||||
@@ -168,7 +168,7 @@ int main()
|
||||
cout << " map OK" << endl;
|
||||
message = deleteMessage;
|
||||
deleteMessage = NULL;
|
||||
if (onlyMap == true)
|
||||
if (onlyMap)
|
||||
continue;
|
||||
Message* foundMessage = messages->find(mstr);
|
||||
if (foundMessage == message)
|
||||
@@ -182,7 +182,7 @@ int main()
|
||||
message = deleteMessage;
|
||||
}
|
||||
|
||||
if (message->isPassive() == true || decode == true) {
|
||||
if (message->isPassive() || decode) {
|
||||
ostringstream output;
|
||||
result = message->decode(mstr, sstr, output);
|
||||
if (result != RESULT_OK) {
|
||||
@@ -199,7 +199,7 @@ int main()
|
||||
istringstream input(inputStr);
|
||||
SymbolString writeMstr;
|
||||
result = message->prepareMaster(0xff, writeMstr, input);
|
||||
if (failedPrepare == true) {
|
||||
if (failedPrepare) {
|
||||
if (result == RESULT_OK)
|
||||
cout << " \"" << inputStr << "\": failed prepare error: unexpectedly succeeded" << endl;
|
||||
else
|
||||
|
||||
@@ -82,7 +82,7 @@ TCPSocket* TCPClient::connect(const string& server, const int& port)
|
||||
|
||||
int TCPServer::start()
|
||||
{
|
||||
if (m_listening == true)
|
||||
if (m_listening)
|
||||
return 0;
|
||||
|
||||
m_lfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
@@ -115,7 +115,7 @@ int TCPServer::start()
|
||||
|
||||
TCPSocket* TCPServer::newSocket()
|
||||
{
|
||||
if (m_listening == false)
|
||||
if (!m_listening)
|
||||
return NULL;
|
||||
|
||||
struct sockaddr_in address;
|
||||
|
||||
@@ -32,11 +32,12 @@ void* Thread::runThread(void* arg)
|
||||
|
||||
Thread::~Thread()
|
||||
{
|
||||
if (m_started == true)
|
||||
if (m_started) {
|
||||
pthread_detach(m_threadid);
|
||||
|
||||
if (m_started == true)
|
||||
}
|
||||
if (m_started) {
|
||||
pthread_cancel(m_threadid);
|
||||
}
|
||||
}
|
||||
|
||||
bool Thread::start(const char* name)
|
||||
@@ -62,7 +63,7 @@ bool Thread::join()
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if (m_started == true) {
|
||||
if (m_started) {
|
||||
m_stopped = true;
|
||||
result = pthread_join(m_threadid, NULL);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
* Return whether this @a Thread is still running and not yet stopped.
|
||||
* @return true if this @a Thread is till running and not yet stopped.
|
||||
*/
|
||||
virtual bool isRunning() { return m_running == true && m_stopped == false; }
|
||||
virtual bool isRunning() { return m_running && !m_stopped; }
|
||||
|
||||
/**
|
||||
* Create the native thread and set its name.
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
|
||||
T item;
|
||||
if (wait == true) {
|
||||
if (wait) {
|
||||
while (m_queue.size() == 0)
|
||||
pthread_cond_wait(&m_cond, &m_mutex);
|
||||
item = m_queue.front();
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
|
||||
T item;
|
||||
if (wait == true) {
|
||||
if (wait) {
|
||||
while (m_queue.size() == 0)
|
||||
pthread_cond_wait(&m_cond, &m_mutex);
|
||||
item = m_queue.front();
|
||||
|
||||
Reference in New Issue
Block a user