[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.
This commit is contained in:
parent
160501b7ca
commit
b33c0504f6
|
@ -2,3 +2,4 @@
|
||||||
*.pro.user
|
*.pro.user
|
||||||
build
|
build
|
||||||
*.user*
|
*.user*
|
||||||
|
doc
|
||||||
|
|
|
@ -6,7 +6,7 @@ set(SOURCES mainwindow.cpp
|
||||||
|
|
||||||
add_subdirectory(model)
|
add_subdirectory(model)
|
||||||
add_subdirectory(editor)
|
add_subdirectory(editor)
|
||||||
add_subdirectory(protocol)
|
add_subdirectory(parser)
|
||||||
|
|
||||||
add_library(src ${HEADERS} ${SOURCES})
|
add_library(src ${HEADERS} ${SOURCES})
|
||||||
target_link_libraries(src model editor protocol)
|
target_link_libraries(src model editor protocol)
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
set(HEADERS editorelementdata.h
|
set(HEADERS editorelementdata.h
|
||||||
guidededitorelementview.h
|
guidededitorelementview.h
|
||||||
flowlayout.h
|
flowlayout.h
|
||||||
EditorNode.h
|
|
||||||
EditorTree.h
|
|
||||||
EditorElementValue.h
|
EditorElementValue.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,8 +9,6 @@ set(SOURCES guidededitorelementview.cpp
|
||||||
editorelementdata.cpp
|
editorelementdata.cpp
|
||||||
guidededitorview.cpp
|
guidededitorview.cpp
|
||||||
flowlayout.cpp
|
flowlayout.cpp
|
||||||
EditorNode.cpp
|
|
||||||
EditorTree.cpp
|
|
||||||
EditorElementValue.cpp
|
EditorElementValue.cpp
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
#ifndef EDITORNODE_H
|
|
||||||
#define EDITORNODE_H
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <functional>
|
|
||||||
#include <list>
|
|
||||||
|
|
||||||
#include "editorelementdata.h"
|
|
||||||
#include "EditorElementValue.h"
|
|
||||||
|
|
||||||
class EditorNode;
|
|
||||||
|
|
||||||
enum class TreeWalkStrategy {
|
|
||||||
depthFirst,
|
|
||||||
breadthFirst,
|
|
||||||
mixture
|
|
||||||
};
|
|
||||||
|
|
||||||
class EditorNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit EditorNode();
|
|
||||||
explicit EditorNode(std::shared_ptr<EditorElementData> data);
|
|
||||||
virtual ~EditorNode();
|
|
||||||
|
|
||||||
const std::shared_ptr<EditorNode> nextSibling();
|
|
||||||
|
|
||||||
const std::shared_ptr<EditorNode> next(TreeWalkStrategy walkStrategy = TreeWalkStrategy::depthFirst);
|
|
||||||
const std::shared_ptr<EditorNode> getRoot();
|
|
||||||
void move(std::shared_ptr<EditorNode> to); //as child
|
|
||||||
void moveChildren(std::shared_ptr<EditorNode> to); //all
|
|
||||||
|
|
||||||
void addChild(std::shared_ptr<EditorNode> child);
|
|
||||||
bool removeChild(std::shared_ptr<EditorNode> child);
|
|
||||||
bool remove();
|
|
||||||
|
|
||||||
std::shared_ptr<EditorNode> getParent() const;
|
|
||||||
void setParent(const std::shared_ptr<EditorNode> &value);
|
|
||||||
|
|
||||||
std::shared_ptr<EditorElementData> getData() const;
|
|
||||||
void setData(const std::shared_ptr<EditorElementData> &value);
|
|
||||||
|
|
||||||
std::shared_ptr<EditorElementValue> getValue() const;
|
|
||||||
void setValue(const std::shared_ptr<EditorElementValue> &value);
|
|
||||||
|
|
||||||
std::list<std::shared_ptr<EditorNode> > getChildren() const;
|
|
||||||
|
|
||||||
void setDataChangedSignal(std::function<void(std::shared_ptr<EditorNode>)> f)
|
|
||||||
{
|
|
||||||
nodeDataChanged = f;
|
|
||||||
}
|
|
||||||
void setTreeChangedSignal(std::function<void(std::shared_ptr<EditorNode>)> f)
|
|
||||||
{
|
|
||||||
treeChanged = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::function<void(std::shared_ptr<EditorNode>)> getTreeChangedSignal(){ return treeChanged; }
|
|
||||||
std::function<void(std::shared_ptr<EditorNode>)> getDataChangedSignal(){ return nodeDataChanged; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void fireNodeDataChanged();
|
|
||||||
void fireTreeChanged();
|
|
||||||
//signal callbacks only set in the root node
|
|
||||||
std::function<void(std::shared_ptr<EditorNode>)> nodeDataChanged;
|
|
||||||
std::function<void(std::shared_ptr<EditorNode>)> treeChanged;
|
|
||||||
|
|
||||||
std::shared_ptr<EditorNode> nextOnSameLevel();
|
|
||||||
std::shared_ptr<EditorNode> parent;
|
|
||||||
std::shared_ptr<EditorElementData> data;
|
|
||||||
std::shared_ptr<EditorElementValue> value;
|
|
||||||
std::list<std::shared_ptr<EditorNode>> children;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // EDITORNODE_H
|
|
|
@ -1,15 +0,0 @@
|
||||||
#include "EditorTree.h"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
EditorTree::EditorTree(QObject *parent) : QObject(parent)
|
|
||||||
{
|
|
||||||
root = std::make_shared<EditorNode>(nullptr);
|
|
||||||
|
|
||||||
root->setDataChangedSignal([this](std::shared_ptr<EditorNode> node){ emit this->nodeDataChanged(node);});
|
|
||||||
root->setTreeChangedSignal([this](std::shared_ptr<EditorNode> node){ emit this->treeChanged(node);});
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorTree::~EditorTree()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
#ifndef EDITORTREE_H
|
|
||||||
#define EDITORTREE_H
|
|
||||||
#include <memory>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "EditorNode.h"
|
|
||||||
|
|
||||||
class EditorTree : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit EditorTree(QObject *parent = 0);
|
|
||||||
virtual ~EditorTree();
|
|
||||||
|
|
||||||
const std::shared_ptr<EditorNode> getRoot() { return root; }
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void nodeDataChanged(std::shared_ptr<EditorNode> node);
|
|
||||||
void treeChanged(std::shared_ptr<EditorNode> node);
|
|
||||||
public slots:
|
|
||||||
private:
|
|
||||||
std::shared_ptr<EditorNode> root;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // EDITORTREE_H
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
GuidedEditorElementView::GuidedEditorElementView(const std::shared_ptr<EditorNode> &ref, QWidget* parent)
|
GuidedEditorElementView::GuidedEditorElementView(const std::shared_ptr<TreeNode> &ref, QWidget* parent)
|
||||||
: GuidedEditorElementView(parent)
|
: GuidedEditorElementView(parent)
|
||||||
{
|
{
|
||||||
this->setReference(ref);
|
this->setReference(ref);
|
||||||
|
@ -51,7 +51,7 @@ void GuidedEditorElementView::render()
|
||||||
subContainer = new QWidget(this);
|
subContainer = new QWidget(this);
|
||||||
FlowLayout* flayout = new FlowLayout(subContainer);
|
FlowLayout* flayout = new FlowLayout(subContainer);
|
||||||
//create and render subelementviews! this is DEPTH_FIRST!!! TODO: make this breadth first!
|
//create and render subelementviews! this is DEPTH_FIRST!!! TODO: make this breadth first!
|
||||||
for (std::shared_ptr<EditorNode> node : reference->getChildren()) {
|
for (std::shared_ptr<TreeNode> node : reference->getChildren()) {
|
||||||
GuidedEditorElementView* view = new GuidedEditorElementView(subContainer);
|
GuidedEditorElementView* view = new GuidedEditorElementView(subContainer);
|
||||||
view->setReference(node);
|
view->setReference(node);
|
||||||
flayout->addWidget(view);
|
flayout->addWidget(view);
|
||||||
|
@ -104,12 +104,12 @@ void GuidedEditorElementView::nodeChanged()
|
||||||
this->render();
|
this->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<EditorNode> GuidedEditorElementView::getReference() const
|
std::shared_ptr<TreeNode> GuidedEditorElementView::getReference() const
|
||||||
{
|
{
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuidedEditorElementView::setReference(const std::shared_ptr<EditorNode>& value)
|
void GuidedEditorElementView::setReference(const std::shared_ptr<TreeNode>& value)
|
||||||
{
|
{
|
||||||
reference = value;
|
reference = value;
|
||||||
QRegExp r(reference->getData()->getRegex());
|
QRegExp r(reference->getData()->getRegex());
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
class GuidedEditorElementView : public QWidget {
|
class GuidedEditorElementView : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GuidedEditorElementView(const std::shared_ptr<EditorNode> &ref,QWidget* parent = 0);
|
explicit GuidedEditorElementView(const std::shared_ptr<TreeNode> &ref,QWidget* parent = 0);
|
||||||
explicit GuidedEditorElementView(QWidget* parent = 0);
|
explicit GuidedEditorElementView(QWidget* parent = 0);
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<EditorNode> getReference() const;
|
std::shared_ptr<TreeNode> getReference() const;
|
||||||
void setReference(const std::shared_ptr<EditorNode> &value);
|
void setReference(const std::shared_ptr<TreeNode> &value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ private:
|
||||||
QMap<QString, QWidget*> otherWidgets;
|
QMap<QString, QWidget*> otherWidgets;
|
||||||
QRegExpValidator* validator;
|
QRegExpValidator* validator;
|
||||||
QWidget* subContainer;
|
QWidget* subContainer;
|
||||||
std::shared_ptr<EditorNode> reference;
|
std::shared_ptr<TreeNode> reference;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GUIDEDEDITORELEMENTVIEW_H
|
#endif // GUIDEDEDITORELEMENTVIEW_H
|
||||||
|
|
|
@ -47,7 +47,7 @@ void GuidedEditorView::setTree(EditorTree* tree)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuidedEditorView::treeDataChangedSlot(std::shared_ptr<EditorNode> node)
|
void GuidedEditorView::treeDataChangedSlot(std::shared_ptr<TreeNode> node)
|
||||||
{
|
{
|
||||||
// get node view
|
// get node view
|
||||||
auto view = nodeToViewMap[node];
|
auto view = nodeToViewMap[node];
|
||||||
|
@ -55,7 +55,7 @@ void GuidedEditorView::treeDataChangedSlot(std::shared_ptr<EditorNode> node)
|
||||||
view->dataChanged();
|
view->dataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuidedEditorView::treeChangedSlot(std::shared_ptr<EditorNode> node)
|
void GuidedEditorView::treeChangedSlot(std::shared_ptr<TreeNode> node)
|
||||||
{
|
{
|
||||||
// get node view
|
// get node view
|
||||||
auto view = nodeToViewMap[node];
|
auto view = nodeToViewMap[node];
|
||||||
|
@ -67,7 +67,7 @@ void GuidedEditorView::render()
|
||||||
{
|
{
|
||||||
if(tree != nullptr) {
|
if(tree != nullptr) {
|
||||||
// root node is invisible!
|
// root node is invisible!
|
||||||
for(std::shared_ptr<EditorNode> node : tree->getRoot()->getChildren()){
|
for(std::shared_ptr<TreeNode> node : tree->getRoot()->getChildren()){
|
||||||
auto view = new GuidedEditorElementView(node, this);
|
auto view = new GuidedEditorElementView(node, this);
|
||||||
this->editorLayout->addWidget(view);
|
this->editorLayout->addWidget(view);
|
||||||
this->nodeToViewMap.insert(node, view);
|
this->nodeToViewMap.insert(node, view);
|
||||||
|
|
|
@ -20,15 +20,15 @@ public slots:
|
||||||
void addElement(EditorElementData* element);
|
void addElement(EditorElementData* element);
|
||||||
void setTree(EditorTree* tree);
|
void setTree(EditorTree* tree);
|
||||||
|
|
||||||
void treeDataChangedSlot(std::shared_ptr<EditorNode> node);
|
void treeDataChangedSlot(std::shared_ptr<TreeNode> node);
|
||||||
void treeChangedSlot(std::shared_ptr<EditorNode> node);
|
void treeChangedSlot(std::shared_ptr<TreeNode> node);
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FlowLayout* editorLayout;
|
FlowLayout* editorLayout;
|
||||||
EditorTree* tree;
|
EditorTree* tree;
|
||||||
QMap<std::shared_ptr<EditorNode>, GuidedEditorElementView*> nodeToViewMap;
|
QMap<std::shared_ptr<TreeNode>, GuidedEditorElementView*> nodeToViewMap;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
|
||||||
set(HEADERS packetmodel.h
|
set(HEADERS Protocol.h
|
||||||
packetelement.h
|
Field.h
|
||||||
|
Tree.h
|
||||||
|
TreeNode.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES packetmodel.cpp
|
set(SOURCES Protocol.cpp
|
||||||
packetelement.cpp
|
Field.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(model ${HEADERS} ${SOURCES})
|
add_library(model ${HEADERS} ${SOURCES})
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
#include "packetelement.h"
|
#include "field.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
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->value = std::string(value);
|
||||||
this->valueType = type;
|
this->valueType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<uint8_t> PacketElement::getBytes()
|
std::list<uint8_t> Field::getBytes()
|
||||||
{
|
{
|
||||||
std::list<uint8_t> result;
|
std::list<uint8_t> result;
|
||||||
switch(this->valueType) {
|
switch(this->valueType) {
|
|
@ -0,0 +1,121 @@
|
||||||
|
#ifndef PACKETELEMENT_H
|
||||||
|
#define PACKETELEMENT_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
|
class Field;
|
||||||
|
|
||||||
|
typedef
|
||||||
|
std::list<std::shared_ptr<Field>>
|
||||||
|
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<std::shared_ptr<FieldSyntax>> 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<FieldList_t> getNextLayer() { return nextLayer; }
|
||||||
|
bool hasNextLayer() { return nextLayer != nullptr && sizeInBit == 0; }
|
||||||
|
void setNextLayer(std::shared_ptr<FieldList_t>& layerElements) { nextLayer = layerElements; }
|
||||||
|
|
||||||
|
void addSyntax(std::string minimalRegex, std::string completeRegex, std::string example)
|
||||||
|
{
|
||||||
|
std::shared_ptr<FieldSyntax> syntax = std::make_shared<FieldSyntax>();
|
||||||
|
syntax->triggerRegex = minimalRegex;
|
||||||
|
syntax->completeRegex = completeRegex;
|
||||||
|
syntax->example = example;
|
||||||
|
syntaxes.push_back(syntax);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<uint8_t> getBytes();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name;
|
||||||
|
uint32_t sizeInBit;
|
||||||
|
uint16_t layer;
|
||||||
|
std::string value;
|
||||||
|
ValueType valueType;
|
||||||
|
|
||||||
|
std::shared_ptr<FieldList_t> nextLayer;
|
||||||
|
|
||||||
|
//additional data
|
||||||
|
std::string description;
|
||||||
|
std::list<std::shared_ptr<FieldSyntax>> syntaxes;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PACKETELEMENT_H
|
|
@ -0,0 +1,13 @@
|
||||||
|
#include "Protocol.h"
|
||||||
|
|
||||||
|
#include "Field.h"
|
||||||
|
|
||||||
|
Protocol::Protocol()
|
||||||
|
{
|
||||||
|
this->elementList = std::make_shared<FieldList_t>();
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::shared_ptr<FieldList_t> Protocol::getList()
|
||||||
|
{
|
||||||
|
return this->elementList;
|
||||||
|
}
|
|
@ -5,18 +5,18 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "packetelement.h"
|
#include "Field.h"
|
||||||
|
|
||||||
class PacketModel
|
class Protocol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PacketModel();
|
Protocol();
|
||||||
const std::shared_ptr<PacketElementList_t> getList();
|
const std::shared_ptr<FieldList_t> getList();
|
||||||
|
|
||||||
bool validate();
|
bool validate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<PacketElementList_t> elementList;
|
std::shared_ptr<FieldList_t> elementList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PACKETMODEL_H
|
#endif // PACKETMODEL_H
|
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef EDITORTREE_H
|
||||||
|
#define EDITORTREE_H
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "TreeNode.h"
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class Tree
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Tree();
|
||||||
|
virtual ~Tree();
|
||||||
|
|
||||||
|
const std::shared_ptr<TreeNode<T>> getRoot() { return root; }
|
||||||
|
|
||||||
|
void nodeDataChanged(std::shared_ptr<TreeNode<T>> node);
|
||||||
|
void treeChanged(std::shared_ptr<TreeNode<T>> node);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<TreeNode<T>> root;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Tree<T>::Tree()
|
||||||
|
{
|
||||||
|
root = std::make_shared<TreeNode<T>>(nullptr);
|
||||||
|
|
||||||
|
root->setDataChangedSignal([this](std::shared_ptr<TreeNode<T>> node){ this->nodeDataChanged(node);});
|
||||||
|
root->setTreeChangedSignal([this](std::shared_ptr<TreeNode<T>> node){ this->treeChanged(node);});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Tree<T>::~Tree()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // EDITORTREE_H
|
|
@ -1,27 +1,97 @@
|
||||||
#include "EditorNode.h"
|
#ifndef EDITORNODE_H
|
||||||
|
#define EDITORNODE_H
|
||||||
|
|
||||||
#include <QList>
|
#include <memory>
|
||||||
|
#include <functional>
|
||||||
|
#include <list>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
EditorNode::EditorNode()
|
template <class T>
|
||||||
|
class TreeNode;
|
||||||
|
|
||||||
|
enum class TreeWalkStrategy {
|
||||||
|
depthFirst,
|
||||||
|
breadthFirst,
|
||||||
|
mixture
|
||||||
|
};
|
||||||
|
template <class T>
|
||||||
|
class TreeNode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit TreeNode();
|
||||||
|
explicit TreeNode(std::shared_ptr<T> data);
|
||||||
|
virtual ~TreeNode();
|
||||||
|
|
||||||
|
const std::shared_ptr<TreeNode<T>> nextSibling();
|
||||||
|
|
||||||
|
const std::shared_ptr<TreeNode<T>> next(TreeWalkStrategy walkStrategy = TreeWalkStrategy::depthFirst);
|
||||||
|
const std::shared_ptr<TreeNode<T>> getRoot();
|
||||||
|
void move(std::shared_ptr<TreeNode<T>> to); //as child
|
||||||
|
void moveChildren(std::shared_ptr<TreeNode<T>> to); //all
|
||||||
|
|
||||||
|
void addChild(std::shared_ptr<TreeNode<T>> child);
|
||||||
|
bool removeChild(std::shared_ptr<TreeNode<T>> child);
|
||||||
|
bool remove();
|
||||||
|
|
||||||
|
uint getDistanceFromRoot();
|
||||||
|
|
||||||
|
std::shared_ptr<TreeNode<T>> getParent() const;
|
||||||
|
void setParent(const std::shared_ptr<TreeNode<T>> &value);
|
||||||
|
|
||||||
|
std::shared_ptr<T> getData() const;
|
||||||
|
void setData(const std::shared_ptr<T> &value);
|
||||||
|
|
||||||
|
std::list<std::shared_ptr<TreeNode<T>> > getChildren() const;
|
||||||
|
|
||||||
|
void setDataChangedSignal(std::function<void(std::shared_ptr<TreeNode<T>>)> f)
|
||||||
|
{
|
||||||
|
nodeDataChanged = f;
|
||||||
|
}
|
||||||
|
void setTreeChangedSignal(std::function<void(std::shared_ptr<TreeNode<T>>)> f)
|
||||||
|
{
|
||||||
|
treeChanged = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::function<void(std::shared_ptr<TreeNode<T>>)> getTreeChangedSignal(){ return treeChanged; }
|
||||||
|
std::function<void(std::shared_ptr<TreeNode<T>>)> getDataChangedSignal(){ return nodeDataChanged; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void fireNodeDataChanged();
|
||||||
|
void fireTreeChanged();
|
||||||
|
//signal callbacks only set in the root node
|
||||||
|
std::function<void(std::shared_ptr<TreeNode<T>>)> nodeDataChanged;
|
||||||
|
std::function<void(std::shared_ptr<TreeNode<T>>)> treeChanged;
|
||||||
|
|
||||||
|
std::shared_ptr<TreeNode<T>> nextOnSameLevel();
|
||||||
|
std::shared_ptr<TreeNode<T>> parent;
|
||||||
|
std::shared_ptr<T> data;
|
||||||
|
std::list<std::shared_ptr<TreeNode<T>>> children;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
TreeNode<T>::TreeNode()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorNode::EditorNode(std::shared_ptr<EditorElementData> data)
|
template <class T>
|
||||||
|
TreeNode<T>::TreeNode(std::shared_ptr<T> data)
|
||||||
{
|
{
|
||||||
this->data = data;
|
this->data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorNode::~EditorNode()
|
template <class T>
|
||||||
|
TreeNode<T>::~TreeNode()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<EditorNode> EditorNode::nextSibling()
|
template <class T>
|
||||||
|
const std::shared_ptr<TreeNode<T>> TreeNode<T>::nextSibling()
|
||||||
{
|
{
|
||||||
if (parent != nullptr) {
|
if (parent != nullptr) {
|
||||||
auto l = parent->getChildren();
|
auto l = parent->getChildren();
|
||||||
auto it = std::find(l.begin(), l.end(), std::shared_ptr<EditorNode>(this));
|
auto it = std::find(l.begin(), l.end(), std::shared_ptr<TreeNode<T>>(this));
|
||||||
if (it != l.end() && ++it != l.end())
|
if (it != l.end() && ++it != l.end())
|
||||||
return *(++it); //next sibling...
|
return *(++it); //next sibling...
|
||||||
else
|
else
|
||||||
|
@ -31,7 +101,8 @@ const std::shared_ptr<EditorNode> EditorNode::nextSibling()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<EditorNode> EditorNode::next(TreeWalkStrategy walkStrategy)
|
template <class T>
|
||||||
|
const std::shared_ptr<TreeNode<T>> TreeNode<T>::next(TreeWalkStrategy walkStrategy)
|
||||||
{
|
{
|
||||||
if (walkStrategy == TreeWalkStrategy::mixture)
|
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.
|
// 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> EditorNode::next(TreeWalkStrategy walkStrategy
|
||||||
return getChildren().front();
|
return getChildren().front();
|
||||||
//return getChildren().first();
|
//return getChildren().first();
|
||||||
else {
|
else {
|
||||||
auto node = std::shared_ptr<EditorNode>(this);
|
auto node = std::shared_ptr<TreeNode<T>>(this);
|
||||||
while (node->nextSibling() == nullptr && node->getParent() != nullptr)
|
while (node->nextSibling() == nullptr && node->getParent() != nullptr)
|
||||||
node = node->getParent();
|
node = node->getParent();
|
||||||
return node->nextSibling();
|
return node->nextSibling();
|
||||||
|
@ -88,39 +159,44 @@ const std::shared_ptr<EditorNode> EditorNode::next(TreeWalkStrategy walkStrategy
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<EditorNode> EditorNode::getRoot()
|
template <class T>
|
||||||
|
const std::shared_ptr<TreeNode<T>> TreeNode<T>::getRoot()
|
||||||
{
|
{
|
||||||
auto node = std::shared_ptr<EditorNode>(this);
|
auto node = std::shared_ptr<TreeNode<T>>(this);
|
||||||
while (node->getParent() != nullptr)
|
while (node->getParent() != nullptr)
|
||||||
node = node->getParent();
|
node = node->getParent();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorNode::move(std::shared_ptr<EditorNode> to)
|
template <class T>
|
||||||
|
void TreeNode<T>::move(std::shared_ptr<TreeNode<T>> to)
|
||||||
{
|
{
|
||||||
this->getParent()->getChildren().remove(std::shared_ptr<EditorNode>(this));
|
this->getParent()->getChildren().remove(std::shared_ptr<TreeNode<T>>(this));
|
||||||
//this->getParent()->getChildren().removeOne(std::shared_ptr<EditorNode>(this));
|
//this->getParent()->getChildren().removeOne(std::shared_ptr<EditorNode>(this));
|
||||||
to->getChildren().push_back(std::shared_ptr<EditorNode>(this));
|
to->getChildren().push_back(std::shared_ptr<TreeNode<T>>(this));
|
||||||
//to->getChildren().append(std::shared_ptr<EditorNode>(this));
|
//to->getChildren().append(std::shared_ptr<EditorNode>(this));
|
||||||
fireTreeChanged();
|
fireTreeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorNode::moveChildren(std::shared_ptr<EditorNode> to)
|
template <class T>
|
||||||
|
void TreeNode<T>::moveChildren(std::shared_ptr<TreeNode<T>> to)
|
||||||
{
|
{
|
||||||
for (auto child : getChildren())
|
for (auto child : getChildren())
|
||||||
child->move(to);
|
child->move(to);
|
||||||
fireTreeChanged();
|
fireTreeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorNode::addChild(std::shared_ptr<EditorNode> child)
|
template <class T>
|
||||||
|
void TreeNode<T>::addChild(std::shared_ptr<TreeNode<T>> child)
|
||||||
{
|
{
|
||||||
this->getChildren().push_back(child);
|
this->getChildren().push_back(child);
|
||||||
//this->getChildren().append(child);
|
//this->getChildren().append(child);
|
||||||
child->setParent(std::shared_ptr<EditorNode>(this));
|
child->setParent(std::shared_ptr<TreeNode<T>>(this));
|
||||||
fireTreeChanged();
|
fireTreeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorNode::removeChild(std::shared_ptr<EditorNode> child)
|
template <class T>
|
||||||
|
bool TreeNode<T>::removeChild(std::shared_ptr<TreeNode<T>> child)
|
||||||
{
|
{
|
||||||
this->getChildren().remove(child);
|
this->getChildren().remove(child);
|
||||||
bool ret = true; //this->getChildren().removeOne(child);
|
bool ret = true; //this->getChildren().removeOne(child);
|
||||||
|
@ -128,7 +204,8 @@ bool EditorNode::removeChild(std::shared_ptr<EditorNode> child)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorNode::remove()
|
template <class T>
|
||||||
|
bool TreeNode<T>::remove()
|
||||||
{
|
{
|
||||||
bool worked = true;
|
bool worked = true;
|
||||||
if (children.size() > 0) {
|
if (children.size() > 0) {
|
||||||
|
@ -137,69 +214,66 @@ bool EditorNode::remove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (worked && parent != nullptr) {
|
if (worked && parent != nullptr) {
|
||||||
parent->getChildren().remove(std::shared_ptr<EditorNode>(this));
|
parent->getChildren().remove(std::shared_ptr<TreeNode<T>>(this));
|
||||||
//worked &= parent->getChildren().removeOne(std::shared_ptr<EditorNode>(this));
|
//worked &= parent->getChildren().removeOne(std::shared_ptr<EditorNode>(this));
|
||||||
}
|
}
|
||||||
if (worked) fireTreeChanged();
|
if (worked) fireTreeChanged();
|
||||||
return worked;
|
return worked;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<EditorNode> EditorNode::getParent() const
|
template <class T>
|
||||||
|
std::shared_ptr<TreeNode<T>> TreeNode<T>::getParent() const
|
||||||
{
|
{
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorNode::setParent(const std::shared_ptr<EditorNode> &value)
|
template <class T>
|
||||||
|
void TreeNode<T>::setParent(const std::shared_ptr<TreeNode<T>> &value)
|
||||||
{
|
{
|
||||||
parent = value;
|
parent = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<EditorElementData> EditorNode::getData() const
|
template <class T>
|
||||||
|
std::shared_ptr<T> TreeNode<T>::getData() const
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorNode::setData(const std::shared_ptr<EditorElementData> &value)
|
template <class T>
|
||||||
|
void TreeNode<T>::setData(const std::shared_ptr<T> &value)
|
||||||
{
|
{
|
||||||
fireNodeDataChanged();
|
fireNodeDataChanged();
|
||||||
data = value;
|
data = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<EditorElementValue> EditorNode::getValue() const
|
template <class T>
|
||||||
{
|
std::list<std::shared_ptr<TreeNode<T>>> TreeNode<T>::getChildren() const
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorNode::setValue(const std::shared_ptr<EditorElementValue> &value)
|
|
||||||
{
|
|
||||||
fireNodeDataChanged();
|
|
||||||
this->value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<std::shared_ptr<EditorNode> > EditorNode::getChildren() const
|
|
||||||
{
|
{
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorNode::fireNodeDataChanged()
|
template <class T>
|
||||||
|
void TreeNode<T>::fireNodeDataChanged()
|
||||||
{
|
{
|
||||||
if(this->getRoot()->getDataChangedSignal() != nullptr)
|
if(this->getRoot()->getDataChangedSignal() != nullptr)
|
||||||
this->getRoot()->getDataChangedSignal()(std::shared_ptr<EditorNode>(this));
|
this->getRoot()->getDataChangedSignal()(std::shared_ptr<TreeNode<T>>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorNode::fireTreeChanged()
|
template <class T>
|
||||||
|
void TreeNode<T>::fireTreeChanged()
|
||||||
{
|
{
|
||||||
if(this->getRoot()->getTreeChangedSignal() != nullptr)
|
if(this->getRoot()->getTreeChangedSignal() != nullptr)
|
||||||
this->getRoot()->getTreeChangedSignal()(std::shared_ptr<EditorNode>(this));
|
this->getRoot()->getTreeChangedSignal()(std::shared_ptr<TreeNode<T>>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<EditorNode> EditorNode::nextOnSameLevel()
|
template <class T>
|
||||||
|
std::shared_ptr<TreeNode<T>> TreeNode<T>::nextOnSameLevel()
|
||||||
{
|
{
|
||||||
if (nextSibling() != nullptr)
|
if (nextSibling() != nullptr)
|
||||||
return nextSibling();
|
return nextSibling();
|
||||||
uint lvl = 1;
|
uint lvl = 1;
|
||||||
auto node = this->getParent();
|
auto node = this->getParent();
|
||||||
auto pnode = std::shared_ptr<EditorNode>(this);
|
auto pnode = std::shared_ptr<TreeNode<T>>(this);
|
||||||
while (lvl > 0 && node != nullptr) {
|
while (lvl > 0 && node != nullptr) {
|
||||||
if (node != pnode->getParent() && node->getChildren().size() > 0) {
|
if (node != pnode->getParent() && node->getChildren().size() > 0) {
|
||||||
node = node->getChildren().front();
|
node = node->getChildren().front();
|
||||||
|
@ -219,3 +293,19 @@ std::shared_ptr<EditorNode> EditorNode::nextOnSameLevel()
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
uint TreeNode<T>::getDistanceFromRoot()
|
||||||
|
{
|
||||||
|
std::shared_ptr<TreeNode<T>> node = std::make_shared<TreeNode<T>>(this);
|
||||||
|
uint lvl = 0;
|
||||||
|
while(node->getParent() != nullptr)
|
||||||
|
{
|
||||||
|
++lvl;
|
||||||
|
node = node->getParent();
|
||||||
|
}
|
||||||
|
return lvl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // EDITORNODE_H
|
|
@ -1,101 +0,0 @@
|
||||||
#ifndef PACKETELEMENT_H
|
|
||||||
#define PACKETELEMENT_H
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
|
|
||||||
class PacketElement;
|
|
||||||
|
|
||||||
typedef
|
|
||||||
std::list<std::shared_ptr<PacketElement>>
|
|
||||||
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<PacketElementList_t> getNextLayer() { return nextLayer; }
|
|
||||||
/**
|
|
||||||
@brief hasNextLayer
|
|
||||||
@return
|
|
||||||
*/
|
|
||||||
bool hasNextLayer() { return nextLayer != nullptr && sizeInBit == 0; }
|
|
||||||
/**
|
|
||||||
@brief setNextLayer
|
|
||||||
@param layerElements
|
|
||||||
*/
|
|
||||||
void setNextLayer(std::shared_ptr<PacketElementList_t>& layerElements) { nextLayer = layerElements; }
|
|
||||||
|
|
||||||
void addSyntax(std::string minimalRegex, std::string completeRegex, std::string example)
|
|
||||||
{
|
|
||||||
std::shared_ptr<ElementSyntax> syntax = std::make_shared<ElementSyntax>();
|
|
||||||
syntax->triggerRegex = minimalRegex;
|
|
||||||
syntax->completeRegex = completeRegex;
|
|
||||||
syntax->example = example;
|
|
||||||
syntaxes.push_back(syntax);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<uint8_t> getBytes();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string name;
|
|
||||||
uint32_t sizeInBit;
|
|
||||||
uint16_t layer;
|
|
||||||
std::string value;
|
|
||||||
ValueType valueType;
|
|
||||||
|
|
||||||
std::shared_ptr<PacketElementList_t> nextLayer;
|
|
||||||
|
|
||||||
//additional data
|
|
||||||
std::string description;
|
|
||||||
std::list<std::shared_ptr<ElementSyntax>> syntaxes;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PACKETELEMENT_H
|
|
|
@ -1,13 +0,0 @@
|
||||||
#include "packetmodel.h"
|
|
||||||
|
|
||||||
#include "packetelement.h"
|
|
||||||
|
|
||||||
PacketModel::PacketModel()
|
|
||||||
{
|
|
||||||
this->elementList = std::make_shared<PacketElementList_t>();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::shared_ptr<PacketElementList_t> PacketModel::getList()
|
|
||||||
{
|
|
||||||
return this->elementList;
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include "../editor/EditorNode.h"
|
#include "../model/TreeNode.h"
|
||||||
|
|
||||||
|
|
||||||
class DataLoader {
|
class DataLoader {
|
||||||
|
@ -18,13 +18,13 @@ public:
|
||||||
|
|
||||||
void loadSingleProtocol(std::string filename);
|
void loadSingleProtocol(std::string filename);
|
||||||
|
|
||||||
std::shared_ptr<EditorNode> generateTree(YAML::Node &node);
|
std::shared_ptr<TreeNode<T>> generateTree(YAML::Node &node);
|
||||||
|
|
||||||
bool getProtocolByName(std::string name, YAML::Node &node);
|
bool getProtocolByName(std::string name, YAML::Node &node);
|
||||||
std::list<std::string> getProtocolNames();
|
std::list<std::string> getProtocolNames();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<EditorNode> genNode(YAML::Node& n, std::shared_ptr<EditorNode> parent = nullptr);
|
std::shared_ptr<TreeNode<T>> genNode(YAML::Node& n, std::shared_ptr<TreeNode<T>> parent = nullptr);
|
||||||
std::string directory;
|
std::string directory;
|
||||||
std::list<YAML::Node> protocolList;
|
std::list<YAML::Node> protocolList;
|
||||||
};
|
};
|
Reference in New Issue