diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c74384..35e5fa5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..0b18f81 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,9 @@ +[requires] +Qt/5.8.0@osechet/stable +gtest/1.8.0@bincrafters/stable + +[options] +Qt:shared=True + +[generators] +cmake diff --git a/doc/editor.md b/doc/editor.md new file mode 100644 index 0000000..be4dada --- /dev/null +++ b/doc/editor.md @@ -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 + + + +``` diff --git a/doc/mvc.md b/doc/mvc.md new file mode 100644 index 0000000..c59e575 --- /dev/null +++ b/doc/mvc.md @@ -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 + +``` diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3f90f00..1169ab7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a7a8470..760aaf0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -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}) diff --git a/src/core/control/DataController.cpp b/src/core/control/DataController.cpp new file mode 100644 index 0000000..e526eb5 --- /dev/null +++ b/src/core/control/DataController.cpp @@ -0,0 +1,6 @@ +#include "DataController.h" + +DataController::DataController() +{ + +} diff --git a/src/core/control/DataController.h b/src/core/control/DataController.h new file mode 100644 index 0000000..e8fe393 --- /dev/null +++ b/src/core/control/DataController.h @@ -0,0 +1,13 @@ +#ifndef DATACONTROLLER_H +#define DATACONTROLLER_H + +namespace NPC_core { +namespace control { + +class DataController +{ +public: + DataController(); +}; +}} +#endif // DATACONTROLLER_H diff --git a/src/core/control/ModelController.cpp b/src/core/control/ModelController.cpp new file mode 100644 index 0000000..ac5257c --- /dev/null +++ b/src/core/control/ModelController.cpp @@ -0,0 +1,12 @@ +#include "ModelController.h" + + +namespace NPC_core { +namespace Control { + +ModelController::ModelController() +{ + +} + +}} diff --git a/src/core/control/ModelController.h b/src/core/control/ModelController.h new file mode 100644 index 0000000..16c5ad3 --- /dev/null +++ b/src/core/control/ModelController.h @@ -0,0 +1,13 @@ +#ifndef MODELCONTROLLER_H +#define MODELCONTROLLER_H + + +namespace NPC_core { +namespace Control { +class ModelController +{ +public: + ModelController(); +}; +}} +#endif // MODELCONTROLLER_H diff --git a/src/core/model/DataField.cpp b/src/core/model/DataField.cpp new file mode 100644 index 0000000..6451439 --- /dev/null +++ b/src/core/model/DataField.cpp @@ -0,0 +1,41 @@ +#include "DataField.h" + +namespace NPC_core { +namespace Model { + +DataField::DataField(std::shared_ptr field) +{ + this->field = field; + this->structure = field->getParentStructure(); +} + +std::shared_ptr DataField::getField() const +{ + return field; +} + +std::shared_ptr DataField::getStructure() const +{ + return structure; +} + +std::string DataField::getValue() const +{ + return value; +} + +void DataField::setValue(const std::string &value) +{ + this->value = value; +} + +std::list > DataField::getModifiers() const +{ + return modifiers; +} + +void DataField::addModifier(const std::shared_ptr &value) +{ + modifiers.push_back(value); +} +}} diff --git a/src/core/model/DataField.h b/src/core/model/DataField.h new file mode 100644 index 0000000..f8c5bec --- /dev/null +++ b/src/core/model/DataField.h @@ -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); + + std::shared_ptr getField() const; + + std::shared_ptr getStructure() const; + + std::string getValue() const; + void setValue(const std::string &value); + + std::list> getModifiers() const; + void addModifier(const std::shared_ptr &value); + +private: + std::shared_ptr field; + std::shared_ptr structure; + std::string value; + std::list> modifiers; // TODO +}; + +}} +#endif // DATAFIELD_H diff --git a/src/core/model/Field.cpp b/src/core/model/Field.cpp index 526a3fc..7842cf7 100644 --- a/src/core/model/Field.cpp +++ b/src/core/model/Field.cpp @@ -27,16 +27,6 @@ void Field::setSyntaxes(const std::map &value) syntaxes = value; } -std::string Field::getValue() const -{ - return value; -} - -void Field::setValue(const std::string &value) -{ - this->value = value; -} - std::shared_ptr Field::getParentStructure() const { return parentStructure; diff --git a/src/core/model/Field.h b/src/core/model/Field.h index 20dcfbf..a491fa6 100644 --- a/src/core/model/Field.h +++ b/src/core/model/Field.h @@ -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 getSyntaxes() const; void setSyntaxes(const std::map &value); - std::string getValue() const; - void setValue(const std::string &value); - std::shared_ptr getParentStructure() const; void setParentStructure(const std::shared_ptr &value); @@ -33,7 +30,8 @@ protected: std::shared_ptr parentStructure; std::string name; std::map syntaxes; // example : regex; for validation - std::string value; + std::map options; + bool nextLevel; }; }} diff --git a/src/core/model/IField.h b/src/core/model/IField.h new file mode 100644 index 0000000..61f8a06 --- /dev/null +++ b/src/core/model/IField.h @@ -0,0 +1,25 @@ +#ifndef IFIELD_H +#define IFIELD_H +#include "Structure.h" +#include +#include +#include + +namespace NPC_core { +namespace Model { + +class Structure; + +class IField +{ +public: + virtual std::string getName() const = 0; + + virtual std::map getSyntaxes() const = 0; + + virtual std::shared_ptr getParentStructure() const = 0; + + virtual bool isNextLevel() = 0; +}; +}} +#endif // IFIELD_H diff --git a/src/core/model/IStructure.h b/src/core/model/IStructure.h new file mode 100644 index 0000000..26335c6 --- /dev/null +++ b/src/core/model/IStructure.h @@ -0,0 +1,21 @@ +#ifndef ISTRUCTURE_H +#define ISTRUCTURE_H +#include +#include +#include "Field.h" +#include "../Tree.h" + +namespace NPC_core { +namespace Model { + +class Field; + +class IStructure +{ +public: + virtual std::string getName() const = 0; + + virtual Tree getElements() const = 0; +}; +}} +#endif // ISTRUCTURE_H diff --git a/src/core/model/Model.cpp b/src/core/model/Model.cpp index 5a0ca97..7a3c35c 100644 --- a/src/core/model/Model.cpp +++ b/src/core/model/Model.cpp @@ -5,4 +5,25 @@ Model::Model() { } + +Tree Model::getStack() const +{ + return stack; +} + +std::list > Model::getStructures() const +{ + return structures; +} + +std::shared_ptr Model::getRAB() const +{ + return rab; +} + +void Model::update() +{ + +} + }} diff --git a/src/core/model/Model.h b/src/core/model/Model.h index 92287c7..d364485 100644 --- a/src/core/model/Model.h +++ b/src/core/model/Model.h @@ -2,7 +2,9 @@ #define AMODEL_H #include "../Tree.h" -#include "Field.h" +#include "DataField.h" +#include "../RandomAccessBinary.h" +#include namespace NPC_core { namespace Model { @@ -10,10 +12,21 @@ class Model { public: Model(); - virtual ~Model(); + virtual ~Model(){} + + Tree getStack() const; + std::list> getStructures() const; + std::shared_ptr getRAB() const; + + void addStructure(std::shared_ptr structure); + + void update(); // updates the stack if a new structure has been added, and updates the binary private: - Tree stack; + Tree stack; + std::shared_ptr rab; + + std::list> structures; }; }} #endif // AMODEL_H diff --git a/src/core/model/Modifier.cpp b/src/core/model/Modifier.cpp new file mode 100644 index 0000000..dfff357 --- /dev/null +++ b/src/core/model/Modifier.cpp @@ -0,0 +1,6 @@ +#include "Modifier.h" + +Modifier::Modifier() +{ + +} diff --git a/src/core/model/Modifier.h b/src/core/model/Modifier.h new file mode 100644 index 0000000..4f63866 --- /dev/null +++ b/src/core/model/Modifier.h @@ -0,0 +1,17 @@ +#ifndef MODIFIER_H +#define MODIFIER_H + +#include +#include + +class Modifier +{ +public: + Modifier(); + virtual ~Modifier(); + + virtual void modifySelf(std::shared_ptr> bytes) = 0; + virtual void modifySelfFromFullData(std::shared_ptr> bytes, const std::shared_ptr> data) = 0; +}; + +#endif // MODIFIER_H diff --git a/src/core/model/NextLevelField.cpp b/src/core/model/NextLevelField.cpp new file mode 100644 index 0000000..6484faa --- /dev/null +++ b/src/core/model/NextLevelField.cpp @@ -0,0 +1,22 @@ +#include "NextLevelField.h" + +namespace NPC_core{ +namespace Model { + +NextLevelField::NextLevelField() +{ + +} + +std::shared_ptr NextLevelField::getNextLevel() const +{ + return nextLevel; +} + +void NextLevelField::setNextLevel(const std::shared_ptr &value) +{ + nextLevel = value; +} + +} +} diff --git a/src/core/model/NextLevelField.h b/src/core/model/NextLevelField.h new file mode 100644 index 0000000..1876c5d --- /dev/null +++ b/src/core/model/NextLevelField.h @@ -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 getNextLevel() const; + void setNextLevel(const std::shared_ptr &value); + +private: + std::shared_ptr nextLevel; +}; + +} +} + +#endif // NEXTLEVELFIELD_H diff --git a/src/core/model/Structure.cpp b/src/core/model/Structure.cpp index a061eff..7b9893a 100644 --- a/src/core/model/Structure.cpp +++ b/src/core/model/Structure.cpp @@ -15,4 +15,14 @@ void Structure::setName(const std::string &value) { name = value; } + +Tree Structure::getElements() const +{ + return elements; +} + +void Structure::setElements(const Tree &value) +{ + elements = value; +} }} diff --git a/src/core/model/Structure.h b/src/core/model/Structure.h index bb2e0bf..bfbbe89 100644 --- a/src/core/model/Structure.h +++ b/src/core/model/Structure.h @@ -15,11 +15,15 @@ class Structure { public: Structure(); - virtual ~Structure(); + virtual ~Structure() {} std::string getName() const; void setName(const std::string &value); + + Tree getElements() const; + void setElements(const Tree &value); + private: Tree elements; std::string name; diff --git a/src/editor/CMakeLists.txt b/src/editor/CMakeLists.txt index d04d9b0..f08ada9 100644 --- a/src/editor/CMakeLists.txt +++ b/src/editor/CMakeLists.txt @@ -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}) diff --git a/src/editor/EditorView.cpp b/src/editor/EditorView.cpp new file mode 100644 index 0000000..69211d1 --- /dev/null +++ b/src/editor/EditorView.cpp @@ -0,0 +1,19 @@ +#include "EditorView.h" + +using namespace NPC_editor; + +EditorView::EditorView(QWidget *parent) : QWidget(parent) +{ + this->flowLayout = std::make_shared(); + this->setLayout(this->flowLayout.get()); +} + +void EditorView::addWidget(QWidget *widget) +{ + this->flowLayout->addWidget(widget); +} + +void EditorView::remWidget(QWidget *widget) +{ + this->flowLayout->removeWidget(widget); +} diff --git a/src/editor/EditorView.h b/src/editor/EditorView.h new file mode 100644 index 0000000..98e2e55 --- /dev/null +++ b/src/editor/EditorView.h @@ -0,0 +1,28 @@ +#ifndef EDITORVIEW_H +#define EDITORVIEW_H + +#include +#include +#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; +}; +} +#endif // EDITORVIEW_H diff --git a/src/editor/flowlayout.h b/src/editor/flowlayout.h index cd22722..0a33813 100644 --- a/src/editor/flowlayout.h +++ b/src/editor/flowlayout.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; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 477566e..2750689 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include #include +#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); diff --git a/src/mainwindow.h b/src/mainwindow.h index 729540e..9d47aa3 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -6,14 +6,14 @@ #include #include #include -#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(); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3093124..3d4efdc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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}) diff --git a/test/core/test_model.cpp b/test/core/test_model.cpp new file mode 100644 index 0000000..f3e3c87 --- /dev/null +++ b/test/core/test_model.cpp @@ -0,0 +1,28 @@ +#include +#include +#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()); + +}