parent
1a63595188
commit
1abe32d0d7
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
project(network_packet_composer)
|
||||
|
||||
# set(CMAKE_CXX_COMPILER clazy)
|
||||
set(CMAKE_CXX_FLAGS "-std=c++14 -g -Wall")
|
||||
|
||||
# Find includes in corresponding build directories
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[requires]
|
||||
Qt/5.8.0@osechet/stable
|
||||
gtest/1.8.0@bincrafters/stable
|
||||
|
||||
[options]
|
||||
Qt:shared=True
|
||||
|
||||
[generators]
|
||||
cmake
|
|
@ -0,0 +1,52 @@
|
|||
# Editor
|
||||
|
||||
```plantuml
|
||||
|
||||
set namespaceSeparator ::
|
||||
|
||||
class NPC_core::RandomAccessBinary
|
||||
|
||||
namespace NPC_editor {
|
||||
class EditorView {
|
||||
}
|
||||
class StructureField {
|
||||
}
|
||||
class HexView
|
||||
EditorView "1" *-- "*" StructureField : contains
|
||||
HexView ..> NPC_core::RandomAccessBinary : shows data of >
|
||||
}
|
||||
|
||||
namespace NPC_core::control {
|
||||
class DataController
|
||||
class ModelController
|
||||
class FromScratchModelController
|
||||
ModelController <|-- FromScratchModelController
|
||||
}
|
||||
|
||||
namespace NPC_core::model {
|
||||
class Model
|
||||
class Structure
|
||||
|
||||
class Field
|
||||
class DataField
|
||||
|
||||
class Repository
|
||||
|
||||
Model "1" *-- "*" Structure
|
||||
DataField ..> Field : represents the data of >
|
||||
Repository "1" *-- "ALL" Structure
|
||||
Structure "1" *- "*" Field
|
||||
Model "1" *--- "*" NPC_core::RandomAccessBinary
|
||||
}
|
||||
|
||||
NPC_core::model::Field <.. NPC_editor::StructureField : shows <
|
||||
NPC_core::control::DataController --> NPC_core::model::DataField : controls >
|
||||
|
||||
|
||||
NPC_core::control::ModelController --> NPC_core::model::Model : controls >
|
||||
|
||||
NPC_editor::StructureField .> NPC_core::control::DataController : > manipulates data through
|
||||
|
||||
|
||||
|
||||
```
|
|
@ -0,0 +1,22 @@
|
|||
```plantuml
|
||||
@startuml
|
||||
|
||||
package Model {
|
||||
class StackModel
|
||||
}
|
||||
|
||||
package View {
|
||||
class Editor
|
||||
}
|
||||
|
||||
package "Controller" as pkg_controller {
|
||||
class Controller
|
||||
}
|
||||
|
||||
pkg_controller -> Model: controls
|
||||
View --> pkg_controller: uses
|
||||
View --> Model: shows
|
||||
|
||||
@enduml
|
||||
|
||||
```
|
|
@ -4,11 +4,15 @@ set(HEADERS mainwindow.h
|
|||
set(SOURCES mainwindow.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(model)
|
||||
# add_subdirectory(model)
|
||||
add_subdirectory(editor)
|
||||
add_subdirectory(parser)
|
||||
add_subdirectory(core)
|
||||
|
||||
add_library(src ${HEADERS} ${SOURCES})
|
||||
target_link_libraries(src model editor parser core )
|
||||
target_link_libraries(src
|
||||
editor
|
||||
parser
|
||||
core
|
||||
)
|
||||
qt5_use_modules(src Widgets)
|
||||
|
|
|
@ -4,41 +4,54 @@ set(HEADERS
|
|||
TreeNode.h
|
||||
BinaryPacketComposer.h
|
||||
APluginManager.h
|
||||
RandomAccessBinary.h
|
||||
# interfaces to model
|
||||
model/IField.h
|
||||
model/IStructure.h
|
||||
# full model implementations
|
||||
model/Repository.h
|
||||
model/Model.h
|
||||
model/Structure.h
|
||||
model/Field.h
|
||||
model/DataField.h
|
||||
model/Modifier.h
|
||||
# control classes
|
||||
control/ARepositoryFactory.h
|
||||
control/AFieldFactory.h
|
||||
control/AStructureFactory.h
|
||||
control/AModelFactory.h
|
||||
|
||||
control/ModelController.h
|
||||
control/DataController.h
|
||||
# schema classes
|
||||
schemaio/AStructureReaderFactory.h
|
||||
schemaio/AStructureWriterFactory.h
|
||||
schemaio/AStructureReader.h
|
||||
schemaio/AStructureWriter.h
|
||||
|
||||
RandomAccessBinary.h
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
BinaryPacketComposer.cpp
|
||||
APluginManager.cpp
|
||||
RandomAccessBinary.cpp
|
||||
|
||||
model/Repository.cpp
|
||||
model/Model.cpp
|
||||
model/Structure.cpp
|
||||
model/Field.cpp
|
||||
model/DataField.cpp
|
||||
model/Modifier.cpp
|
||||
|
||||
control/ARepositoryFactory.cpp
|
||||
control/AFieldFactory.cpp
|
||||
control/AStructureFactory.cpp
|
||||
control/AModelFactory.cpp
|
||||
control/ModelController.cpp
|
||||
control/DataController.cpp
|
||||
|
||||
schemaio/AStructureReaderFactory.cpp
|
||||
schemaio/AStructureWriterFactory.cpp
|
||||
schemaio/AStructureReader.cpp
|
||||
schemaio/AStructureWriter.cpp
|
||||
|
||||
RandomAccessBinary.cpp
|
||||
)
|
||||
|
||||
add_library(core ${HEADERS} ${SOURCES})
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#include "DataController.h"
|
||||
|
||||
DataController::DataController()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef DATACONTROLLER_H
|
||||
#define DATACONTROLLER_H
|
||||
|
||||
namespace NPC_core {
|
||||
namespace control {
|
||||
|
||||
class DataController
|
||||
{
|
||||
public:
|
||||
DataController();
|
||||
};
|
||||
}}
|
||||
#endif // DATACONTROLLER_H
|
|
@ -0,0 +1,12 @@
|
|||
#include "ModelController.h"
|
||||
|
||||
|
||||
namespace NPC_core {
|
||||
namespace Control {
|
||||
|
||||
ModelController::ModelController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef MODELCONTROLLER_H
|
||||
#define MODELCONTROLLER_H
|
||||
|
||||
|
||||
namespace NPC_core {
|
||||
namespace Control {
|
||||
class ModelController
|
||||
{
|
||||
public:
|
||||
ModelController();
|
||||
};
|
||||
}}
|
||||
#endif // MODELCONTROLLER_H
|
|
@ -0,0 +1,41 @@
|
|||
#include "DataField.h"
|
||||
|
||||
namespace NPC_core {
|
||||
namespace Model {
|
||||
|
||||
DataField::DataField(std::shared_ptr<Field> field)
|
||||
{
|
||||
this->field = field;
|
||||
this->structure = field->getParentStructure();
|
||||
}
|
||||
|
||||
std::shared_ptr<Field> DataField::getField() const
|
||||
{
|
||||
return field;
|
||||
}
|
||||
|
||||
std::shared_ptr<Structure> DataField::getStructure() const
|
||||
{
|
||||
return structure;
|
||||
}
|
||||
|
||||
std::string DataField::getValue() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void DataField::setValue(const std::string &value)
|
||||
{
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<Modifier> > DataField::getModifiers() const
|
||||
{
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
void DataField::addModifier(const std::shared_ptr<Modifier> &value)
|
||||
{
|
||||
modifiers.push_back(value);
|
||||
}
|
||||
}}
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef DATAFIELD_H
|
||||
#define DATAFIELD_H
|
||||
|
||||
#include "Field.h"
|
||||
#include "Structure.h"
|
||||
#include "Modifier.h"
|
||||
namespace NPC_core {
|
||||
namespace Model {
|
||||
|
||||
class DataField
|
||||
{
|
||||
public:
|
||||
DataField(std::shared_ptr<Field> field);
|
||||
|
||||
std::shared_ptr<Field> getField() const;
|
||||
|
||||
std::shared_ptr<Structure> getStructure() const;
|
||||
|
||||
std::string getValue() const;
|
||||
void setValue(const std::string &value);
|
||||
|
||||
std::list<std::shared_ptr<Modifier>> getModifiers() const;
|
||||
void addModifier(const std::shared_ptr<Modifier> &value);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Field> field;
|
||||
std::shared_ptr<Structure> structure;
|
||||
std::string value;
|
||||
std::list<std::shared_ptr<Modifier>> modifiers; // TODO
|
||||
};
|
||||
|
||||
}}
|
||||
#endif // DATAFIELD_H
|
|
@ -27,16 +27,6 @@ void Field::setSyntaxes(const std::map<std::string, std::string> &value)
|
|||
syntaxes = value;
|
||||
}
|
||||
|
||||
std::string Field::getValue() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void Field::setValue(const std::string &value)
|
||||
{
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
std::shared_ptr<Structure> Field::getParentStructure() const
|
||||
{
|
||||
return parentStructure;
|
||||
|
|
|
@ -15,7 +15,7 @@ class Field
|
|||
{
|
||||
public:
|
||||
Field();
|
||||
virtual ~Field();
|
||||
virtual ~Field(){}
|
||||
|
||||
std::string getName() const;
|
||||
void setName(const std::string &value);
|
||||
|
@ -23,9 +23,6 @@ public:
|
|||
std::map<std::string, std::string> getSyntaxes() const;
|
||||
void setSyntaxes(const std::map<std::string, std::string> &value);
|
||||
|
||||
std::string getValue() const;
|
||||
void setValue(const std::string &value);
|
||||
|
||||
std::shared_ptr<Structure> getParentStructure() const;
|
||||
void setParentStructure(const std::shared_ptr<Structure> &value);
|
||||
|
||||
|
@ -33,7 +30,8 @@ protected:
|
|||
std::shared_ptr<Structure> parentStructure;
|
||||
std::string name;
|
||||
std::map<std::string, std::string> syntaxes; // example : regex; for validation
|
||||
std::string value;
|
||||
std::map<std::string, std::string> options;
|
||||
bool nextLevel;
|
||||
};
|
||||
}}
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef IFIELD_H
|
||||
#define IFIELD_H
|
||||
#include "Structure.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace NPC_core {
|
||||
namespace Model {
|
||||
|
||||
class Structure;
|
||||
|
||||
class IField
|
||||
{
|
||||
public:
|
||||
virtual std::string getName() const = 0;
|
||||
|
||||
virtual std::map<std::string, std::string> getSyntaxes() const = 0;
|
||||
|
||||
virtual std::shared_ptr<Structure> getParentStructure() const = 0;
|
||||
|
||||
virtual bool isNextLevel() = 0;
|
||||
};
|
||||
}}
|
||||
#endif // IFIELD_H
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef ISTRUCTURE_H
|
||||
#define ISTRUCTURE_H
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include "Field.h"
|
||||
#include "../Tree.h"
|
||||
|
||||
namespace NPC_core {
|
||||
namespace Model {
|
||||
|
||||
class Field;
|
||||
|
||||
class IStructure
|
||||
{
|
||||
public:
|
||||
virtual std::string getName() const = 0;
|
||||
|
||||
virtual Tree<Field> getElements() const = 0;
|
||||
};
|
||||
}}
|
||||
#endif // ISTRUCTURE_H
|
|
@ -5,4 +5,25 @@ Model::Model()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
Tree<DataField> Model::getStack() const
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<Structure> > Model::getStructures() const
|
||||
{
|
||||
return structures;
|
||||
}
|
||||
|
||||
std::shared_ptr<RandomAccessBinary> Model::getRAB() const
|
||||
{
|
||||
return rab;
|
||||
}
|
||||
|
||||
void Model::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
#define AMODEL_H
|
||||
|
||||
#include "../Tree.h"
|
||||
#include "Field.h"
|
||||
#include "DataField.h"
|
||||
#include "../RandomAccessBinary.h"
|
||||
#include <list>
|
||||
|
||||
namespace NPC_core {
|
||||
namespace Model {
|
||||
|
@ -10,10 +12,21 @@ class Model
|
|||
{
|
||||
public:
|
||||
Model();
|
||||
virtual ~Model();
|
||||
virtual ~Model(){}
|
||||
|
||||
Tree<DataField> getStack() const;
|
||||
std::list<std::shared_ptr<Structure>> getStructures() const;
|
||||
std::shared_ptr<RandomAccessBinary> getRAB() const;
|
||||
|
||||
void addStructure(std::shared_ptr<Structure> structure);
|
||||
|
||||
void update(); // updates the stack if a new structure has been added, and updates the binary
|
||||
|
||||
private:
|
||||
Tree<Field> stack;
|
||||
Tree<DataField> stack;
|
||||
std::shared_ptr<RandomAccessBinary> rab;
|
||||
|
||||
std::list<std::shared_ptr<Structure>> structures;
|
||||
};
|
||||
}}
|
||||
#endif // AMODEL_H
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#include "Modifier.h"
|
||||
|
||||
Modifier::Modifier()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef MODIFIER_H
|
||||
#define MODIFIER_H
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
class Modifier
|
||||
{
|
||||
public:
|
||||
Modifier();
|
||||
virtual ~Modifier();
|
||||
|
||||
virtual void modifySelf(std::shared_ptr<std::vector<uint8_t>> bytes) = 0;
|
||||
virtual void modifySelfFromFullData(std::shared_ptr<std::vector<uint8_t>> bytes, const std::shared_ptr<std::vector<uint8_t>> data) = 0;
|
||||
};
|
||||
|
||||
#endif // MODIFIER_H
|
|
@ -0,0 +1,22 @@
|
|||
#include "NextLevelField.h"
|
||||
|
||||
namespace NPC_core{
|
||||
namespace Model {
|
||||
|
||||
NextLevelField::NextLevelField()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<Structure> NextLevelField::getNextLevel() const
|
||||
{
|
||||
return nextLevel;
|
||||
}
|
||||
|
||||
void NextLevelField::setNextLevel(const std::shared_ptr<Structure> &value)
|
||||
{
|
||||
nextLevel = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef NEXTLEVELFIELD_H
|
||||
#define NEXTLEVELFIELD_H
|
||||
|
||||
#include "Field.h"
|
||||
#include "Structure.h"
|
||||
namespace NPC_core{
|
||||
namespace Model {
|
||||
|
||||
class NextLevelField : public Field
|
||||
{
|
||||
public:
|
||||
NextLevelField();
|
||||
|
||||
std::shared_ptr<Structure> getNextLevel() const;
|
||||
void setNextLevel(const std::shared_ptr<Structure> &value);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Structure> nextLevel;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // NEXTLEVELFIELD_H
|
|
@ -15,4 +15,14 @@ void Structure::setName(const std::string &value)
|
|||
{
|
||||
name = value;
|
||||
}
|
||||
|
||||
Tree<Field> Structure::getElements() const
|
||||
{
|
||||
return elements;
|
||||
}
|
||||
|
||||
void Structure::setElements(const Tree<Field> &value)
|
||||
{
|
||||
elements = value;
|
||||
}
|
||||
}}
|
||||
|
|
|
@ -15,11 +15,15 @@ class Structure
|
|||
{
|
||||
public:
|
||||
Structure();
|
||||
virtual ~Structure();
|
||||
virtual ~Structure() {}
|
||||
|
||||
std::string getName() const;
|
||||
void setName(const std::string &value);
|
||||
|
||||
|
||||
Tree<Field> getElements() const;
|
||||
void setElements(const Tree<Field> &value);
|
||||
|
||||
private:
|
||||
Tree<Field> elements;
|
||||
std::string name;
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
set(HEADERS
|
||||
flowlayout.h
|
||||
StructureField.h
|
||||
EditorView.h
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
flowlayout.cpp
|
||||
StructureField.cpp
|
||||
EditorView.cpp
|
||||
)
|
||||
|
||||
add_library(editor ${HEADERS} ${SOURCES})
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#include "EditorView.h"
|
||||
|
||||
using namespace NPC_editor;
|
||||
|
||||
EditorView::EditorView(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
this->flowLayout = std::make_shared<FlowLayout>();
|
||||
this->setLayout(this->flowLayout.get());
|
||||
}
|
||||
|
||||
void EditorView::addWidget(QWidget *widget)
|
||||
{
|
||||
this->flowLayout->addWidget(widget);
|
||||
}
|
||||
|
||||
void EditorView::remWidget(QWidget *widget)
|
||||
{
|
||||
this->flowLayout->removeWidget(widget);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef EDITORVIEW_H
|
||||
#define EDITORVIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include "flowlayout.h"
|
||||
|
||||
namespace NPC_editor {
|
||||
|
||||
class EditorView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EditorView(QWidget *parent = nullptr);
|
||||
virtual ~EditorView() {}
|
||||
|
||||
void addWidget(QWidget * widget);
|
||||
void remWidget(QWidget * widget);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
std::shared_ptr<FlowLayout> flowLayout;
|
||||
};
|
||||
}
|
||||
#endif // EDITORVIEW_H
|
|
@ -10,7 +10,7 @@ class FlowLayout : public QLayout
|
|||
public:
|
||||
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
|
||||
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
|
||||
~FlowLayout();
|
||||
~FlowLayout() override;
|
||||
|
||||
void addItem(QLayoutItem *item) Q_DECL_OVERRIDE;
|
||||
int horizontalSpacing() const;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "mainwindow.h"
|
||||
#include <QPushButton>
|
||||
#include <iostream>
|
||||
#include "editor/EditorView.h"
|
||||
|
||||
void MainWindow::doSomething()
|
||||
{
|
||||
|
@ -12,8 +13,8 @@ void MainWindow::doSomething()
|
|||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
//editor = new GuidedEditorView(this);
|
||||
//this->setCentralWidget(editor);
|
||||
editor = new NPC_editor::EditorView(this);
|
||||
this->setCentralWidget(editor);
|
||||
dockWidget = new QDockWidget(this);
|
||||
this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
#include <QList>
|
||||
#include <QGridLayout>
|
||||
#include <QDockWidget>
|
||||
#include "editor/guidededitorview.h"
|
||||
#include "editor/EditorView.h"
|
||||
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
GuidedEditorView* editor;
|
||||
NPC_editor::EditorView* editor;
|
||||
QDockWidget* dockWidget;
|
||||
public slots:
|
||||
void doSomething();
|
||||
|
|
|
@ -7,6 +7,7 @@ INCLUDE_DIRECTORIES(/usr/include/gtest)
|
|||
set(SOURCES
|
||||
core/test_tree.cpp
|
||||
core/test_rab.cpp
|
||||
core/test_model.cpp
|
||||
)
|
||||
|
||||
add_executable(runUnitTests ${SOURCES})
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include "gtest/gtest.h"
|
||||
#include "../src/core/model/Model.h"
|
||||
#include "../src/core/model/Field.h"
|
||||
#include "../src/core/model/DataField.h"
|
||||
#include "../src/core/model/Structure.h"
|
||||
|
||||
class ModelTest : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp(){
|
||||
baseStructure.setName("BaseStructure");
|
||||
secondLvlStructure.setName("Second Level");
|
||||
|
||||
}
|
||||
|
||||
virtual void TearDown(){
|
||||
}
|
||||
|
||||
NPC_core::Model::Structure baseStructure;
|
||||
NPC_core::Model::Structure secondLvlStructure;
|
||||
NPC_core::Model::Model m;
|
||||
};
|
||||
|
||||
TEST_F(ModelTest, IsEmptyInitially) {
|
||||
EXPECT_EQ(0, m.getStructures().size());
|
||||
|
||||
}
|
Reference in New Issue