Skip to content

Commit

Permalink
AURORA: Add GFF3Struct::addField()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Mar 3, 2016
1 parent ccc71f3 commit 617748d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/aurora/gff3file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,28 @@ const GFF3List &GFF3Struct::getList(const Common::UString &field) const {
return _parent->getList(f->data / 4);
}

// --- Field adding and deleting ---

void GFF3Struct::addField(const Common::UString &field, FieldType type) {
if ((type <= kFieldTypeNone) || (type >= kFieldTypeMAX))
throw Common::Exception("GFF3: Invalid field type");

if (type == kFieldTypeStruct)
throw Common::Exception("GFF3: Can't create a struct with addField()");
if (type == kFieldTypeList)
throw Common::Exception("GFF3: Can't create a list with addField()");

Field f(type);

std::pair<FieldMap::iterator, bool> result;

result = _fields.insert(std::make_pair(field, f));
if (!result.second)
throw Common::Exception("GFF3: Field \"%s\" already exists", field.c_str());

_fieldNames.push_back(field);
}

// --- Field value write helpers ---

GFF3Struct::Field *GFF3Struct::getField(const Common::UString &name) {
Expand Down
13 changes: 12 additions & 1 deletion src/aurora/gff3file.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ class GFF3Struct {
kFieldTypeList = 15, ///< List containing a number of structs.
kFieldTypeOrientation = 16, ///< An object orientation.
kFieldTypeVector = 17, ///< A vector of 3 floats.
kFieldTypeStrRef = 18 ///< String reference, index into a talk table.
kFieldTypeStrRef = 18, ///< String reference, index into a talk table.

kFieldTypeMAX
};

/** Return the struct's unique ID within the GFF3.
Expand Down Expand Up @@ -253,6 +255,15 @@ class GFF3Struct {
const GFF3List &getList (const Common::UString &field) const;
// '---

// .--- Field adder/deleter
/** Create an empty field with this name and type.
*
* The field in question must not already exists.
* Structs and lists cannot be added/created with this method.
*/
void addField(const Common::UString &field, FieldType type);
// '---

// .--- Write field values
void setChar(const Common::UString &field, char value);
void setUint(const Common::UString &field, uint64 value);
Expand Down

0 comments on commit 617748d

Please sign in to comment.