Skip to content

Commit

Permalink
AURORA: Add GFF3Struct::addList()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Mar 3, 2016
1 parent aca5d37 commit 9241e5f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
35 changes: 33 additions & 2 deletions src/aurora/gff3file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ void GFF3File::destroyStruct(GFF3Struct &strct) {
delete &strct;
}

GFF3List &GFF3File::createList() {
const uint32 uid = _nextListUID++;

std::pair<ListMap::iterator, bool> result = _lists.insert(std::make_pair(uid, GFF3List(*this, uid)));

return result.first->second;
}

Common::SeekableReadStream &GFF3File::getStream(uint32 offset) const {
_stream->seek(offset);

Expand Down Expand Up @@ -861,8 +869,10 @@ void GFF3Struct::addField(const Common::UString &field, FieldType type) {
return;
}

if (type == kFieldTypeList)
throw Common::Exception("GFF3: Can't create a list with addField()");
if (type == kFieldTypeList) {
addList(field);
return;
}

Field f(type);

Expand Down Expand Up @@ -934,6 +944,24 @@ void GFF3Struct::removeStruct(const Common::UString &field) {
_fieldNames.erase(n);
}

GFF3List &GFF3Struct::addList(const Common::UString &field) {
Field f(kFieldTypeList);

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);

GFF3List &list = _parent->createList();

result.first->second.data = list.getUID();

return list;
}

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

GFF3Struct::Field *GFF3Struct::getField(const Common::UString &name) {
Expand Down Expand Up @@ -1227,6 +1255,9 @@ void GFF3Struct::setString(const Common::UString &field, Common::SeekableReadStr
}


GFF3List::GFF3List(GFF3File &parent, uint32 uid) : _parent(&parent), _uid(uid) {
}

GFF3List::GFF3List(GFF3File &parent, uint32 uid, const std::vector<const GFF3Struct *> &list) :
_parent(&parent), _uid(uid), _list(list) {

Expand Down
7 changes: 6 additions & 1 deletion src/aurora/gff3file.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class GFF3File : public AuroraFile {

GFF3Struct &createStruct(uint32 id);
void destroyStruct(GFF3Struct &strct);

GFF3List &createList();
// '---

friend class GFF3Struct;
Expand Down Expand Up @@ -279,7 +281,6 @@ class GFF3Struct {
/** Create an empty field with this name and type.
*
* The field in question must not already exists.
* Lists cannot be added/created with this method.
*/
void addField(const Common::UString &field, FieldType type);
/** Remove a field with this name.
Expand All @@ -293,6 +294,9 @@ class GFF3Struct {

/** Remove a struct field completely. */
void removeStruct(const Common::UString &field);

/** Create an empty list field with this name and return it. */
GFF3List &addList(const Common::UString &field);
// '---

// .--- Write field values
Expand Down Expand Up @@ -421,6 +425,7 @@ class GFF3List {
std::vector<const GFF3Struct *> _list;


GFF3List(GFF3File &parent, uint32 uid);
GFF3List(GFF3File &parent, uint32 uid, const std::vector<const GFF3Struct *> &list);

friend class GFF3File;
Expand Down

0 comments on commit 9241e5f

Please sign in to comment.