code style

This commit is contained in:
Roland Jax
2014-12-30 20:08:48 +01:00
parent df85caf71f
commit 612270f942
12 changed files with 85 additions and 53 deletions
+8 -6
View File
@@ -127,11 +127,11 @@ void printErrorPos(vector<string>::iterator begin, const vector<string>::iterato
cnt++;
}
}
if (begin < pos) {
if (begin < pos)
cnt += 1+(*begin).length()+1;
} else if (begin == pos) {
else if (begin == pos)
cnt++;
}
string item = *begin++;
cout << TEXT_SEPARATOR << item << TEXT_SEPARATOR;
}
@@ -647,7 +647,8 @@ result_t StringDataField::writeSymbols(istringstream& input,
value -= 2000;
else if (value > 99)
return RESULT_ERR_OUT_OF_RANGE; // invalid year
} else if (value < 1 || (i == 0 && value > 31) || (i == 1 && value > 12))
}
else if (value < 1 || (i == 0 && value > 31) || (i == 1 && value > 12))
return RESULT_ERR_OUT_OF_RANGE; // invalid date part
break;
case bt_tim:
@@ -898,7 +899,7 @@ result_t NumberDataField::readSymbols(SymbolString& input,
}
signedValue = (int) value; // negative signed value
}
else if (negative) // negative signed value
else if (negative == true) // negative signed value
signedValue = (int) value - (1 << m_bitCount);
else
signedValue = (int) value;
@@ -907,7 +908,8 @@ result_t NumberDataField::readSymbols(SymbolString& input,
if ((m_dataType.flags & (FIX|BCD)) == (FIX|BCD))
output << setw(m_length * 2) << setfill('0');
output << static_cast<int>(signedValue) << setw(0);
} else
}
else
output << setprecision(m_precision)
<< fixed << static_cast<float>(signedValue / (float) m_divisor);
+17 -11
View File
@@ -104,17 +104,20 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
size_t len = strlen(str);
if (len == 0) { // default: active get
defaultName = "r";
} else if (strncasecmp(str, "R", 1) == 0) { // active get
}else if (strncasecmp(str, "R", 1) == 0) { // active get
char last = str[len-1];
if (last >= '0' && last <= '9') { // poll priority (=active get)
pollPriority = last - '0';
defaultName = string(str).substr(0, len - 1); // cut off priority digit
} else
}
else
defaultName = str;
} else if (strncasecmp(str, "W", 1) == 0) { // active set
}
else if (strncasecmp(str, "W", 1) == 0) { // active set
isSet = true;
defaultName = str;
} else { // any other: passive set/get
}
else { // any other: passive set/get
isPassive = true;
isSet = strcasecmp(str+len-1, "W") == 0; // if type ends with "w" it is treated as passive set
defaultName = str;
@@ -178,11 +181,11 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
for (int pos=0, useDefaults=1; pos<2; pos++) { // message id (PBSB, optional master data)
string token = *it++;
if (useDefaults == 1) {
if (pos == 0 && token.size() > 0) {
if (pos == 0 && token.size() > 0)
useDefaults = 0;
} else {
else
token = getDefault("", defaults, defaultPos).append(token);
}
}
istringstream input(token);
if (it == end)
@@ -257,7 +260,8 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
if (m_dstAddress == SYN)
return RESULT_ERR_INVALID_ADDR;
result = master.push_back(m_dstAddress, false, false);
} else
}
else
result = master.push_back(dstAddress, false, false);
if (result != RESULT_OK)
return result;
@@ -430,7 +434,7 @@ Message* MessageMap::find(const string& clazz, const string& name, const bool is
string lname = strtolower(name);
for (int i=0; i<2; i++) {
string key;
if (i==0)
if (i == 0)
key = string(isPassive ? "P" : (isSet ? "W" : "R")) + lclass + FIELD_SEPARATOR + lname;
else if (clazz.length() == 0)
key = string(isPassive ? "-P" : (isSet ? "-W" : "-R")) + lname; // second try: without class
@@ -473,10 +477,12 @@ deque<Message*> MessageMap::findAll(const string& clazz, const string& name, con
if (message->isPassive() == true) {
if (withPassive == false)
continue;
} else if (message->isSet() == true) {
}
else if (message->isSet() == true) {
if (withWrite == false)
continue;
} else {
}
else {
if (withRead == false)
continue;
}
+2 -1
View File
@@ -199,7 +199,8 @@ result_t DeviceNetwork::openDevice(const string deviceName, const bool noDeviceC
return RESULT_ERR_NOTFOUND;
memcpy(&sock.sin_addr, he->h_addr_list[0], he->h_length);
} else {
}
else {
ret = inet_aton(host, &sock.sin_addr);
if (ret == 0)
return RESULT_ERR_NOTFOUND;
+7 -7
View File
@@ -116,7 +116,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
if (isEscaped == false && value == ESC) {
m_data.push_back(ESC);
m_data.push_back(0x00);
if (updateCRC) {
if (updateCRC == true) {
addCRC(ESC);
addCRC(0x00);
}
@@ -124,14 +124,14 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
else if (isEscaped == false && value == SYN) {
m_data.push_back(ESC);
m_data.push_back(0x01);
if (updateCRC) {
if (updateCRC == true) {
addCRC(ESC);
addCRC(0x01);
}
}
else {
m_data.push_back(value);
if (updateCRC)
if (updateCRC == true)
addCRC(value);
}
@@ -141,7 +141,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
if (m_unescapeState != 1)
return RESULT_ERR_ESC; // invalid unescape state
m_data.push_back(value);
if (updateCRC) {
if (updateCRC == true) {
if (value == ESC) {
addCRC(ESC);
addCRC(0x00);
@@ -157,7 +157,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
return RESULT_OK;
}
else if (m_unescapeState != 1) {
if (updateCRC)
if (updateCRC == true)
addCRC(value);
if (value == 0x00) {
@@ -173,13 +173,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)
if (updateCRC == true)
addCRC(value);
m_unescapeState = 2;
return RESULT_IN_ESC;
}
if (updateCRC)
if (updateCRC == true)
addCRC(value);
m_data.push_back(value);
+4 -2
View File
@@ -100,7 +100,8 @@ int main()
continue;
}
cout << "\"" << check[2] << "\": find OK" << endl;
} else {
}
else {
vector<string>::iterator it = entries.begin();
result = Message::create(it, entries.end(), NULL, templates, deleteMessage);
if (failedCreate == true) {
@@ -162,7 +163,8 @@ int main()
bool match = inputStr == output.str();
verify(false, "decode", check[2] + "/" + check[3], match, inputStr, output.str());
} else {
}
else {
result = message->prepareMaster(0xff, writeMstr, input);
if (failedPrepare == true) {
if (result == RESULT_OK)
+4 -2
View File
@@ -90,7 +90,8 @@ bool Appl::parseArgs(int argc, char* argv[])
lastOption = true;
// find option with short format '-'
} else if (_argv[i].rfind("-") == 0 && _argv[i].size() > 1) {
}
else if (_argv[i].rfind("-") == 0 && _argv[i].size() > 1) {
// walk through all characters
for (size_t j = 1; j < _argv[i].size(); j++) {
@@ -110,7 +111,8 @@ bool Appl::parseArgs(int argc, char* argv[])
lastOption = true;
} else {
}
else {
// break loop with command
if (lastOption == false && strlen(m_withCommand) != 0)
break;
+2 -1
View File
@@ -58,7 +58,8 @@ TCPSocket* TCPClient::connect(const string& server, const int& port)
return NULL;
memcpy(&address.sin_addr, he->h_addr_list[0], he->h_length);
} else {
}
else {
ret = inet_aton(server.c_str(), &address.sin_addr);
if (ret == 0)
return NULL;
+2 -1
View File
@@ -86,7 +86,8 @@ public:
else if (m_queue.size() > 0) {
item = m_queue.front();
m_queue.pop_front();
} else
}
else
item = NULL;
pthread_mutex_unlock(&m_mutex);