add getField(), getDataType()

This commit is contained in:
John
2021-11-20 10:11:55 +01:00
parent dea6b976e2
commit 8370ba72b4
3 changed files with 54 additions and 0 deletions
+23
View File
@@ -997,6 +997,29 @@ string DataFieldSet::getName(ssize_t fieldIndex) const {
return ostream.str();
}
const SingleDataField* DataFieldSet::getField(ssize_t fieldIndex) const {
if (fieldIndex < (ssize_t)m_ignoredCount) {
return nullptr;
}
if ((size_t)fieldIndex + m_ignoredCount >= m_fields.size()) {
return nullptr;
}
if (m_ignoredCount == 0) {
return m_fields[fieldIndex];
}
ssize_t remain = fieldIndex;
for (const auto field : m_fields) {
if (field->isIgnored()) {
continue;
}
remain--;
if (remain == 0) {
return field;
}
}
return nullptr;
}
result_t DataFieldSet::derive(const string& name, PartType partType, int divisor,
const map<unsigned int, string>& values, map<string, string>* attributes,
vector<const SingleDataField*>* fields) const {
+24
View File
@@ -270,6 +270,13 @@ class DataField : public AttributedItem {
*/
virtual string getName(ssize_t fieldIndex) const = 0;
/**
* Get the specified field.
* @param fieldIndex the index of the field (excluding ignored fields).
* @return the field, or @a nullptr if not available.
*/
virtual const SingleDataField* getField(ssize_t fieldIndex) const = 0;
/**
* Dump the field settings to the output.
* @param prependFieldSeparator whether to start with a @a FIELD_SEPARATOR.
@@ -417,6 +424,20 @@ class SingleDataField : public DataField {
return isIgnored() || fieldIndex > 0 ? "" : m_name;
}
// @copydoc
virtual const SingleDataField* getField(ssize_t fieldIndex) const {
if (isIgnored() || fieldIndex > 0) {
return nullptr;
}
return const_cast<SingleDataField*>(this);
}
/**
* Return the data type definition.
* @return the data type definition.
*/
const DataType* getDataType() const { return m_dataType; }
/**
* Dump the common prefix field settings to the output (name and part type).
* @param prependFieldSeparator whether to start with a @a FIELD_SEPARATOR.
@@ -658,6 +679,9 @@ class DataFieldSet : public DataField {
// @copydoc
string getName(ssize_t fieldIndex) const override;
// @copydoc
const SingleDataField* getField(ssize_t fieldIndex) const override;
// @copydoc
result_t derive(const string& name, PartType partType, int divisor,
const map<unsigned int, string>& values, map<string, string>* attributes,
+7
View File
@@ -285,6 +285,13 @@ class Message : public AttributedItem {
*/
string getFieldName(ssize_t fieldIndex) const { return m_data->getName(fieldIndex); }
/**
* Get the specified field.
* @param fieldIndex the index of the field (excluding ignored fields).
* @return the field, or @a nullptr if not available.
*/
const SingleDataField* getField(ssize_t fieldIndex) const { return m_data->getField(fieldIndex); }
/**
* Get whether this is a write message.
* @return whether this is a write message.