From fc6b0a9899c708e5f04210cd268cf7f644ee4332 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Fri, 2 Nov 2018 21:08:00 +0100 Subject: [PATCH] Heavy work again finally... Building a better model of protocol fields and implementing... ... at least the empty hulls, but content will follow. --- .gitignore | 2 + CMakeLists.txt | 2 + doc/binary_utilisation.graphml | 170 ----- doc/classdiagram.graphml | 422 ------------ doc/core.graphml | 683 ------------------- doc/core.md | 99 +++ doc/editor-view.md | 61 ++ doc/editor.md | 3 +- doc/model.graphml | 768 ---------------------- doc/packages.graphml | 484 -------------- doc/structure_rw.graphml | 383 ----------- src/core/CMakeLists.txt | 20 +- src/core/JSONSerializable.h | 14 + src/core/RandomAccessBinary.cpp | 2 + src/core/RandomAccessBinary.h | 3 +- src/core/Validator.h | 9 + src/core/YAMLSerializable.h | 12 + src/core/control/AFieldFactory.cpp | 3 - src/core/control/DataController.cpp | 7 + src/core/control/DataController.h | 8 + src/core/control/ModelController.cpp | 2 +- src/core/control/ModelController.h | 2 +- src/core/model/CombinationField.cpp | 11 + src/core/model/CombinationField.h | 16 + src/core/model/DataField.cpp | 41 -- src/core/model/DataField.h | 33 - src/core/model/Field.cpp | 22 +- src/core/model/Field.h | 46 +- src/core/model/ICombinationField.h | 13 + src/core/model/IField.h | 28 +- src/core/model/ILayerTransitionField.h | 14 + src/core/model/IModel.h | 18 + src/core/model/IRegexValueField.h | 16 + src/core/model/IValidateableValueField.h | 17 + src/core/model/IValueField.h | 17 + src/core/model/LayerTransitionField.cpp | 10 + src/core/model/LayerTransitionField.h | 16 + src/core/model/Model.cpp | 9 +- src/core/model/Model.h | 17 +- src/core/model/NextLevelField.cpp | 22 - src/core/model/NextLevelField.h | 24 - src/core/model/RegexValueField.cpp | 13 + src/core/model/RegexValueField.h | 16 + src/core/model/Structure.h | 3 +- src/core/model/ValidateableValueField.cpp | 23 + src/core/model/ValidateableValueField.h | 24 + src/core/model/ValueField.cpp | 28 + src/core/model/ValueField.h | 25 + test/core/test_model.cpp | 1 - test/core/test_rab.cpp | 1 + 50 files changed, 583 insertions(+), 3100 deletions(-) delete mode 100644 doc/binary_utilisation.graphml delete mode 100644 doc/classdiagram.graphml delete mode 100644 doc/core.graphml create mode 100644 doc/core.md create mode 100644 doc/editor-view.md delete mode 100644 doc/model.graphml delete mode 100644 doc/packages.graphml delete mode 100644 doc/structure_rw.graphml create mode 100644 src/core/JSONSerializable.h create mode 100644 src/core/Validator.h create mode 100644 src/core/YAMLSerializable.h create mode 100644 src/core/model/CombinationField.cpp create mode 100644 src/core/model/CombinationField.h delete mode 100644 src/core/model/DataField.cpp delete mode 100644 src/core/model/DataField.h create mode 100644 src/core/model/ICombinationField.h create mode 100644 src/core/model/ILayerTransitionField.h create mode 100644 src/core/model/IModel.h create mode 100644 src/core/model/IRegexValueField.h create mode 100644 src/core/model/IValidateableValueField.h create mode 100644 src/core/model/IValueField.h create mode 100644 src/core/model/LayerTransitionField.cpp create mode 100644 src/core/model/LayerTransitionField.h delete mode 100644 src/core/model/NextLevelField.cpp delete mode 100644 src/core/model/NextLevelField.h create mode 100644 src/core/model/RegexValueField.cpp create mode 100644 src/core/model/RegexValueField.h create mode 100644 src/core/model/ValidateableValueField.cpp create mode 100644 src/core/model/ValidateableValueField.h create mode 100644 src/core/model/ValueField.cpp create mode 100644 src/core/model/ValueField.h diff --git a/.gitignore b/.gitignore index 17b492b..191fb12 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ build *.user* doxygen +venv +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e5fa5..a2e4464 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) +set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) + # Find the QtWidgets library find_package(Qt5Widgets) diff --git a/doc/binary_utilisation.graphml b/doc/binary_utilisation.graphml deleted file mode 100644 index b0715cb..0000000 --- a/doc/binary_utilisation.graphml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - ABinaryUtilisationFactory - - - - - - - - - - - - - - - - - - - - - - BinaryUtilisationFactory - - - - - - - - - - - - - - - - - - - - - - ABinaryUtilisation - - - - - - - - - +utilse(byte[]) -+getOptions():string (yaml?) -+setOptions(string) - - - - - - - - - - - - - - NetworkBinaryUtilisation - - - - - - - - - - - - - - - - - - - - - - SaveFileBinaryUtilisation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/classdiagram.graphml b/doc/classdiagram.graphml deleted file mode 100644 index 605b1f5..0000000 --- a/doc/classdiagram.graphml +++ /dev/null @@ -1,422 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - Editor - - - - - - - - - List of Elements -- EditorPane - - - - - - - - - - - - - Element - - - - - - - - - Layer -- Input -- Name -- Hint -- SyntaxHint - - - - - - - - - - - - - Layer - - - - - - - - - - - - - - - - - - - - - IProtocolReader - - - - - - - - - + getProtocolList() : std::list<string> -+ getProtocol(identifier : string) : ProtocolModel - -+ setSearchPath(path : string) : void -+ refresh() - - - - - - - - - - - - YamlProtocolReader - - - - - - - - - - - - - - - - - - - - - XMLProtocolReader - - - - - - - - - - - - - - - - - - - - - JSONProtocolReader - - - - - - - - - - - - - - - - - - - - - ProtocolModel - - - - - - - - - elements : list<ProtocolElement> - - - - - - - - - - - - - StackModel - - - - - - - - - stack : list<ProtocolModel> - - - - - - - - - - - - - ProtocolElement - - - - - - - - - sizeInBit : int -- name : string -- description : string -- regex : string -- nextLayer : bool - - - - - - - - - - - - - StackManager - - - - - - - - - + getAvailableProtocolNames() : list<name> -+ addProtocolToStack(name) : bool -+ getProtocolModel(name) : ProtocolModel -+ loadProtocols() -+ - - - - - - - - - - - - StackCompiler - - - - - - - - - + compile(model : StackModel) : byte[] -+ compile(pmodel : ProtocolModel) : byte[] - - - - - - - - - - - - - ElementModel - - - - - - - - - title -- regex -- userinput -- group -- group-Color -- tooltip/hints? -- additionalInfo -- - - - - - - - - - - - - - - EditorModel - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/core.graphml b/doc/core.graphml deleted file mode 100644 index b6056ec..0000000 --- a/doc/core.graphml +++ /dev/null @@ -1,683 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - libuv - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IUtiliserPlugin - - - - - - - - - - - - - - - - - - - - - IModelPlugin - - - - - - - - - - - - - - - - - - - - - ABinaryUtilisationFactory - - - - - - - - - - - - - - - - - - - - - ABinaryUtilisation - - - - - - - - - +utilse(byte[]) -+getOptions():string (yaml?) -+setOptions(string) - - - - - - - - - - - - - AFieldFactory - - - - - - - - - + createField() -+ createFieldBinaryInformation() -+ createFieldLogicalInformation() -+ createFieldVisualInformation() -+ createFieldRepresentation() - - - - - - - - - - - - AStructureFactory - - - - - - - - - + createStructure() - - - - - - - - - - - - AModelFactory - - - - - - - - - + createModel() - - - - - - - - - - - - AModel - - - - - - - - - - - - - - - - - - - - - AStructure - - - - - - - - - - - - - - - - - - - - - AField - - - - - - - - - - - - - - - - - - - - - ARepository - - - - - - - - - - - - - - - - - - - - - ARepositoryFactory - - - - - - - - - - - - - - - - - - - - - ISchemaIOPlugin - - - - - - - - - - - - - - - - - - - - - AStructureReader - - - - - - - - - - - - - - - - - - - - - AStructureReaderFactory - - - - - - - - - - - - - - - - - - - - - AStructureWriter - - - - - - - - - - - - - - - - - - - - - AStructureWriterFactory - - - - - - - - - - - - - - - - - - - - - APluginManager - - - - - - - - - - - - - - - - - - - - - UtiliserPluginManager - - - - - - - - - - - - - - - - - - - - - ModelPluginManager - - - - - - - - - - - - - - - - - - - - - SchemaIOPluginManager - - - - - - - - - - - - - - - - - - - - - BinaryPacketComposer - - - - - - - - - - - - - - - - - - - - - - Tree - - - - - - - - - - - - - - - - - - - - - - TreeNode - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/core.md b/doc/core.md new file mode 100644 index 0000000..e11e411 --- /dev/null +++ b/doc/core.md @@ -0,0 +1,99 @@ +# core + +```plantuml + +set namespaceSeparator :: + +namespace core { + class BinaryPacketComposer + class RandomAccessBinary + class Tree + class TreeNode + interface YAMLSerializer { + + string toYAML() + + void fromYAML(string yaml) + } + interface JSONSerializer { + + string toJSON() + + void fromJSON(string json) + } + + namespace control { + class ModelController{ + - Model[] currentModels + } + class RepositoryController + class DataController + class FieldFactory + class ModelFactory + class StructureFactory + } + namespace model { + class Model { + - Structure[] structures + - Tree combinedFields + - RandomAccessBinary data + } + class Generator + class Repository { + - Structure[] availableStructures + } + class Structure{ + - String name + - String description + - Tree fields + } + class Field { + - String name + - String description + } + class ValueField { + - String hexvalue + - uint bitsize + } + class CombinationField { + // - list otherFields + } + class ValidateableValueField { + - Validator validator + } + class RegexValueField { + - String regex + } + class GeneratedField { + - Generator gen + } + class LayerTransitionField { + // placeholder for nesting + // structures inside structures + } + class Validator { + + } + class RegexValidator { + + } + } + + core::Tree *-- core::TreeNode + core::model::Field <|-- core::model::ValueField + core::model::ValueField <|-- core::model::ValidateableValueField + core::model::Field <|-- core::model::CombinationField + core::model::ValidateableValueField <|-- core::model::RegexValueField + core::model::ValidateableValueField <|-- core::model::GeneratedField + core::model::RegexValueField *-- core::model::RegexValidator + core::model::Validator <|-- core::model::RegexValidator + core::model::GeneratedField *-- core::model::Generator + core::model::Field <|-- core::model::LayerTransitionField + core::model::Repository o-- core::model::Structure + core::model::Model o-- core::model::Structure + core::model::Model o-up- core::RandomAccessBinary + core::model::Model <-- core::control::ModelController : controls + core::model::Repository <-- core::control::RepositoryController : controls + core::control::ModelFactory --> core::model::Model : creates + core::control::FieldFactory --> core::model::Field : creates all Variants + core::control::StructureFactory --> core::model::Structure : creates + core::YAMLSerializer <|--- core::model : all classes implement + core::JSONSerializer <|--- core::model : all classes implement +} +``` diff --git a/doc/editor-view.md b/doc/editor-view.md new file mode 100644 index 0000000..f2e48eb --- /dev/null +++ b/doc/editor-view.md @@ -0,0 +1,61 @@ +# Editor View + +```plantuml +@startuml + +set namespaceSeparator :: + +namespace core::model { + class Field { + - String name + - String description + } + + class ValueField { + - String value + - uint bitsize + } + Field <|-- ValueField + + class ValidateableValueField { + - Validator validator + } + ValueField <|-- ValidateableValueField + + class RegexValueField { + - String regex + } + ValidateableValueField <|-- RegexValueField + + class FunctionField { + - Function fnc + } + ValidateableValueField <|-- FunctionField + + class LayerTransitionField { + - Layer nextLayer + } + Field <|-- LayerTransitionField +} +namespace editorview { + class Layer { + - int level + } + + class FieldView { + - Layer layer + - Field field + } + core::model::Field --* FieldView + + core::model::ValueField --* ValueFieldView + FieldView <|-- ValueFieldView + core::model::ValidateableValueField --* ValidateableValueFieldView + ValueFieldView <|-- ValidateableValueFieldView + core::model::ValidateableValueField --* RegexValueFiledView + ValidateableValueFieldView <|-- RegexValueFiledView + core::model::FunctionField --* FunctionFieldView + ValidateableValueFieldView <|-- FunctionFieldView +} +@enduml +``` diff --git a/doc/editor.md b/doc/editor.md index be4dada..4be4402 100644 --- a/doc/editor.md +++ b/doc/editor.md @@ -36,9 +36,10 @@ namespace NPC_core::model { DataField ..> Field : represents the data of > Repository "1" *-- "ALL" Structure Structure "1" *- "*" Field - Model "1" *--- "*" NPC_core::RandomAccessBinary } +NPC_core::control::DataController "1" *-up- "*" NPC_core::RandomAccessBinary + NPC_core::model::Field <.. NPC_editor::StructureField : shows < NPC_core::control::DataController --> NPC_core::model::DataField : controls > diff --git a/doc/model.graphml b/doc/model.graphml deleted file mode 100644 index 12849d6..0000000 --- a/doc/model.graphml +++ /dev/null @@ -1,768 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - Field - - - - - - - - - owningStructure -- binary -- logical -- visual -- representation - - - - - - - - - - - - - Binary - - - - - - - - - - - - - - - - - - - - - Logical - - - - - - - - - - - - - - - - - - - - - Visual - - - - - - - - - - - - - - - - - - - - - Representation - - - - - - - - - - - - - - - - - - - - - Structure - - - - - - - - - name -- description -- fields -- data - + putData(Field*, data) -+ validateData(Field*, data) -+ updateData() -+ ... - - - - - - - - - - - - - AFieldFactory - - - - - - - - - + createField() -+ createFieldBinaryInformation() -+ createFieldLogicalInformation() -+ createFieldVisualInformation() -+ createFieldRepresentation() - - - - - - - - - - - - AStructureFactory - - - - - - - - - + createStructure() - - - - - - - - - - - - StructureFactory - - - - - - - - - - - - - - - - - - - - - FieldFactory - - - - - - - - - - - - - - - - - - - - - RandomAccessBinary - - - - - - - - - binaryData - + setBytes(uint position, std::vector<uint8_t> data) -+ setByte(uint position, uint8_t data) - -+ setBit(uint64_t position, bool value) -+ setBit(uint bytePosition, uint bitPosition, bool value) -+ setBits(uint64_t position, uint bits, uint value) -+ setBits(uint bytePosition, uint bitPosition, uint bits, uint value) - -+ getByte(uint position) -+ getBytes(uint position, uint bytes) - -+ getBit(uint64_t position) -+ getBit(uint bytePosition, uint bitPosition) -+ getBits(uint64_t position, uint bits) -+ getBits(uint bytePosition, uint bitPosition, uint bits) - -+ get_uint32(uint position) -+ get_uint16(uint position) -+ get_uint64(uint position) -+ get_float(uint position) -+ get_double(uint position) - -+ get_string(uint position, uint length) - -+ get_hex_string(uint position, uint length) -+ get_hex_string() - - - - - - - - - - - - Model - - - - - - - - - +getBinary():byte[] -+getStructures():Structure[] -+addStructure() -+remStructure() - - - - - - - - - - - - AModelFactory - - - - - - - - - + createModel() - - - - - - - - - - - - ModelFactory - - - - - - - - - - - - - - - - - - - - - Repository - - - - - - - - - +addStructure() -+remStructure() -+getStructures() - - - - - - - - - - - - - - Contains the known structures. - - - - - - - - - - - - - - - - - AModel - - - - - - - - - - - - - - - - - - - - - AStructure - - - - - - - - - - - - - - - - - - - - - AField - - - - - - - - - - - - - - - - - - - - - ARepository - - - - - - - - - - - - - - - - - - - - - RepositoryFactory - - - - - - - - - - - - - - - - - - - - - ARepositoryFactory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/packages.graphml b/doc/packages.graphml deleted file mode 100644 index fb53361..0000000 --- a/doc/packages.graphml +++ /dev/null @@ -1,484 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - GUI - - - - - - - - - - - - - - - - - - - - - Model - - - - - - - - - - - - - - - - - - - - - ByteDispatcher - - - - - - - - - - - - - - - - - - - - - DefinitionManager - - - - - - - - - - - - - - - - - - - - - ProtocolDefinitions - - - - - - - - - - - - - - - - - - - - - - Workflow - - - - - - - - - - - - - - - - - - load definitions - - - - - - - - - - - - - - - - - - - - - - create binary - - - - - - - - - - - - - - - - - - - - - - save/send - - - - - - - - - - - - - - - - - - - - - - create definition - - - - - - - - - - - - - - - - - - - - - - save definition - - - - - - - - - - - - - - - - - - - - - - read binary - - - - - - - - - - - - - - - - - - - - - - display - - - - - - - - - - - - - - - - - - - - - - code generation - - - - - - - - - - - - - - - - - - - - Reads/Writes - - - - - - - - - - - - - - - - - Generates/Produces - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Displays - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ? - - - - - - - - - - - - - - - - diff --git a/doc/structure_rw.graphml b/doc/structure_rw.graphml deleted file mode 100644 index 2cbd167..0000000 --- a/doc/structure_rw.graphml +++ /dev/null @@ -1,383 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - AStructureReader - - - - - - - - - - - - - - - - - - - - - YAML_StructureReader - - - - - - - - - - - - - - - - - - - - - XML_StructureReader - - - - - - - - - - - - - - - - - - - - - JSON_StructureReader - - - - - - - - - - - - - - - - - - - - - StructureReaderFactory - - - - - - - - - - - - - - - - - - - - - AStructureReaderFactory - - - - - - - - - - - - - - - - - - - - - AStructureWriter - - - - - - - - - - - - - - - - - - - - - YAML_StructureWriter - - - - - - - - - - - - - - - - - - - - - XML_StructureWriter - - - - - - - - - - - - - - - - - - - - - JSON_StructureWriter - - - - - - - - - - - - - - - - - - - - - StructureWriterFactory - - - - - - - - - - - - - - - - - - - - - AStructureWriterFactory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 760aaf0..78911f5 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -7,13 +7,23 @@ set(HEADERS RandomAccessBinary.h # interfaces to model model/IField.h + model/ILayerTransitionField.h model/IStructure.h + model/IModel.h + model/IValueField.h + model/IValidateableValueField.h + model/ICombinationField.h + model/IRegexValueField.h # full model implementations model/Repository.h model/Model.h model/Structure.h model/Field.h - model/DataField.h + model/LayerTransitionField.h + model/ValueField.h + model/ValidateableValueField.h + model/CombinationField.h + model/RegexValueField.h model/Modifier.h # control classes control/ARepositoryFactory.h @@ -21,7 +31,6 @@ set(HEADERS control/AStructureFactory.h control/AModelFactory.h control/ModelController.h - control/DataController.h # schema classes schemaio/AStructureReaderFactory.h schemaio/AStructureWriterFactory.h @@ -38,7 +47,11 @@ set(SOURCES model/Model.cpp model/Structure.cpp model/Field.cpp - model/DataField.cpp + model/ValueField.cpp + model/LayerTransitionField.cpp + model/ValidateableValueField.cpp + model/RegexValueField.cpp + model/CombinationField.cpp model/Modifier.cpp control/ARepositoryFactory.cpp @@ -46,7 +59,6 @@ set(SOURCES control/AStructureFactory.cpp control/AModelFactory.cpp control/ModelController.cpp - control/DataController.cpp schemaio/AStructureReaderFactory.cpp schemaio/AStructureWriterFactory.cpp diff --git a/src/core/JSONSerializable.h b/src/core/JSONSerializable.h new file mode 100644 index 0000000..ae6d7ca --- /dev/null +++ b/src/core/JSONSerializable.h @@ -0,0 +1,14 @@ +#ifndef JSONSERIALIZABLE_H +#define JSONSERIALIZABLE_H +#include + +namespace NPC_core { + + class JSONSerializable { + public: + virtual std::string toJSON() const = 0; + virtual void fromJSON(std::string &json) = 0; + }; +} + +#endif diff --git a/src/core/RandomAccessBinary.cpp b/src/core/RandomAccessBinary.cpp index 27a14c8..ac4e091 100644 --- a/src/core/RandomAccessBinary.cpp +++ b/src/core/RandomAccessBinary.cpp @@ -4,6 +4,7 @@ #include #include #include +namespace NPC_core { RandomAccessBinary::RandomAccessBinary() : RandomAccessBinary(1548) {} @@ -286,3 +287,4 @@ std::__cxx11::string RandomAccessBinary::get_hex_string() } return output.str(); } +} diff --git a/src/core/RandomAccessBinary.h b/src/core/RandomAccessBinary.h index 3eb4cb3..81c0639 100644 --- a/src/core/RandomAccessBinary.h +++ b/src/core/RandomAccessBinary.h @@ -4,6 +4,7 @@ #include #include #include +namespace NPC_core { class RandomAccessBinary { @@ -69,5 +70,5 @@ private: std::unique_ptr> ptr_data; Endianness endianness; }; - +} #endif // RANDOMACCESSBINARY_H diff --git a/src/core/Validator.h b/src/core/Validator.h new file mode 100644 index 0000000..0277728 --- /dev/null +++ b/src/core/Validator.h @@ -0,0 +1,9 @@ +#ifndef VALIDATOR_H +#define VALIDATOR_H + +namespace NPC_core { + class Validator { + }; +} + +#endif diff --git a/src/core/YAMLSerializable.h b/src/core/YAMLSerializable.h new file mode 100644 index 0000000..e009be7 --- /dev/null +++ b/src/core/YAMLSerializable.h @@ -0,0 +1,12 @@ +#ifndef YAMLSERIALIZABLE_H +#define YAMLSERIALIZABLE_H +#include +namespace NPC_core { + + class YAMLSerializable { + public: + virtual std::string toYAML() const = 0; + virtual void fromYAML(std::string &yaml) = 0; + }; +} +#endif diff --git a/src/core/control/AFieldFactory.cpp b/src/core/control/AFieldFactory.cpp index 7871873..e078956 100644 --- a/src/core/control/AFieldFactory.cpp +++ b/src/core/control/AFieldFactory.cpp @@ -10,7 +10,6 @@ std::shared_ptr AFieldFactory::createField(std::string name, std:: { auto f = std::make_shared(); f->setName(name); - f->setParentStructure(parentStructure); return f; } @@ -18,8 +17,6 @@ std::shared_ptr AFieldFactory::createFieldFull(std::string name, s { auto f = std::make_shared(); f->setName(name); - f->setSyntaxes(syntaxes); - f->setParentStructure(parentStructure); return f; } }} diff --git a/src/core/control/DataController.cpp b/src/core/control/DataController.cpp index e526eb5..2492ab9 100644 --- a/src/core/control/DataController.cpp +++ b/src/core/control/DataController.cpp @@ -1,6 +1,13 @@ #include "DataController.h" +using namespace NPC_core::control; + DataController::DataController() { } + +std::shared_ptr DataController::getRAB() const +{ + return rab; +} diff --git a/src/core/control/DataController.h b/src/core/control/DataController.h index e8fe393..2892c93 100644 --- a/src/core/control/DataController.h +++ b/src/core/control/DataController.h @@ -1,6 +1,9 @@ #ifndef DATACONTROLLER_H #define DATACONTROLLER_H +#include "RandomAccessBinary.h" +#include + namespace NPC_core { namespace control { @@ -8,6 +11,11 @@ class DataController { public: DataController(); + + std::shared_ptr getRAB() const; + +private: + std::shared_ptr rab; }; }} #endif // DATACONTROLLER_H diff --git a/src/core/control/ModelController.cpp b/src/core/control/ModelController.cpp index ac5257c..9b4e5fc 100644 --- a/src/core/control/ModelController.cpp +++ b/src/core/control/ModelController.cpp @@ -2,7 +2,7 @@ namespace NPC_core { -namespace Control { +namespace control { ModelController::ModelController() { diff --git a/src/core/control/ModelController.h b/src/core/control/ModelController.h index 16c5ad3..afc5172 100644 --- a/src/core/control/ModelController.h +++ b/src/core/control/ModelController.h @@ -3,7 +3,7 @@ namespace NPC_core { -namespace Control { +namespace control { class ModelController { public: diff --git a/src/core/model/CombinationField.cpp b/src/core/model/CombinationField.cpp new file mode 100644 index 0000000..3accd3d --- /dev/null +++ b/src/core/model/CombinationField.cpp @@ -0,0 +1,11 @@ +#include "CombinationField.h" + +namespace NPC_core { + namespace Model { + CombinationField::CombinationField() { + } + + CombinationField::~CombinationField() { + } + } +} diff --git a/src/core/model/CombinationField.h b/src/core/model/CombinationField.h new file mode 100644 index 0000000..610fe68 --- /dev/null +++ b/src/core/model/CombinationField.h @@ -0,0 +1,16 @@ +#ifndef COMBINATIONFIELD_H +#define COMBINATIONFIELD_H +#include "ICombinationField.h" +#include "ValidateableValueField.h" + +namespace NPC_core { + namespace Model { + class CombinationField : public ICombinationField, public Field { + public: + CombinationField(); + virtual ~CombinationField(); + }; + } +} + +#endif diff --git a/src/core/model/DataField.cpp b/src/core/model/DataField.cpp deleted file mode 100644 index 6451439..0000000 --- a/src/core/model/DataField.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#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 deleted file mode 100644 index f8c5bec..0000000 --- a/src/core/model/DataField.h +++ /dev/null @@ -1,33 +0,0 @@ -#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 7842cf7..0215b40 100644 --- a/src/core/model/Field.cpp +++ b/src/core/model/Field.cpp @@ -4,7 +4,6 @@ namespace NPC_core { namespace Model { Field::Field() { - this->parentStructure = nullptr; } std::string Field::getName() const @@ -17,25 +16,14 @@ void Field::setName(const std::string &value) name = value; } -std::map Field::getSyntaxes() const +std::string Field::getDescription() const { - return syntaxes; + return description; } -void Field::setSyntaxes(const std::map &value) +void Field::setDescription(const std::string &value) { - syntaxes = value; -} - -std::shared_ptr Field::getParentStructure() const -{ - return parentStructure; -} - -void Field::setParentStructure(const std::shared_ptr &value) -{ - parentStructure = value; -} - + description = value; +} } } diff --git a/src/core/model/Field.h b/src/core/model/Field.h index a491fa6..3698e5d 100644 --- a/src/core/model/Field.h +++ b/src/core/model/Field.h @@ -5,14 +5,14 @@ #include #include #include +#include "IField.h" namespace NPC_core { namespace Model { class Structure; -class Field -{ +class Field : public IField { public: Field(); virtual ~Field(){} @@ -20,19 +20,39 @@ public: std::string getName() const; void setName(const std::string &value); - std::map getSyntaxes() const; - void setSyntaxes(const std::map &value); - - std::shared_ptr getParentStructure() const; - void setParentStructure(const std::shared_ptr &value); - -protected: - std::shared_ptr parentStructure; + std::string getDescription() const; + void setDescription(const std::string &value); +private: std::string name; - std::map syntaxes; // example : regex; for validation - std::map options; - bool nextLevel; + std::string description; }; + +// class Field : public IField +// { +// public: +// Field(); +// virtual ~Field(){} +// +// std::string getName() const; +// void setName(const std::string &value); +// +// std::map getSyntaxes() const; +// void setSyntaxes(const std::map &value); +// +// std::shared_ptr getParentStructure() const; +// void setParentStructure(const std::shared_ptr &value); +// +// protected: +// std::shared_ptr parentStructure; +// std::string name; +// std::map syntaxes; // example : regex; for validation +// std::map options; +// bool nextLevel; +// +// // IField interface +// public: +// bool isNextLevel() { return this->nextLevel; } +// }; }} #endif // AFIELD_H diff --git a/src/core/model/ICombinationField.h b/src/core/model/ICombinationField.h new file mode 100644 index 0000000..6adfe98 --- /dev/null +++ b/src/core/model/ICombinationField.h @@ -0,0 +1,13 @@ +#ifndef ICOMBINATIONFIELD_H +#define ICOMBINATIONFIELD_H +#include "IField.h" + +namespace NPC_core { + namespace Model { + class ICombinationField : public IField { + public: + + }; + } +} +#endif diff --git a/src/core/model/IField.h b/src/core/model/IField.h index 61f8a06..f4fd5cf 100644 --- a/src/core/model/IField.h +++ b/src/core/model/IField.h @@ -1,25 +1,27 @@ #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; + public: + virtual std::string getName() const = 0; + virtual std::string getDescription() const = 0; }; + +// 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/ILayerTransitionField.h b/src/core/model/ILayerTransitionField.h new file mode 100644 index 0000000..0e1254e --- /dev/null +++ b/src/core/model/ILayerTransitionField.h @@ -0,0 +1,14 @@ +#ifndef ILAYERTRANSITIONFIELD_H +#define ILAYERTRANSITIONFIELD_H +#include "IField.h" + +namespace NPC_core { + namespace Model { + + class ILayerTransitionField : public IField { + + }; + } +} + +#endif diff --git a/src/core/model/IModel.h b/src/core/model/IModel.h new file mode 100644 index 0000000..b3e68f6 --- /dev/null +++ b/src/core/model/IModel.h @@ -0,0 +1,18 @@ +#ifndef IMODEL_H +#define IMODEL_H +#include "../Tree.h" +#include "Field.h" +#include "../RandomAccessBinary.h" +#include +namespace NPC_core { +namespace Model { +class IModel +{ +public: + virtual Tree getStack() const = 0; + virtual std::list> getStructures() const = 0; + virtual std::string getBinaryInHex() const = 0; +}; +}} + +#endif // IMODEL_H diff --git a/src/core/model/IRegexValueField.h b/src/core/model/IRegexValueField.h new file mode 100644 index 0000000..5d76ba8 --- /dev/null +++ b/src/core/model/IRegexValueField.h @@ -0,0 +1,16 @@ +#ifndef IREGEXVALUEFIELD_H +#define IREGEXVALUEFIELD_H +#include "IValidateableValueField.h" +#include + +namespace NPC_core { + namespace Model { + class IRegexValueField : IValidateableValueField { + public: + // virtual std::string getRegex() const = 0; + + }; + } +} + +#endif diff --git a/src/core/model/IValidateableValueField.h b/src/core/model/IValidateableValueField.h new file mode 100644 index 0000000..8376842 --- /dev/null +++ b/src/core/model/IValidateableValueField.h @@ -0,0 +1,17 @@ +#ifndef IVALIDATEABLEVALUEFIELD_H +#define IVALIDATEABLEVALUEFIELD_H +#include "IValueField.h" +#include "../Validator.h" + +namespace NPC_core { + namespace Model { + class IValidateableValueField : public IValueField { + public: + virtual bool validate() const = 0; + virtual Validator& getValidator() const = 0; + }; + } +} + + +#endif diff --git a/src/core/model/IValueField.h b/src/core/model/IValueField.h new file mode 100644 index 0000000..c0821c8 --- /dev/null +++ b/src/core/model/IValueField.h @@ -0,0 +1,17 @@ +#ifndef IVALUEFIELD_H +#define IVALUEFIELD_H +#include +#include "IField.h" + +namespace NPC_core { +namespace Model { + +class IValueField: public IField { + public: + virtual std::string getValue() const = 0; + virtual uint32_t getBitsize() const = 0; +}; + + +}} +#endif diff --git a/src/core/model/LayerTransitionField.cpp b/src/core/model/LayerTransitionField.cpp new file mode 100644 index 0000000..9e88467 --- /dev/null +++ b/src/core/model/LayerTransitionField.cpp @@ -0,0 +1,10 @@ +#include "LayerTransitionField.h" + +namespace NPC_core { + namespace Model { + LayerTransitionField::LayerTransitionField() : Field() { + } + LayerTransitionField::~LayerTransitionField() { + } + } +} diff --git a/src/core/model/LayerTransitionField.h b/src/core/model/LayerTransitionField.h new file mode 100644 index 0000000..24bb475 --- /dev/null +++ b/src/core/model/LayerTransitionField.h @@ -0,0 +1,16 @@ +#ifndef LAYERTRANSITIONFIELD_H +#define LAYERTRANSITIONFIELD_H +#include "ILayerTransitionField.h" +#include "Field.h" + +namespace NPC_core { + namespace Model { + class LayerTransitionField : public Field, public ILayerTransitionField { + public: + LayerTransitionField(); + virtual ~LayerTransitionField(); + }; + } +} + +#endif diff --git a/src/core/model/Model.cpp b/src/core/model/Model.cpp index 7a3c35c..99c334f 100644 --- a/src/core/model/Model.cpp +++ b/src/core/model/Model.cpp @@ -3,10 +3,10 @@ namespace NPC_core { namespace Model { Model::Model() { - + this->rab = std::make_unique(); } -Tree Model::getStack() const +Tree Model::getStack() const { return stack; } @@ -16,9 +16,8 @@ std::list > Model::getStructures() const return structures; } -std::shared_ptr Model::getRAB() const -{ - return rab; +std::string Model::getBinaryInHex() const { + return this->rab->get_hex_string(); } void Model::update() diff --git a/src/core/model/Model.h b/src/core/model/Model.h index d364485..1bbc343 100644 --- a/src/core/model/Model.h +++ b/src/core/model/Model.h @@ -1,31 +1,30 @@ #ifndef AMODEL_H #define AMODEL_H - +#include #include "../Tree.h" -#include "DataField.h" +#include "Field.h" #include "../RandomAccessBinary.h" +#include "IModel.h" #include namespace NPC_core { namespace Model { -class Model +class Model : public IModel { public: Model(); virtual ~Model(){} - Tree getStack() const; + Tree getStack() const; std::list> getStructures() const; - std::shared_ptr getRAB() const; - + std::string getBinaryInHex() 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; - std::shared_ptr rab; - + Tree stack; + std::unique_ptr rab; std::list> structures; }; }} diff --git a/src/core/model/NextLevelField.cpp b/src/core/model/NextLevelField.cpp deleted file mode 100644 index 6484faa..0000000 --- a/src/core/model/NextLevelField.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#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 deleted file mode 100644 index 1876c5d..0000000 --- a/src/core/model/NextLevelField.h +++ /dev/null @@ -1,24 +0,0 @@ -#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/RegexValueField.cpp b/src/core/model/RegexValueField.cpp new file mode 100644 index 0000000..a96c29a --- /dev/null +++ b/src/core/model/RegexValueField.cpp @@ -0,0 +1,13 @@ +#include "RegexValueField.h" + +namespace NPC_core { + namespace Model { + RegexValueField::RegexValueField() : ValidateableValueField() { + } + + RegexValueField::~RegexValueField() { + } + + + } +} diff --git a/src/core/model/RegexValueField.h b/src/core/model/RegexValueField.h new file mode 100644 index 0000000..4476542 --- /dev/null +++ b/src/core/model/RegexValueField.h @@ -0,0 +1,16 @@ +#ifndef REGEXVALUEFIELD_H +#define REGEXVALUEFIELD_H +#include "ValidateableValueField.h" +#include "IRegexValueField.h" + + +namespace NPC_core { + namespace Model { + class RegexValueField : public ValidateableValueField, public IRegexValueField { + public: + RegexValueField(); + virtual ~RegexValueField(); + }; + } +} +#endif diff --git a/src/core/model/Structure.h b/src/core/model/Structure.h index bfbbe89..90a537a 100644 --- a/src/core/model/Structure.h +++ b/src/core/model/Structure.h @@ -5,13 +5,14 @@ #include #include "Field.h" #include "../Tree.h" +#include "IStructure.h" namespace NPC_core { namespace Model { class Field; -class Structure +class Structure : public IStructure { public: Structure(); diff --git a/src/core/model/ValidateableValueField.cpp b/src/core/model/ValidateableValueField.cpp new file mode 100644 index 0000000..4494b8c --- /dev/null +++ b/src/core/model/ValidateableValueField.cpp @@ -0,0 +1,23 @@ +#include "ValidateableValueField.h" + +namespace NPC_core { + namespace Model { + ValidateableValueField::ValidateableValueField() : ValueField() { + } + + ValidateableValueField::~ValidateableValueField() { + } + + Validator& ValidateableValueField::getValidator() { + return this->validator; + } + + bool ValidateableValueField::validate() { +// return this->validator.validate(); + } + + void ValidateableValueField::setValidator(Validator& value) { + this->validator = value; + } + } +} diff --git a/src/core/model/ValidateableValueField.h b/src/core/model/ValidateableValueField.h new file mode 100644 index 0000000..2ccde73 --- /dev/null +++ b/src/core/model/ValidateableValueField.h @@ -0,0 +1,24 @@ +#ifndef VALIDATEABLEVALUEFIELD_H +#define VALIDATEABLEVALUEFIELD_H +#include "ValueField.h" +#include "IValidateableValueField.h" +#include "../Validator.h" + +namespace NPC_core { + namespace Model { + class ValidateableValueField : public IValidateableValueField, public ValueField { + public: + ValidateableValueField(); + virtual ~ValidateableValueField(); + bool validate(); + Validator& getValidator(); + + void setValidator(Validator& value); + private: + Validator validator; + + }; + } +} + +#endif diff --git a/src/core/model/ValueField.cpp b/src/core/model/ValueField.cpp new file mode 100644 index 0000000..6874593 --- /dev/null +++ b/src/core/model/ValueField.cpp @@ -0,0 +1,28 @@ +#include "ValueField.h" + +namespace NPC_core { + namespace Model { + + ValueField::ValueField() : Field() { + } + + ValueField::~ValueField() {} + + std::string ValueField::getValue() const { + return this->value; + } + + uint32_t ValueField::getBitsize() const { + return this->bitsize; + } + + void ValueField::setValue(std::string &value) { + this->value = value; + } + + void ValueField::setBitsize(uint32_t &value) { + this->bitsize = value; + } + + } +} diff --git a/src/core/model/ValueField.h b/src/core/model/ValueField.h new file mode 100644 index 0000000..a08bb25 --- /dev/null +++ b/src/core/model/ValueField.h @@ -0,0 +1,25 @@ +#ifndef VALUEFIELD_H +#define VALUEFIELD_H +#include "IValueField.h" +#include "Field.h" + +namespace NPC_core { +namespace Model { + +class ValueField : public IValueField, public Field { + public: + ValueField(); + virtual ~ValueField(); + virtual std::string getValue() const; + virtual uint32_t getBitsize() const; + + void setValue(std::string &value); + void setBitsize(uint32_t &size); + + private: + std::string value; + uint32_t bitsize; +}; +}} +#endif + diff --git a/test/core/test_model.cpp b/test/core/test_model.cpp index f3e3c87..8173f50 100644 --- a/test/core/test_model.cpp +++ b/test/core/test_model.cpp @@ -3,7 +3,6 @@ #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 { diff --git a/test/core/test_rab.cpp b/test/core/test_rab.cpp index 87ddf37..2381ff5 100644 --- a/test/core/test_rab.cpp +++ b/test/core/test_rab.cpp @@ -3,6 +3,7 @@ #include #include "gtest/gtest.h" #include "../src/core/RandomAccessBinary.h" +using namespace NPC_core; class RABTest : public ::testing::Test { protected: