switch ";" and "," but keep ";" for values shown in/parsed from UI, added todos, removed "p" for poll (use 1-9 instead), formatting
This commit is contained in:
+14
-32
@@ -59,19 +59,11 @@ Message::Message(const string clazz, const string name, const bool isSet,
|
||||
*/
|
||||
string getDefault(string value, vector<string>* defaults, size_t pos)
|
||||
{
|
||||
/*cout<<"getDefault("<<value<<",";
|
||||
if (defaults==NULL)
|
||||
cout<<"NULL";
|
||||
else
|
||||
cout<<static_cast<unsigned>(defaults->size());
|
||||
cout<<","<<static_cast<unsigned>(pos)<<"=";*/
|
||||
if (value.length() > 0 || defaults == NULL || pos > defaults->size()) {
|
||||
//cout<<value<<endl;
|
||||
return value;
|
||||
}
|
||||
|
||||
value = defaults->at(pos);
|
||||
//cout<<value<<endl;
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -79,7 +71,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
|
||||
vector< vector<string> >* defaultsRows,
|
||||
DataFieldTemplates* templates, Message*& returnValue)
|
||||
{
|
||||
// [type];[class];name;[comment];[QQ];ZZ;id;fields...
|
||||
// [type],[class],name,[comment],[QQ],ZZ,id,fields...
|
||||
result_t result;
|
||||
bool isSet = false, isPassive = false;
|
||||
char defaultsChar;
|
||||
@@ -96,33 +88,23 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
|
||||
} else if (strncasecmp(str, "W", 1) == 0) { // active set
|
||||
isSet = true;
|
||||
defaultsChar = 'w';
|
||||
} else if (strncasecmp(str, "P", 1) == 0) { // poll (=active get)
|
||||
if (str[1] == 0)
|
||||
pollPriority = 1;
|
||||
else {
|
||||
result_t result;
|
||||
pollPriority = parseInt(str+1, 10, 1, 9, result);
|
||||
if (result != RESULT_OK)
|
||||
return result;
|
||||
}
|
||||
defaultsChar = 'r';
|
||||
} else if (str[0] >= '0' && str[0] <= '9') { // poll priority (=active get)
|
||||
result_t result;
|
||||
pollPriority = parseInt(str, 10, 1, 9, result);
|
||||
pollPriority = parseInt(str, 10, 0, 9, result); // priority is the same as "r"
|
||||
if (result != RESULT_OK)
|
||||
return result;
|
||||
defaultsChar = 'r';
|
||||
} else { // any other: passive set/get
|
||||
isPassive = true;
|
||||
isSet = strncasecmp(str+1, "W", 1) == 0;
|
||||
defaultsChar = str[0];
|
||||
isSet = strcasecmp(str+strlen(str)-1, "W") == 0; // if type ends with "w" it is treated as passive set
|
||||
defaultsChar = str[0]; // TODO better not case sensitive, also in defaults definition
|
||||
}
|
||||
|
||||
vector<string>* defaults = NULL;
|
||||
if (defaultsRows != NULL && defaultsRows->size() > 0) {
|
||||
for (vector< vector<string> >::reverse_iterator it = defaultsRows->rbegin(); it != defaultsRows->rend(); it++) {
|
||||
string check = (*it)[0];
|
||||
if (check[0] == defaultsChar) {
|
||||
if (check[0] == defaultsChar) { // TODO better not case sensitive
|
||||
defaults = &(*it);
|
||||
break;
|
||||
}
|
||||
@@ -340,7 +322,7 @@ result_t MessageMap::add(Message* message)
|
||||
bool isSet = message->isSet();
|
||||
string clazz = message->getClass();
|
||||
string name = message->getName();
|
||||
string key = string(isPassive ? "P" : (isSet ? "W" : "R")) + clazz + ";" + name;
|
||||
string key = string(isPassive ? "P" : (isSet ? "W" : "R")) + clazz + FIELD_SEPARATOR + name;
|
||||
map<string, Message*>::iterator nameIt = m_messagesByName.find(key);
|
||||
if (nameIt != m_messagesByName.end()) {
|
||||
return RESULT_ERR_DUPLICATE; // duplicate key
|
||||
@@ -349,7 +331,7 @@ result_t MessageMap::add(Message* message)
|
||||
m_messagesByName[key] = message;
|
||||
m_messageCount++;
|
||||
|
||||
key = string(isPassive ? "-P;" : (isSet ? "-W;" : "-R;")) + name; // also store without class
|
||||
key = string(isPassive ? "-P" : (isSet ? "-W" : "-R")) + name; // also store without class
|
||||
m_messagesByName[key] = message; // last key without class overrides previous
|
||||
|
||||
if (message->isPassive() == true) {
|
||||
@@ -377,7 +359,7 @@ result_t MessageMap::addFromFile(vector<string>& row, DataFieldTemplates* arg, v
|
||||
|
||||
istringstream stream(types);
|
||||
string type;
|
||||
while (getline(stream, type, ',') != 0) {
|
||||
while (getline(stream, type, VALUE_SEPARATOR) != 0) {
|
||||
row[0] = type;
|
||||
vector<string>::iterator it = row.begin();
|
||||
result = Message::create(it, row.end(), defaults, arg, message);
|
||||
@@ -393,14 +375,14 @@ result_t MessageMap::addFromFile(vector<string>& row, DataFieldTemplates* arg, v
|
||||
return result;
|
||||
}
|
||||
|
||||
Message* MessageMap::find(const string& clazz, const string& name, const bool isSet,const bool isPassive)
|
||||
Message* MessageMap::find(const string& clazz, const string& name, const bool isSet, const bool isPassive)
|
||||
{
|
||||
for (int i=0; i<2; i++) {
|
||||
string key;
|
||||
if (i==0)
|
||||
key = string(isPassive ? "P" : (isSet ? "W" : "R")) + clazz + ";" + name;
|
||||
key = string(isPassive ? "P" : (isSet ? "W" : "R")) + clazz + FIELD_SEPARATOR + name;
|
||||
else
|
||||
key = string(isPassive ? "-P;" : (isSet ? "-W;" : "-R;")) + name; // second try: without class
|
||||
key = string(isPassive ? "-P" : (isSet ? "-W" : "-R")) + name; // second try: without class
|
||||
map<string, Message*>::iterator it = m_messagesByName.find(key);
|
||||
if (it != m_messagesByName.end())
|
||||
return it->second;
|
||||
@@ -422,7 +404,7 @@ Message* MessageMap::find(SymbolString& master)
|
||||
return NULL;
|
||||
|
||||
unsigned long long sourceMask = 0x1fLL << (8 * 7);
|
||||
for (int idLength=maxIdLength; idLength>=m_minIdLength; idLength--) {
|
||||
for (int idLength = maxIdLength; idLength >= m_minIdLength; idLength--) {
|
||||
int exp = 7;
|
||||
unsigned long long key = (unsigned long long)idLength << (8 * exp + 5);
|
||||
key |= (unsigned long long)getMasterNumber(master[0]) << (8 * exp--);
|
||||
@@ -455,8 +437,8 @@ void MessageMap::clear()
|
||||
m_pollMessages.pop();
|
||||
}
|
||||
// free message instances
|
||||
for (map<string, Message*>::iterator it=m_messagesByName.begin(); it!=m_messagesByName.end(); it++) {
|
||||
if (it->first[0] != '-') // avoid double free
|
||||
for (map<string, Message*>::iterator it = m_messagesByName.begin(); it != m_messagesByName.end(); it++) {
|
||||
if (it->first[0] != '-') // avoid double free: instances stored multiple times have a key starting with "-"
|
||||
delete it->second;
|
||||
it->second = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user