fixed getNextOffset() and added optional PartType argument, renamed pt_template to pt_any, added getPartType()
This commit is contained in:
+20
-9
@@ -165,7 +165,7 @@ result_t DataField::create(std::vector<std::string>::iterator& it,
|
||||
posStr++;
|
||||
}
|
||||
else if (isTemplate) {
|
||||
partType = pt_template;
|
||||
partType = pt_any;
|
||||
}
|
||||
else {
|
||||
result = RESULT_ERR_INVALID_ARG;
|
||||
@@ -174,7 +174,7 @@ result_t DataField::create(std::vector<std::string>::iterator& it,
|
||||
|
||||
if (posStr[0] == 0) {
|
||||
if (fields.empty() == false)
|
||||
offset = fields.back()->getNextOffset();
|
||||
offset = fields.back()->getNextOffset(partType);
|
||||
else
|
||||
offset = 0;
|
||||
length = 0;
|
||||
@@ -274,7 +274,7 @@ result_t DataField::create(std::vector<std::string>::iterator& it,
|
||||
result = ref->second->derive(name, comment, unit, partType, offset, divisor, values, fields);
|
||||
if (result != RESULT_OK)
|
||||
break;
|
||||
offset = fields.back()->getNextOffset();
|
||||
offset = fields.back()->getNextOffset(partType);
|
||||
}
|
||||
if (offset > MAX_POS) {
|
||||
result = RESULT_ERR_INVALID_ARG; // invalid pos definition
|
||||
@@ -362,8 +362,11 @@ result_t DataField::create(std::vector<std::string>::iterator& it,
|
||||
}
|
||||
|
||||
|
||||
unsigned char SingleDataField::getNextOffset()
|
||||
unsigned char SingleDataField::getNextOffset(PartType partType)
|
||||
{
|
||||
if (partType != pt_any && partType != m_partType)
|
||||
return 0;
|
||||
|
||||
unsigned char offset = m_offset + m_length;
|
||||
if ((m_dataType.numBits % 8) != 0
|
||||
&& m_dataType.precisionOrFirstBit + (m_dataType.numBits % 8) < 8)
|
||||
@@ -429,7 +432,7 @@ result_t StringDataField::derive(std::string name, std::string comment,
|
||||
unsigned int divisor, std::map<unsigned int, std::string> values,
|
||||
std::vector<SingleDataField*>& fields)
|
||||
{
|
||||
if (m_partType != pt_template && partType == pt_template)
|
||||
if (m_partType != pt_any && partType == pt_any)
|
||||
return RESULT_ERR_INVALID_ARG; // cannot create a template from a concrete instance
|
||||
if (divisor != 0 || values.empty() == false)
|
||||
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
|
||||
@@ -706,7 +709,7 @@ result_t NumberDataField::derive(std::string name, std::string comment,
|
||||
unsigned int divisor, std::map<unsigned int, std::string> values,
|
||||
std::vector<SingleDataField*>& fields)
|
||||
{
|
||||
if (m_partType != pt_template && partType == pt_template)
|
||||
if (m_partType != pt_any && partType == pt_any)
|
||||
return RESULT_ERR_INVALID_ARG; // cannot create a template from a concrete instance
|
||||
if (name.empty() == true)
|
||||
name = m_name;
|
||||
@@ -840,7 +843,7 @@ result_t ValueListDataField::derive(std::string name, std::string comment,
|
||||
unsigned int divisor, std::map<unsigned int, std::string> values,
|
||||
std::vector<SingleDataField*>& fields)
|
||||
{
|
||||
if (m_partType != pt_template && partType == pt_template)
|
||||
if (m_partType != pt_any && partType == pt_any)
|
||||
return RESULT_ERR_INVALID_ARG; // cannot create a template from a concrete instance
|
||||
if (name.empty() == true)
|
||||
name = m_name;
|
||||
@@ -911,9 +914,17 @@ DataFieldSet::~DataFieldSet()
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char DataFieldSet::getNextOffset()
|
||||
unsigned char DataFieldSet::getNextOffset(PartType partType)
|
||||
{
|
||||
return m_fields.back()->getNextOffset();
|
||||
return 0;
|
||||
|
||||
for (std::vector<SingleDataField*>::reverse_iterator it = m_fields.rbegin(); it < m_fields.rend(); it++) {
|
||||
SingleDataField* field = *it;
|
||||
if (partType == pt_any || partType == field->getPartType())
|
||||
return field->getNextOffset(partType);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
result_t DataFieldSet::derive(std::string name, std::string comment,
|
||||
|
||||
+13
-7
@@ -28,7 +28,7 @@
|
||||
|
||||
/** the message part in which a data field is stored. */
|
||||
enum PartType {
|
||||
pt_template, // special part type for templates (relative offset)
|
||||
pt_any, // stored in any data (master or slave, relative offset)
|
||||
pt_masterData, // stored in master data
|
||||
pt_slaveData, // stored in slave data
|
||||
};
|
||||
@@ -112,9 +112,10 @@ public:
|
||||
const bool isSetMessage=false, const unsigned char dstAddress=SYN);
|
||||
/**
|
||||
* @brief Returns the offset to the first symbol in the message part for a field following this field.
|
||||
* @param partType the message part for which to get the offset, or @a pt_any for any.
|
||||
* @return the offset to the first symbol in the message part for a field following this field.
|
||||
*/
|
||||
virtual unsigned char getNextOffset() = 0;
|
||||
virtual unsigned char getNextOffset(PartType partType=pt_any) = 0;
|
||||
/**
|
||||
* @brief Derives a new DataField from this field.
|
||||
* @param name the field name.
|
||||
@@ -134,12 +135,12 @@ public:
|
||||
* @brief Get the field name.
|
||||
* @return the field name.
|
||||
*/
|
||||
const std::string getName() { return m_name; }
|
||||
std::string getName() const { return m_name; }
|
||||
/**
|
||||
* @brief Get the field comment.
|
||||
* @return the field comment.
|
||||
*/
|
||||
const std::string getComment() { return m_comment; }
|
||||
std::string getComment() const { return m_comment; }
|
||||
/**
|
||||
* @brief Reads the value from the master or slave @a SymbolString.
|
||||
* @param masterData the unescaped master data @a SymbolString for reading binary data.
|
||||
@@ -204,9 +205,14 @@ public:
|
||||
* @brief Get the value unit.
|
||||
* @return the value unit.
|
||||
*/
|
||||
const std::string getUnit() { return m_unit; }
|
||||
std::string getUnit() const { return m_unit; }
|
||||
/**
|
||||
* @brief Get the message part in which the field is stored.
|
||||
* @return the message part in which the field is stored.
|
||||
*/
|
||||
PartType getPartType() const { return m_partType; }
|
||||
// @copydoc
|
||||
virtual unsigned char getNextOffset();
|
||||
virtual unsigned char getNextOffset(PartType partType=pt_any);
|
||||
/**
|
||||
* @brief Reads the value from the master or slave @a SymbolString.
|
||||
* @param masterData the unescaped master data @a SymbolString for reading binary data.
|
||||
@@ -470,7 +476,7 @@ public:
|
||||
*/
|
||||
virtual ~DataFieldSet();
|
||||
// @copydoc
|
||||
virtual unsigned char getNextOffset();
|
||||
virtual unsigned char getNextOffset(PartType partType=pt_any);
|
||||
// @copydoc
|
||||
virtual result_t derive(std::string name, std::string comment,
|
||||
std::string unit, const PartType partType, unsigned char offset,
|
||||
|
||||
Reference in New Issue
Block a user