From 685a6974896255bf35b339545cf6d5798b322030 Mon Sep 17 00:00:00 2001 From: nasiCurious Date: Tue, 11 Oct 2022 10:07:45 +0330 Subject: [PATCH] comman detector --- CommandDetector.pro | 7 + CommandDetector.pro.user | 335 ++++++++++++++++++++++++++++++ logic/include/CommandDecoder.h | 18 ++ logic/include/CommandsType.h | 37 ++++ logic/logic.pro | 32 +++ logic/src/CommandDecoder.cpp | 55 +++++ test/include/CommandDecoderTest.h | 25 +++ test/src/CommandDecoderTest.cpp | 54 +++++ test/src/main.cpp | 10 + test/test.pro | 19 ++ 10 files changed, 592 insertions(+) create mode 100644 CommandDetector.pro create mode 100644 CommandDetector.pro.user create mode 100644 logic/include/CommandDecoder.h create mode 100644 logic/include/CommandsType.h create mode 100644 logic/logic.pro create mode 100644 logic/src/CommandDecoder.cpp create mode 100644 test/include/CommandDecoderTest.h create mode 100644 test/src/CommandDecoderTest.cpp create mode 100644 test/src/main.cpp create mode 100644 test/test.pro diff --git a/CommandDetector.pro b/CommandDetector.pro new file mode 100644 index 0000000..f3c3fe8 --- /dev/null +++ b/CommandDetector.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + logic \ + test + +test.depends += logic diff --git a/CommandDetector.pro.user b/CommandDetector.pro.user new file mode 100644 index 0000000..230aa97 --- /dev/null +++ b/CommandDetector.pro.user @@ -0,0 +1,335 @@ + + + + + + EnvironmentId + {c192e638-4eee-4c29-adef-5cfa3bcff92b} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + false + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.13.1 GCC 64bit + Desktop Qt 5.13.1 GCC 64bit + qt.qt5.5131.gcc_64_kit + 1 + 0 + 0 + + /home/hasis/Desktop/Nastaran/TRAIN/TaskLearning2/build-CommandDetector-Desktop_Qt_5_13_1_GCC_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/hasis/Desktop/Nastaran/TRAIN/TaskLearning2/build-CommandDetector-Desktop_Qt_5_13_1_GCC_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/hasis/Desktop/Nastaran/TRAIN/TaskLearning2/build-CommandDetector-Desktop_Qt_5_13_1_GCC_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + test + + Qt4ProjectManager.Qt4RunConfiguration:/home/hasis/Desktop/Nastaran/TRAIN/TaskLearning2/CommandDetector/test/test.pro + -node 3 -d 5 -g -f 2 + 3768 + false + true + true + false + false + true + + /home/hasis/Desktop/Nastaran/TRAIN/TaskLearning2/build-CommandDetector-Desktop_Qt_5_13_1_GCC_64bit-Release/test + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/logic/include/CommandDecoder.h b/logic/include/CommandDecoder.h new file mode 100644 index 0000000..27aa47b --- /dev/null +++ b/logic/include/CommandDecoder.h @@ -0,0 +1,18 @@ +#ifndef COMMANDDECODER_H +#define COMMANDDECODER_H + +#include +#include "CommandsType.h" + +class CommandDecoder +{ +private: + bool isStartWithDash(char* argv); + +public: + CommandDecoder(); + + QList decodeStrintg(int argc, char* argv[]); +}; + +#endif //COMMANDDECODER_H diff --git a/logic/include/CommandsType.h b/logic/include/CommandsType.h new file mode 100644 index 0000000..7545f6d --- /dev/null +++ b/logic/include/CommandsType.h @@ -0,0 +1,37 @@ +#ifndef COMMANDSTYPE2_H +#define COMMANDSTYPE2_H + +#include +#include + +#include + +struct CommandsType2 +{ + char* command; + char* value; + + bool operator==(const CommandsType2& com) const + { + for(size_t i = 0; i < strlen(com.command); i++) + { + if(com.command[i] != command[i]) + { + return false; + } + } + for(size_t i = 0; i < strlen(com.value); i++) + { + if(com.value[i] != value[i]) + { + return false; + } + } + + return true; + } +}; + +Q_DECLARE_METATYPE(CommandsType2); + +#endif //COMMANDSTYPE_H diff --git a/logic/logic.pro b/logic/logic.pro new file mode 100644 index 0000000..9480071 --- /dev/null +++ b/logic/logic.pro @@ -0,0 +1,32 @@ +TEMPLATE = lib + +CONFIG += staticlib +CONFIG += debug +CONFIG += c++11 + +TARGET = logic + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + src/CommandDecoder.cpp + +HEADERS += \ + include/CommandDecoder.h \ + include/CommandsType.h + + +# Default rules for deployment. +unix { + target.path = /usr/lib +} +!isEmpty(target.path): INSTALLS += target diff --git a/logic/src/CommandDecoder.cpp b/logic/src/CommandDecoder.cpp new file mode 100644 index 0000000..28c86a4 --- /dev/null +++ b/logic/src/CommandDecoder.cpp @@ -0,0 +1,55 @@ +#include "../include/CommandDecoder.h" + +QList CommandDecoder::decodeStrintg(int argc, char* argv[]) +{ + if(argc < 2) + { + throw" the usage should lookLike this Sin "; + } + else + { + QList test; + bool checkIsValue; + auto count = argc - 1; + uint8_t j = 1; + checkIsValue = false; + + while(j <= count) + { + auto sample1 = new CommandsType2(); + if(isStartWithDash(argv[j])) + { + sample1->command = argv[j]; + checkIsValue = true; + test.append(*sample1); + } + else + { + if(!checkIsValue) + { + throw" error hasValue "; + } + test.last().value = argv[j]; + checkIsValue = false; + } + + j++; + } + + return test; + } +} + +bool CommandDecoder::isStartWithDash(char* argv) +{ + if('-' == argv[0]) + { + return true; + } + + return false; +} + +CommandDecoder::CommandDecoder() +{ +} diff --git a/test/include/CommandDecoderTest.h b/test/include/CommandDecoderTest.h new file mode 100644 index 0000000..07761da --- /dev/null +++ b/test/include/CommandDecoderTest.h @@ -0,0 +1,25 @@ +#ifndef COMMANDDECODERTEST_H +#define COMMANDDECODERTEST_H + +#include + +#include "CommandsType.h" + +class CommandDecoderTest : public QObject +{ + Q_OBJECT + +private: + QList handiResult(); + +public: + CommandDecoderTest(); + ~CommandDecoderTest(); + +//uncrustify off +private slots: +//uncrustify on + void testDecoder(); +}; + +#endif //COMMANDDECODERTEST_H diff --git a/test/src/CommandDecoderTest.cpp b/test/src/CommandDecoderTest.cpp new file mode 100644 index 0000000..8220ce3 --- /dev/null +++ b/test/src/CommandDecoderTest.cpp @@ -0,0 +1,54 @@ +#include "include/CommandDecoderTest.h" + +#include "CommandDecoder.h" + +QList CommandDecoderTest::handiResult() +{ + QList blist; + auto b1 = new CommandsType2(); + auto b2 = new CommandsType2(); + b1->command = "-node"; + b1->value = "3"; + blist.append(*b1); + b2->command = "-f"; + b2->value = "7"; + blist.append(*b2); + + return blist; +} + +//**************************************************************** +CommandDecoderTest::CommandDecoderTest() +{ +} + +//**************************************************************** +CommandDecoderTest::~CommandDecoderTest() +{ +} + +//**************************************************************** +void CommandDecoderTest::testDecoder() +{ + CommandDecoder comTest; + + char* ptr_array[5]; + char array[5][20] = {{0}}; + strcpy(array[0], "order"); + strcpy(array[1], "-node"); + strcpy(array[2], "3"); + strcpy(array[3], "-f"); + strcpy(array[4], "7"); + for(int i = 0; i < 5; i++) + { + ptr_array[i] = array[i]; + } + + QList c1 = comTest.decodeStrintg(5, ptr_array); + auto c2 = handiResult(); + + //QVERIFY(c1 == c2); + + QCOMPARE(c1, c2); + //QCOMPARE(c, c1); +} diff --git a/test/src/main.cpp b/test/src/main.cpp new file mode 100644 index 0000000..6a67e88 --- /dev/null +++ b/test/src/main.cpp @@ -0,0 +1,10 @@ +#include "include/CommandDecoderTest.h" + +#include + +int main() +{ + QTest::qExec(new CommandDecoderTest); + + return 0; +} diff --git a/test/test.pro b/test/test.pro new file mode 100644 index 0000000..2b6c8bb --- /dev/null +++ b/test/test.pro @@ -0,0 +1,19 @@ +QT += testlib +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += $$files(src/*.cpp, true) + +HEADERS += $$files(include/*.h, true) + + +unix:!macx: LIBS += -L$$OUT_PWD/../logic/ -llogic + +INCLUDEPATH += $$PWD/../logic/include +DEPENDPATH += $$PWD/../logic/include + +unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../logic/liblogic.a