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)
68 string currentLabel(
label());
71 if (sibling !=
this && currentLabel == sibling->label()) {
72 stringstream newLabel(currentLabel);
73 newLabel.seekp(0, ios_base::end);
74 if (newLabel.tellp()) {
78 currentLabel = newLabel.str();
82 m_label = currentLabel;
94 if (m_parent != parent || (m_index != index && index >= 0)) {
96 m_parent->m_children.erase(m_parent->m_children.begin() + m_index);
97 for (
auto i = m_parent->m_children.begin() + m_index; i < m_parent->m_children.end(); ++i) {
102 if (index < 0 || static_cast<size_t>(index) >= parent->m_children.size()) {
103 m_index = parent->m_children.size();
104 parent->m_children.push_back(
this);
106 for (
auto i = parent->m_children.insert(parent->m_children.begin() +
index,
this) + 1; i != parent->m_children.end(); ++i) {
153 res.push_back(
label());
162 byte version = stream.peek();
197 , m_expandedByDefault(true)
205 :
Entry(label, parent)
206 , m_expandedByDefault(true)
214 : m_expandedByDefault(true)
216 BinaryReader reader(&stream);
217 byte version = reader.readByte();
219 if (version == 0x0 || version == 0x1) {
220 setLabel(reader.readLengthPrefixedString());
221 if (version == 0x1) {
222 uint16 extendedHeaderSize = reader.readUInt16BE();
223 if (extendedHeaderSize >= 1) {
224 byte flags = reader.readByte();
225 m_expandedByDefault = flags & 0x80;
226 extendedHeaderSize -= 1;
230 uint32 childCount = reader.readUInt32BE();
231 for (uint32 i = 0; i < childCount; ++i) {
250 for (
Entry *otherChild : other.m_children) {
252 clonedChild->m_parent =
this;
253 clonedChild->m_index = m_children.size();
254 m_children.push_back(clonedChild);
263 for (
Entry *child : m_children) {
264 child->m_parent =
nullptr;
276 auto iterator = m_children.cbegin() + begin;
277 auto endIterator = m_children.begin() + end;
278 for (; iterator < endIterator; ++iterator) {
279 (*iterator)->m_parent =
nullptr;
282 m_children.erase(m_children.begin() + begin, endIterator);
290 if (at < m_children.size()) {
291 m_children.at(at)->m_parent =
nullptr;
292 m_children[at] = newChild;
309 if (path.front() ==
label()) {
316 for (
Entry *child : m_children) {
317 if (path.front() == child->label()) {
329 if (path.size() == 1) {
330 switch (*creationType) {
334 return new NodeEntry(path.front(),
this);
349 BinaryWriter writer(&stream);
351 writer.writeLengthPrefixedString(
label());
358 writer.writeByte(flags);
361 writer.writeUInt32BE(m_children.size());
362 for (
const Entry *child : m_children) {
385 :
Entry(label, parent)
394 BinaryReader reader(&stream);
395 byte version = reader.readByte();
398 if (version == 0x0 || version == 0x1) {
399 setLabel(reader.readLengthPrefixedString());
400 if (version == 0x1) {
401 uint16 extendedHeaderSize = reader.readUInt16BE();
405 uint32 fieldCount = reader.readUInt32BE();
406 for (uint32 i = 0; i < fieldCount; ++i) {
407 m_fields.push_back(
Field(
this, stream));
425 m_fields = other.m_fields;
437 BinaryWriter writer(&stream);
439 writer.writeLengthPrefixedString(
label());
444 writer.writeUInt32BE(m_fields.size());
445 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...