4 #include <c++utilities/io/binaryreader.h> 5 #include <c++utilities/io/binarywriter.h> 32 Entry::Entry(
const string &label,
NodeEntry *parent) :
46 m_label(other.m_label),
67 string currentLabel(
label());
70 if(sibling !=
this && currentLabel == sibling->label()) {
71 stringstream newLabel(currentLabel);
72 newLabel.seekp(0, ios_base::end);
73 if(newLabel.tellp()) {
77 currentLabel = newLabel.str();
81 m_label = currentLabel;
93 if(m_parent != parent || (m_index != index && index >= 0)) {
95 m_parent->m_children.erase(m_parent->m_children.begin() + m_index);
96 for(
auto i = m_parent->m_children.begin() + m_index; i < m_parent->m_children.end(); ++i) {
101 if(index < 0 || static_cast<size_t>(index) >= parent->m_children.size()) {
102 m_index = parent->m_children.size();
103 parent->m_children.push_back(
this);
105 for(
auto i = parent->m_children.insert(parent->m_children.begin() +
index,
this) + 1;
106 i != parent->m_children.end(); ++i) {
153 res.push_back(
label());
162 byte version = stream.peek();
197 m_expandedByDefault(true)
204 Entry(label, parent),
205 m_expandedByDefault(true)
212 m_expandedByDefault(true)
214 BinaryReader reader(&stream);
215 byte version = reader.readByte();
217 if(version == 0x0 || version == 0x1) {
218 setLabel(reader.readLengthPrefixedString());
220 uint16 extendedHeaderSize = reader.readUInt16BE();
221 if(extendedHeaderSize >= 1) {
222 byte flags = reader.readByte();
223 m_expandedByDefault = flags & 0x80;
224 extendedHeaderSize -= 1;
228 uint32 childCount = reader.readUInt32BE();
229 for(uint32 i = 0; i < childCount; ++i) {
248 for(
Entry *otherChild : other.m_children) {
250 clonedChild->m_parent =
this;
251 clonedChild->m_index = m_children.size();
252 m_children.push_back(clonedChild);
261 for(
Entry *child : m_children) {
262 child->m_parent =
nullptr;
274 auto iterator = m_children.cbegin() + begin;
275 auto endIterator = m_children.begin() + end;
276 for(; iterator < endIterator; ++iterator) {
277 (*iterator)->m_parent =
nullptr;
280 m_children.erase(m_children.begin() + begin, endIterator);
288 if(at < m_children.size()) {
289 m_children.at(at)->m_parent =
nullptr;
290 m_children[at] = newChild;
307 if(path.front() ==
label()) {
314 for(
Entry *child : m_children) {
315 if(path.front() == child->label()) {
327 if(path.size() == 1) {
328 switch(*creationType) {
332 return new NodeEntry(path.front(),
this);
347 BinaryWriter writer(&stream);
349 writer.writeLengthPrefixedString(
label());
356 writer.writeByte(flags);
359 writer.writeUInt32BE(m_children.size());
360 for(
const Entry *child : m_children) {
390 BinaryReader reader(&stream);
391 byte version = reader.readByte();
394 if(version == 0x0 || version == 0x1) {
395 setLabel(reader.readLengthPrefixedString());
397 uint16 extendedHeaderSize = reader.readUInt16BE();
401 uint32 fieldCount = reader.readUInt32BE();
402 for(uint32 i = 0; i < fieldCount; ++i) {
403 m_fields.push_back(
Field(
this, stream));
421 m_fields = other.m_fields;
432 BinaryWriter writer(&stream);
434 writer.writeLengthPrefixedString(
label());
439 writer.writeUInt32BE(m_fields.size());
440 for(
const Field &field : m_fields) {
~NodeEntry()
Destroys the entry.
NodeEntry * parent() const
Returns the parent entry.
The NodeEntry class acts as parent for other entries.
virtual void make(std::ostream &stream) const
Serializes the entry to the specified stream.
const std::string & label() const
Returns the label.
void setLabel(const std::string &label)
Sets the label.
~AccountEntry()
Destroys the entry.
bool isIndirectChildOf(NodeEntry *entry) const
Returns an indication whether the instance is an indirect child of the specified entry.
NodeEntry()
Constructs a new node entry.
virtual Entry * clone() const =0
Clones the entry.
bool isExpandedByDefault() const
Contains all IO related classes.
int index() const
Returns the index of the entry within its parent.
Entry * entryByPath(std::list< std::string > &path, bool includeThis=true, EntryType *creationType=nullptr)
Returns an entry specified by the provided path.
virtual NodeEntry * clone() const
Clones the entry.
std::list< std::string > path() const
Returns the path of the entry.
std::string m_extendedData
The Field class holds field information which consists of a name and a value and is able to serialize...
The exception that is thrown when a parsing error occurs.
Entry(const std::string &label=std::string(), NodeEntry *parent=nullptr)
Constructs a new entry with the specified label and parent.
virtual void make(std::ostream &stream) const
Serializes the entry to the specified stream.
static Entry * parse(std::istream &stream)
Parses an entry from the specified stream.
virtual AccountEntry * clone() const
Clones the entry.
virtual ~Entry()
Destroys the entry.
static bool denotesNodeEntry(byte version)
const std::vector< Entry * > & children() const
void makeLabelUnique()
Internally called to make the label unique.
void replaceChild(size_t at, Entry *newChild)
Replaces the child at the specified index with the specified newChild.
void setParent(NodeEntry *parent, int index=-1)
Sets the parent for the entry.
void deleteChildren(int begin, int end)
Deletes children from the node entry.
EntryType
Specifies the entry type.
The exception that is thrown when a parsing error occurs.
Instances of the Entry class form a hierarchic data strucutre used to store account information...