added helper for dumping messages, corrected line number printing
This commit is contained in:
+32
-10
@@ -114,7 +114,7 @@ void printErrorPos(vector<string>::iterator begin, const vector<string>::iterato
|
||||
{
|
||||
if (pos > begin)
|
||||
pos--;
|
||||
cout << "Error reading \"" << filename << "\" line " << static_cast<unsigned>(lineNo) << " field " << static_cast<unsigned>(1+pos.base()-begin.base()) << " value \"" << *pos << "\": " << getResultCode(result) << endl;
|
||||
cout << "Error reading \"" << filename << "\" line " << setw(0) << dec << static_cast<unsigned>(lineNo) << " field " << static_cast<unsigned>(1+pos.base()-begin.base()) << " value \"" << *pos << "\": " << getResultCode(result) << endl;
|
||||
cout << "Erroneous item is here:" << endl;
|
||||
bool first = true;
|
||||
int cnt = 0;
|
||||
@@ -376,15 +376,28 @@ result_t DataField::create(vector<string>::iterator& it,
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
void DataField::dumpString(ostream& output, const string str, const bool prependFieldSeparator)
|
||||
{
|
||||
if (prependFieldSeparator)
|
||||
output << FIELD_SEPARATOR;
|
||||
if (str.find_first_of(FIELD_SEPARATOR) == string::npos) {
|
||||
output << str;
|
||||
} else {
|
||||
output << TEXT_SEPARATOR << str << TEXT_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SingleDataField::dump(ostream& output)
|
||||
{
|
||||
output << m_name << FIELD_SEPARATOR;
|
||||
output << setw(0) << dec; // initialize formatting
|
||||
dumpString(output, m_name, false);
|
||||
output << FIELD_SEPARATOR;
|
||||
if (m_partType == pt_masterData)
|
||||
output << "m";
|
||||
else if (m_partType == pt_slaveData)
|
||||
output << "s";
|
||||
output << FIELD_SEPARATOR << m_dataType.name;
|
||||
dumpString(output, m_dataType.name);
|
||||
}
|
||||
|
||||
result_t SingleDataField::read(const PartType partType,
|
||||
@@ -480,8 +493,9 @@ void StringDataField::dump(ostream& output)
|
||||
SingleDataField::dump(output);
|
||||
if ((m_dataType.flags & ADJ) != 0)
|
||||
output << ":" << static_cast<unsigned>(m_length);
|
||||
output << FIELD_SEPARATOR << FIELD_SEPARATOR; // no value list, no divisor
|
||||
output << m_unit << FIELD_SEPARATOR << m_comment << FIELD_SEPARATOR;
|
||||
output << FIELD_SEPARATOR; // no value list, no divisor
|
||||
dumpString(output, m_unit);
|
||||
dumpString(output, m_comment);
|
||||
}
|
||||
|
||||
result_t StringDataField::readSymbols(SymbolString& input,
|
||||
@@ -873,8 +887,10 @@ result_t NumberDataField::derive(string name, string comment,
|
||||
void NumberDataField::dump(ostream& output)
|
||||
{
|
||||
NumericDataField::dump(output);
|
||||
output << static_cast<unsigned>(m_divisor) << FIELD_SEPARATOR;
|
||||
output << m_unit << FIELD_SEPARATOR << m_comment << FIELD_SEPARATOR;
|
||||
if ((m_dataType.bitCount%8) != 0 && m_dataType.divisorOrFirstBit != m_divisor)
|
||||
output << static_cast<unsigned>(m_divisor / m_dataType.divisorOrFirstBit) << FIELD_SEPARATOR;
|
||||
dumpString(output, m_unit);
|
||||
dumpString(output, m_comment);
|
||||
}
|
||||
|
||||
result_t NumberDataField::readSymbols(SymbolString& input,
|
||||
@@ -1025,8 +1041,8 @@ void ValueListDataField::dump(ostream& output)
|
||||
output << VALUE_SEPARATOR;
|
||||
output << static_cast<unsigned>(it->first) << "=" << it->second;
|
||||
}
|
||||
output << FIELD_SEPARATOR;
|
||||
output << m_unit << FIELD_SEPARATOR << m_comment << FIELD_SEPARATOR;
|
||||
dumpString(output, m_unit);
|
||||
dumpString(output, m_comment);
|
||||
}
|
||||
|
||||
result_t ValueListDataField::readSymbols(SymbolString& input,
|
||||
@@ -1156,8 +1172,14 @@ result_t DataFieldSet::derive(string name, string comment,
|
||||
|
||||
void DataFieldSet::dump(ostream& output)
|
||||
{
|
||||
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++)
|
||||
bool first = true;
|
||||
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
output << FIELD_SEPARATOR;
|
||||
(*it)->dump(output);
|
||||
}
|
||||
}
|
||||
|
||||
result_t DataFieldSet::read(const PartType partType,
|
||||
|
||||
@@ -147,6 +147,14 @@ public:
|
||||
DataFieldTemplates* templates, DataField*& returnField,
|
||||
const bool isWriteMessage=false, const unsigned char dstAddress=SYN);
|
||||
|
||||
/**
|
||||
* Dump the @a string optionally embedded in @a TEXT_SEPARATOR to the output.
|
||||
* @param output the @a ostream to dump to.
|
||||
* @param str the @a string to dump.
|
||||
* @param prependFieldSeparator whether to start with a @a FIELD_SEPARATOR.
|
||||
*/
|
||||
static void dumpString(ostream& output, const string str, const bool prependFieldSeparator=true);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -371,6 +372,41 @@ bool Message::isLessPollWeight(const Message* other)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Message::dump(ostream& output)
|
||||
{
|
||||
if (m_isPassive) {
|
||||
output << "u";
|
||||
if (m_isWrite)
|
||||
output << "w";
|
||||
} else if (m_isWrite)
|
||||
output << "w";
|
||||
else {
|
||||
output << "r";
|
||||
if (m_pollPriority>0)
|
||||
output << static_cast<unsigned>(m_pollPriority);
|
||||
}
|
||||
DataField::dumpString(output, m_class);
|
||||
DataField::dumpString(output, m_name);
|
||||
DataField::dumpString(output, m_comment);
|
||||
output << FIELD_SEPARATOR;
|
||||
if (m_srcAddress != SYN)
|
||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(m_srcAddress);
|
||||
output << FIELD_SEPARATOR;
|
||||
if (m_dstAddress != SYN)
|
||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(m_dstAddress);
|
||||
output << FIELD_SEPARATOR;
|
||||
unsigned int cnt = 0;
|
||||
for (vector<unsigned char>::const_iterator it=m_id.begin(); it<m_id.end(); it++) {
|
||||
if (cnt++ == 2)
|
||||
output << FIELD_SEPARATOR;
|
||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
|
||||
}
|
||||
if (cnt <= 2)
|
||||
output << FIELD_SEPARATOR; // no further ID bytes besides PBSB
|
||||
output << FIELD_SEPARATOR;
|
||||
m_data->dump(output);
|
||||
}
|
||||
|
||||
|
||||
string strtolower(const string& str)
|
||||
{
|
||||
@@ -587,3 +623,20 @@ Message* MessageMap::getNextPoll()
|
||||
m_pollMessages.push(ret); // re-insert at new position
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MessageMap::dump(ostream& output)
|
||||
{
|
||||
bool first = true;
|
||||
for (map<string, Message*>::iterator it = m_messagesByName.begin(); it != m_messagesByName.end(); it++) {
|
||||
if (it->first[0] == '-') // skip instances stored multiple times (key starting with "-")
|
||||
continue;
|
||||
Message* message = it->second;
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
cout << endl;
|
||||
message->dump(cout);
|
||||
}
|
||||
if (!first)
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
+13
-1
@@ -240,6 +240,12 @@ public:
|
||||
*/
|
||||
bool isLessPollWeight(const Message* other);
|
||||
|
||||
/**
|
||||
* Write the message definition to the @a ostream.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
*/
|
||||
void dump(ostream& output);
|
||||
|
||||
private:
|
||||
|
||||
/** the optional device class. */
|
||||
@@ -261,7 +267,7 @@ private:
|
||||
/** the source address, or @a SYN for any (only relevant if passive). */
|
||||
const unsigned char m_srcAddress;
|
||||
|
||||
/** the destination address. */
|
||||
/** the destination address, or @a SYN for any (only for temporary scan messages). */
|
||||
const unsigned char m_dstAddress;
|
||||
|
||||
/** the primary, secondary, and optionally further command ID bytes. */
|
||||
@@ -396,6 +402,12 @@ public:
|
||||
*/
|
||||
Message* getNextPoll();
|
||||
|
||||
/**
|
||||
* Write the message definitions to the @a ostream.
|
||||
* @param output the @a ostream to append the formatted messages to.
|
||||
*/
|
||||
void dump(ostream& output);
|
||||
|
||||
private:
|
||||
|
||||
/** the minimum ID length used by any of the known @a Message instances. */
|
||||
|
||||
Reference in New Issue
Block a user