From b33c0504f609f6456ed043f6f91ba30735d87610 Mon Sep 17 00:00:00 2001 From: "Marcel M. Otte" Date: Fri, 25 Nov 2016 22:43:36 +0100 Subject: [PATCH] [ci skip] commiting current changes Huge changes in the model and protocol loading part. Trying to keep Qt out of these lowlevel parts, so trying to achieve everything with boost or std. --- .gitignore | 1 + src/CMakeLists.txt | 2 +- src/editor/CMakeLists.txt | 4 - src/editor/EditorNode.h | 74 -------- src/editor/EditorTree.cpp | 15 -- src/editor/EditorTree.h | 25 --- src/editor/guidededitorelementview.cpp | 8 +- src/editor/guidededitorelementview.h | 8 +- src/editor/guidededitorview.cpp | 6 +- src/editor/guidededitorview.h | 6 +- src/model/CMakeLists.txt | 10 +- src/model/{packetelement.cpp => Field.cpp} | 8 +- src/model/Field.h | 121 ++++++++++++ src/model/Protocol.cpp | 13 ++ src/model/{packetmodel.h => Protocol.h} | 10 +- src/model/Tree.h | 40 ++++ .../EditorNode.cpp => model/TreeNode.h} | 174 +++++++++++++----- src/model/packetelement.h | 101 ---------- src/model/packetmodel.cpp | 13 -- src/{protocol => parser}/CMakeLists.txt | 0 src/{protocol => parser}/DataLoader.cpp | 0 src/{protocol => parser}/DataLoader.h | 6 +- 22 files changed, 340 insertions(+), 305 deletions(-) delete mode 100644 src/editor/EditorNode.h delete mode 100644 src/editor/EditorTree.cpp delete mode 100644 src/editor/EditorTree.h rename src/model/{packetelement.cpp => Field.cpp} (62%) create mode 100644 src/model/Field.h create mode 100644 src/model/Protocol.cpp rename src/model/{packetmodel.h => Protocol.h} (50%) create mode 100644 src/model/Tree.h rename src/{editor/EditorNode.cpp => model/TreeNode.h} (53%) delete mode 100644 src/model/packetelement.h delete mode 100644 src/model/packetmodel.cpp rename src/{protocol => parser}/CMakeLists.txt (100%) rename src/{protocol => parser}/DataLoader.cpp (100%) rename src/{protocol => parser}/DataLoader.h (72%) diff --git a/.gitignore b/.gitignore index f8ac05f..899ebfe 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.pro.user build *.user* +doc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 39d0f3b..33203c5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ set(SOURCES mainwindow.cpp add_subdirectory(model) add_subdirectory(editor) -add_subdirectory(protocol) +add_subdirectory(parser) add_library(src ${HEADERS} ${SOURCES}) target_link_libraries(src model editor protocol) diff --git a/src/editor/CMakeLists.txt b/src/editor/CMakeLists.txt index c5fb1fa..a679fc0 100644 --- a/src/editor/CMakeLists.txt +++ b/src/editor/CMakeLists.txt @@ -2,8 +2,6 @@ set(HEADERS editorelementdata.h guidededitorelementview.h flowlayout.h - EditorNode.h - EditorTree.h EditorElementValue.h ) @@ -11,8 +9,6 @@ set(SOURCES guidededitorelementview.cpp editorelementdata.cpp guidededitorview.cpp flowlayout.cpp - EditorNode.cpp - EditorTree.cpp EditorElementValue.cpp ) diff --git a/src/editor/EditorNode.h b/src/editor/EditorNode.h deleted file mode 100644 index 55aa754..0000000 --- a/src/editor/EditorNode.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef EDITORNODE_H -#define EDITORNODE_H - -#include -#include -#include - -#include "editorelementdata.h" -#include "EditorElementValue.h" - -class EditorNode; - -enum class TreeWalkStrategy { - depthFirst, - breadthFirst, - mixture -}; - -class EditorNode -{ -public: - explicit EditorNode(); - explicit EditorNode(std::shared_ptr data); - virtual ~EditorNode(); - - const std::shared_ptr nextSibling(); - - const std::shared_ptr next(TreeWalkStrategy walkStrategy = TreeWalkStrategy::depthFirst); - const std::shared_ptr getRoot(); - void move(std::shared_ptr to); //as child - void moveChildren(std::shared_ptr to); //all - - void addChild(std::shared_ptr child); - bool removeChild(std::shared_ptr child); - bool remove(); - - std::shared_ptr getParent() const; - void setParent(const std::shared_ptr &value); - - std::shared_ptr getData() const; - void setData(const std::shared_ptr &value); - - std::shared_ptr getValue() const; - void setValue(const std::shared_ptr &value); - - std::list > getChildren() const; - - void setDataChangedSignal(std::function)> f) - { - nodeDataChanged = f; - } - void setTreeChangedSignal(std::function)> f) - { - treeChanged = f; - } - - std::function)> getTreeChangedSignal(){ return treeChanged; } - std::function)> getDataChangedSignal(){ return nodeDataChanged; } - -private: - void fireNodeDataChanged(); - void fireTreeChanged(); - //signal callbacks only set in the root node - std::function)> nodeDataChanged; - std::function)> treeChanged; - - std::shared_ptr nextOnSameLevel(); - std::shared_ptr parent; - std::shared_ptr data; - std::shared_ptr value; - std::list> children; -}; - -#endif // EDITORNODE_H diff --git a/src/editor/EditorTree.cpp b/src/editor/EditorTree.cpp deleted file mode 100644 index 99433cd..0000000 --- a/src/editor/EditorTree.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "EditorTree.h" -#include - -EditorTree::EditorTree(QObject *parent) : QObject(parent) -{ - root = std::make_shared(nullptr); - - root->setDataChangedSignal([this](std::shared_ptr node){ emit this->nodeDataChanged(node);}); - root->setTreeChangedSignal([this](std::shared_ptr node){ emit this->treeChanged(node);}); -} - -EditorTree::~EditorTree() -{ - -} diff --git a/src/editor/EditorTree.h b/src/editor/EditorTree.h deleted file mode 100644 index ab6b8d9..0000000 --- a/src/editor/EditorTree.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef EDITORTREE_H -#define EDITORTREE_H -#include -#include - -#include "EditorNode.h" - -class EditorTree : public QObject -{ - Q_OBJECT -public: - explicit EditorTree(QObject *parent = 0); - virtual ~EditorTree(); - - const std::shared_ptr getRoot() { return root; } - -signals: - void nodeDataChanged(std::shared_ptr node); - void treeChanged(std::shared_ptr node); -public slots: -private: - std::shared_ptr root; -}; - -#endif // EDITORTREE_H diff --git a/src/editor/guidededitorelementview.cpp b/src/editor/guidededitorelementview.cpp index 939a592..045273d 100644 --- a/src/editor/guidededitorelementview.cpp +++ b/src/editor/guidededitorelementview.cpp @@ -9,7 +9,7 @@ #include -GuidedEditorElementView::GuidedEditorElementView(const std::shared_ptr &ref, QWidget* parent) +GuidedEditorElementView::GuidedEditorElementView(const std::shared_ptr &ref, QWidget* parent) : GuidedEditorElementView(parent) { this->setReference(ref); @@ -51,7 +51,7 @@ void GuidedEditorElementView::render() subContainer = new QWidget(this); FlowLayout* flayout = new FlowLayout(subContainer); //create and render subelementviews! this is DEPTH_FIRST!!! TODO: make this breadth first! - for (std::shared_ptr node : reference->getChildren()) { + for (std::shared_ptr node : reference->getChildren()) { GuidedEditorElementView* view = new GuidedEditorElementView(subContainer); view->setReference(node); flayout->addWidget(view); @@ -104,12 +104,12 @@ void GuidedEditorElementView::nodeChanged() this->render(); } -std::shared_ptr GuidedEditorElementView::getReference() const +std::shared_ptr GuidedEditorElementView::getReference() const { return reference; } -void GuidedEditorElementView::setReference(const std::shared_ptr& value) +void GuidedEditorElementView::setReference(const std::shared_ptr& value) { reference = value; QRegExp r(reference->getData()->getRegex()); diff --git a/src/editor/guidededitorelementview.h b/src/editor/guidededitorelementview.h index 57f5ee3..ff3cd4c 100644 --- a/src/editor/guidededitorelementview.h +++ b/src/editor/guidededitorelementview.h @@ -16,12 +16,12 @@ class GuidedEditorElementView : public QWidget { Q_OBJECT public: - explicit GuidedEditorElementView(const std::shared_ptr &ref,QWidget* parent = 0); + explicit GuidedEditorElementView(const std::shared_ptr &ref,QWidget* parent = 0); explicit GuidedEditorElementView(QWidget* parent = 0); - std::shared_ptr getReference() const; - void setReference(const std::shared_ptr &value); + std::shared_ptr getReference() const; + void setReference(const std::shared_ptr &value); signals: @@ -40,7 +40,7 @@ private: QMap otherWidgets; QRegExpValidator* validator; QWidget* subContainer; - std::shared_ptr reference; + std::shared_ptr reference; }; #endif // GUIDEDEDITORELEMENTVIEW_H diff --git a/src/editor/guidededitorview.cpp b/src/editor/guidededitorview.cpp index 57ceef5..4366b31 100644 --- a/src/editor/guidededitorview.cpp +++ b/src/editor/guidededitorview.cpp @@ -47,7 +47,7 @@ void GuidedEditorView::setTree(EditorTree* tree) } -void GuidedEditorView::treeDataChangedSlot(std::shared_ptr node) +void GuidedEditorView::treeDataChangedSlot(std::shared_ptr node) { // get node view auto view = nodeToViewMap[node]; @@ -55,7 +55,7 @@ void GuidedEditorView::treeDataChangedSlot(std::shared_ptr node) view->dataChanged(); } -void GuidedEditorView::treeChangedSlot(std::shared_ptr node) +void GuidedEditorView::treeChangedSlot(std::shared_ptr node) { // get node view auto view = nodeToViewMap[node]; @@ -67,7 +67,7 @@ void GuidedEditorView::render() { if(tree != nullptr) { // root node is invisible! - for(std::shared_ptr node : tree->getRoot()->getChildren()){ + for(std::shared_ptr node : tree->getRoot()->getChildren()){ auto view = new GuidedEditorElementView(node, this); this->editorLayout->addWidget(view); this->nodeToViewMap.insert(node, view); diff --git a/src/editor/guidededitorview.h b/src/editor/guidededitorview.h index 46f04d7..d4fb912 100644 --- a/src/editor/guidededitorview.h +++ b/src/editor/guidededitorview.h @@ -20,15 +20,15 @@ public slots: void addElement(EditorElementData* element); void setTree(EditorTree* tree); - void treeDataChangedSlot(std::shared_ptr node); - void treeChangedSlot(std::shared_ptr node); + void treeDataChangedSlot(std::shared_ptr node); + void treeChangedSlot(std::shared_ptr node); void render(); private: FlowLayout* editorLayout; EditorTree* tree; - QMap, GuidedEditorElementView*> nodeToViewMap; + QMap, GuidedEditorElementView*> nodeToViewMap; }; diff --git a/src/model/CMakeLists.txt b/src/model/CMakeLists.txt index b98c3d2..c77df50 100644 --- a/src/model/CMakeLists.txt +++ b/src/model/CMakeLists.txt @@ -1,10 +1,12 @@ -set(HEADERS packetmodel.h - packetelement.h +set(HEADERS Protocol.h + Field.h + Tree.h + TreeNode.h ) -set(SOURCES packetmodel.cpp - packetelement.cpp +set(SOURCES Protocol.cpp + Field.cpp ) add_library(model ${HEADERS} ${SOURCES}) diff --git a/src/model/packetelement.cpp b/src/model/Field.cpp similarity index 62% rename from src/model/packetelement.cpp rename to src/model/Field.cpp index e9578a9..2197e72 100644 --- a/src/model/packetelement.cpp +++ b/src/model/Field.cpp @@ -1,17 +1,17 @@ -#include "packetelement.h" +#include "field.h" #include -PacketElement::PacketElement(std::string name, uint32_t sizeInBit, uint16_t layer): name(name), sizeInBit(sizeInBit), layer(layer) +Field::Field(std::string name, uint32_t sizeInBit, uint16_t layer): name(name), sizeInBit(sizeInBit), layer(layer) { } -void PacketElement::setValue(std::string &value, ValueType type) +void Field::setValue(std::string &value, ValueType type) { this->value = std::string(value); this->valueType = type; } -std::list PacketElement::getBytes() +std::list Field::getBytes() { std::list result; switch(this->valueType) { diff --git a/src/model/Field.h b/src/model/Field.h new file mode 100644 index 0000000..ab663d8 --- /dev/null +++ b/src/model/Field.h @@ -0,0 +1,121 @@ +#ifndef PACKETELEMENT_H +#define PACKETELEMENT_H + +#include +#include +#include +#include + + +class Field; + +typedef + std::list> + FieldList_t; + + /** + @brief The ValueType enum + */ +enum class ValueType { hexBinary, integer, text }; + +class FieldSyntax +{ +public: + std::string triggerRegex; + std::string completeRegex; + std::string example; +}; + +class FieldProperties +{ +/* +length: + type: integer + reflength: + type: string + data: + type: boolean + field: == name + type: string + desc: + type: string + bitfield: + type: boolean + optional: + type: boolean + repeatable: + type: boolean + nextlayer: + type: boolean + reference: + type: string + subfields: + type: array +*/ +public: + std::string protocol; + std::string name; + std::string description; + std::string sizeReferenceField; + std::string protocolReference; + bool data, optional, repeatable, nextLayer; + uint32_t size; + std::list> syntaxes; +}; + +class FieldData +{ +public: + std::string data; + ValueType type; +}; + +/** + @brief The Field class + */ + +class Field +{ +public: + Field(std::string name, uint32_t sizeInBit, uint16_t layer); + void setValue(std::string& value) {this->value = value; this->valueType = ValueType::text; } + void setValue(std::string& value, ValueType type); + + const std::string getValue() { return value; } + uint32_t getSizeInBit() { return sizeInBit; } + uint16_t getLayer() { return layer; } + const std::string getName() { return name; } + const std::string getDescription() { return description; } + + + const std::shared_ptr getNextLayer() { return nextLayer; } + bool hasNextLayer() { return nextLayer != nullptr && sizeInBit == 0; } + void setNextLayer(std::shared_ptr& layerElements) { nextLayer = layerElements; } + + void addSyntax(std::string minimalRegex, std::string completeRegex, std::string example) + { + std::shared_ptr syntax = std::make_shared(); + syntax->triggerRegex = minimalRegex; + syntax->completeRegex = completeRegex; + syntax->example = example; + syntaxes.push_back(syntax); + } + + std::list getBytes(); + +private: + std::string name; + uint32_t sizeInBit; + uint16_t layer; + std::string value; + ValueType valueType; + + std::shared_ptr nextLayer; + + //additional data + std::string description; + std::list> syntaxes; + +}; + +#endif // PACKETELEMENT_H diff --git a/src/model/Protocol.cpp b/src/model/Protocol.cpp new file mode 100644 index 0000000..f77fde0 --- /dev/null +++ b/src/model/Protocol.cpp @@ -0,0 +1,13 @@ +#include "Protocol.h" + +#include "Field.h" + +Protocol::Protocol() +{ + this->elementList = std::make_shared(); +} + +const std::shared_ptr Protocol::getList() +{ + return this->elementList; +} diff --git a/src/model/packetmodel.h b/src/model/Protocol.h similarity index 50% rename from src/model/packetmodel.h rename to src/model/Protocol.h index ca26067..f31f505 100644 --- a/src/model/packetmodel.h +++ b/src/model/Protocol.h @@ -5,18 +5,18 @@ #include #include -#include "packetelement.h" +#include "Field.h" -class PacketModel +class Protocol { public: - PacketModel(); - const std::shared_ptr getList(); + Protocol(); + const std::shared_ptr getList(); bool validate(); private: - std::shared_ptr elementList; + std::shared_ptr elementList; }; #endif // PACKETMODEL_H diff --git a/src/model/Tree.h b/src/model/Tree.h new file mode 100644 index 0000000..be58e65 --- /dev/null +++ b/src/model/Tree.h @@ -0,0 +1,40 @@ +#ifndef EDITORTREE_H +#define EDITORTREE_H +#include + +#include "TreeNode.h" + +template +class Tree +{ +public: + explicit Tree(); + virtual ~Tree(); + + const std::shared_ptr> getRoot() { return root; } + + void nodeDataChanged(std::shared_ptr> node); + void treeChanged(std::shared_ptr> node); + +private: + std::shared_ptr> root; +}; + + +template +Tree::Tree() +{ + root = std::make_shared>(nullptr); + + root->setDataChangedSignal([this](std::shared_ptr> node){ this->nodeDataChanged(node);}); + root->setTreeChangedSignal([this](std::shared_ptr> node){ this->treeChanged(node);}); +} + +template +Tree::~Tree() +{ + +} + + +#endif // EDITORTREE_H diff --git a/src/editor/EditorNode.cpp b/src/model/TreeNode.h similarity index 53% rename from src/editor/EditorNode.cpp rename to src/model/TreeNode.h index 94848e5..6b892a4 100644 --- a/src/editor/EditorNode.cpp +++ b/src/model/TreeNode.h @@ -1,27 +1,97 @@ -#include "EditorNode.h" +#ifndef EDITORNODE_H +#define EDITORNODE_H -#include +#include +#include +#include +#include -EditorNode::EditorNode() +template +class TreeNode; + +enum class TreeWalkStrategy { + depthFirst, + breadthFirst, + mixture +}; +template +class TreeNode +{ +public: + explicit TreeNode(); + explicit TreeNode(std::shared_ptr data); + virtual ~TreeNode(); + + const std::shared_ptr> nextSibling(); + + const std::shared_ptr> next(TreeWalkStrategy walkStrategy = TreeWalkStrategy::depthFirst); + const std::shared_ptr> getRoot(); + void move(std::shared_ptr> to); //as child + void moveChildren(std::shared_ptr> to); //all + + void addChild(std::shared_ptr> child); + bool removeChild(std::shared_ptr> child); + bool remove(); + + uint getDistanceFromRoot(); + + std::shared_ptr> getParent() const; + void setParent(const std::shared_ptr> &value); + + std::shared_ptr getData() const; + void setData(const std::shared_ptr &value); + + std::list> > getChildren() const; + + void setDataChangedSignal(std::function>)> f) + { + nodeDataChanged = f; + } + void setTreeChangedSignal(std::function>)> f) + { + treeChanged = f; + } + + std::function>)> getTreeChangedSignal(){ return treeChanged; } + std::function>)> getDataChangedSignal(){ return nodeDataChanged; } + +private: + void fireNodeDataChanged(); + void fireTreeChanged(); + //signal callbacks only set in the root node + std::function>)> nodeDataChanged; + std::function>)> treeChanged; + + std::shared_ptr> nextOnSameLevel(); + std::shared_ptr> parent; + std::shared_ptr data; + std::list>> children; +}; + +template +TreeNode::TreeNode() { } -EditorNode::EditorNode(std::shared_ptr data) +template +TreeNode::TreeNode(std::shared_ptr data) { this->data = data; } -EditorNode::~EditorNode() +template +TreeNode::~TreeNode() { } -const std::shared_ptr EditorNode::nextSibling() +template +const std::shared_ptr> TreeNode::nextSibling() { if (parent != nullptr) { auto l = parent->getChildren(); - auto it = std::find(l.begin(), l.end(), std::shared_ptr(this)); + auto it = std::find(l.begin(), l.end(), std::shared_ptr>(this)); if (it != l.end() && ++it != l.end()) return *(++it); //next sibling... else @@ -31,7 +101,8 @@ const std::shared_ptr EditorNode::nextSibling() } -const std::shared_ptr EditorNode::next(TreeWalkStrategy walkStrategy) +template +const std::shared_ptr> TreeNode::next(TreeWalkStrategy walkStrategy) { if (walkStrategy == TreeWalkStrategy::mixture) // choose node, work through all siblings, choose next node, but don't change branches more than one parent away, except branch is at an end. @@ -69,7 +140,7 @@ const std::shared_ptr EditorNode::next(TreeWalkStrategy walkStrategy return getChildren().front(); //return getChildren().first(); else { - auto node = std::shared_ptr(this); + auto node = std::shared_ptr>(this); while (node->nextSibling() == nullptr && node->getParent() != nullptr) node = node->getParent(); return node->nextSibling(); @@ -88,39 +159,44 @@ const std::shared_ptr EditorNode::next(TreeWalkStrategy walkStrategy return nullptr; } -const std::shared_ptr EditorNode::getRoot() +template +const std::shared_ptr> TreeNode::getRoot() { - auto node = std::shared_ptr(this); + auto node = std::shared_ptr>(this); while (node->getParent() != nullptr) node = node->getParent(); return node; } -void EditorNode::move(std::shared_ptr to) +template +void TreeNode::move(std::shared_ptr> to) { - this->getParent()->getChildren().remove(std::shared_ptr(this)); + this->getParent()->getChildren().remove(std::shared_ptr>(this)); //this->getParent()->getChildren().removeOne(std::shared_ptr(this)); - to->getChildren().push_back(std::shared_ptr(this)); + to->getChildren().push_back(std::shared_ptr>(this)); //to->getChildren().append(std::shared_ptr(this)); fireTreeChanged(); } -void EditorNode::moveChildren(std::shared_ptr to) +template +void TreeNode::moveChildren(std::shared_ptr> to) { for (auto child : getChildren()) child->move(to); fireTreeChanged(); } -void EditorNode::addChild(std::shared_ptr child) +template +void TreeNode::addChild(std::shared_ptr> child) { this->getChildren().push_back(child); //this->getChildren().append(child); - child->setParent(std::shared_ptr(this)); + child->setParent(std::shared_ptr>(this)); fireTreeChanged(); } -bool EditorNode::removeChild(std::shared_ptr child) +template +bool TreeNode::removeChild(std::shared_ptr> child) { this->getChildren().remove(child); bool ret = true; //this->getChildren().removeOne(child); @@ -128,7 +204,8 @@ bool EditorNode::removeChild(std::shared_ptr child) return ret; } -bool EditorNode::remove() +template +bool TreeNode::remove() { bool worked = true; if (children.size() > 0) { @@ -137,69 +214,66 @@ bool EditorNode::remove() } } if (worked && parent != nullptr) { - parent->getChildren().remove(std::shared_ptr(this)); + parent->getChildren().remove(std::shared_ptr>(this)); //worked &= parent->getChildren().removeOne(std::shared_ptr(this)); } if (worked) fireTreeChanged(); return worked; } -std::shared_ptr EditorNode::getParent() const +template +std::shared_ptr> TreeNode::getParent() const { return parent; } -void EditorNode::setParent(const std::shared_ptr &value) +template +void TreeNode::setParent(const std::shared_ptr> &value) { parent = value; } -std::shared_ptr EditorNode::getData() const +template +std::shared_ptr TreeNode::getData() const { return data; } -void EditorNode::setData(const std::shared_ptr &value) +template +void TreeNode::setData(const std::shared_ptr &value) { fireNodeDataChanged(); data = value; } -std::shared_ptr EditorNode::getValue() const -{ - return value; -} - -void EditorNode::setValue(const std::shared_ptr &value) -{ - fireNodeDataChanged(); - this->value = value; -} - -std::list > EditorNode::getChildren() const +template +std::list>> TreeNode::getChildren() const { return children; } -void EditorNode::fireNodeDataChanged() +template +void TreeNode::fireNodeDataChanged() { if(this->getRoot()->getDataChangedSignal() != nullptr) - this->getRoot()->getDataChangedSignal()(std::shared_ptr(this)); + this->getRoot()->getDataChangedSignal()(std::shared_ptr>(this)); } -void EditorNode::fireTreeChanged() +template +void TreeNode::fireTreeChanged() { if(this->getRoot()->getTreeChangedSignal() != nullptr) - this->getRoot()->getTreeChangedSignal()(std::shared_ptr(this)); + this->getRoot()->getTreeChangedSignal()(std::shared_ptr>(this)); } -std::shared_ptr EditorNode::nextOnSameLevel() +template +std::shared_ptr> TreeNode::nextOnSameLevel() { if (nextSibling() != nullptr) return nextSibling(); uint lvl = 1; auto node = this->getParent(); - auto pnode = std::shared_ptr(this); + auto pnode = std::shared_ptr>(this); while (lvl > 0 && node != nullptr) { if (node != pnode->getParent() && node->getChildren().size() > 0) { node = node->getChildren().front(); @@ -219,3 +293,19 @@ std::shared_ptr EditorNode::nextOnSameLevel() } return node; } + +template +uint TreeNode::getDistanceFromRoot() +{ + std::shared_ptr> node = std::make_shared>(this); + uint lvl = 0; + while(node->getParent() != nullptr) + { + ++lvl; + node = node->getParent(); + } + return lvl; +} + + +#endif // EDITORNODE_H diff --git a/src/model/packetelement.h b/src/model/packetelement.h deleted file mode 100644 index 4d97328..0000000 --- a/src/model/packetelement.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef PACKETELEMENT_H -#define PACKETELEMENT_H - -#include -#include -#include -#include - - -class PacketElement; - -typedef - std::list> - PacketElementList_t; - - /** - @brief The ValueType enum - */ -enum class ValueType { hexBinary, integer, text }; - -class ElementSyntax -{ -public: - std::string triggerRegex; - std::string completeRegex; - std::string example; -}; - - -/** - @brief The PacketElement class - */ - -class PacketElement -{ -public: - /** - @brief PacketElement - @param name - @param sizeInBit - @param layer - */ - PacketElement(std::string name, uint32_t sizeInBit, uint16_t layer); - /** - @brief setValue - @param value - */ - void setValue(std::string& value) {this->value = value; this->valueType = ValueType::text; } - /** - @brief setValue - @param value - @param type - */ - void setValue(std::string& value, ValueType type); - - const std::string getValue() { return value; } - uint32_t getSizeInBit() { return sizeInBit; } - uint16_t getLayer() { return layer; } - const std::string getName() { return name; } - const std::string getDescription() { return description; } - - - const std::shared_ptr getNextLayer() { return nextLayer; } - /** - @brief hasNextLayer - @return - */ - bool hasNextLayer() { return nextLayer != nullptr && sizeInBit == 0; } - /** - @brief setNextLayer - @param layerElements - */ - void setNextLayer(std::shared_ptr& layerElements) { nextLayer = layerElements; } - - void addSyntax(std::string minimalRegex, std::string completeRegex, std::string example) - { - std::shared_ptr syntax = std::make_shared(); - syntax->triggerRegex = minimalRegex; - syntax->completeRegex = completeRegex; - syntax->example = example; - syntaxes.push_back(syntax); - } - - std::list getBytes(); - -private: - std::string name; - uint32_t sizeInBit; - uint16_t layer; - std::string value; - ValueType valueType; - - std::shared_ptr nextLayer; - - //additional data - std::string description; - std::list> syntaxes; - -}; - -#endif // PACKETELEMENT_H diff --git a/src/model/packetmodel.cpp b/src/model/packetmodel.cpp deleted file mode 100644 index 7386dad..0000000 --- a/src/model/packetmodel.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "packetmodel.h" - -#include "packetelement.h" - -PacketModel::PacketModel() -{ - this->elementList = std::make_shared(); -} - -const std::shared_ptr PacketModel::getList() -{ - return this->elementList; -} diff --git a/src/protocol/CMakeLists.txt b/src/parser/CMakeLists.txt similarity index 100% rename from src/protocol/CMakeLists.txt rename to src/parser/CMakeLists.txt diff --git a/src/protocol/DataLoader.cpp b/src/parser/DataLoader.cpp similarity index 100% rename from src/protocol/DataLoader.cpp rename to src/parser/DataLoader.cpp diff --git a/src/protocol/DataLoader.h b/src/parser/DataLoader.h similarity index 72% rename from src/protocol/DataLoader.h rename to src/parser/DataLoader.h index cd1029c..a4b7fe7 100644 --- a/src/protocol/DataLoader.h +++ b/src/parser/DataLoader.h @@ -6,7 +6,7 @@ #include #include -#include "../editor/EditorNode.h" +#include "../model/TreeNode.h" class DataLoader { @@ -18,13 +18,13 @@ public: void loadSingleProtocol(std::string filename); - std::shared_ptr generateTree(YAML::Node &node); + std::shared_ptr> generateTree(YAML::Node &node); bool getProtocolByName(std::string name, YAML::Node &node); std::list getProtocolNames(); private: - std::shared_ptr genNode(YAML::Node& n, std::shared_ptr parent = nullptr); + std::shared_ptr> genNode(YAML::Node& n, std::shared_ptr> parent = nullptr); std::string directory; std::list protocolList; };