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
+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,