From 62bd9aa4da85ef87c4d9a9bb7911f8a4e0ac9986 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 18 Dec 2017 23:01:33 +0100 Subject: Moved to QtCreator project with QMake --- CMakeLists.txt | 48 ----- OrbitingYeti.pro | 44 +++++ OrbitingYeti.pro.user | 336 ++++++++++++++++++++++++++++++++++ etc/linux-build.sh | 5 - etc/linux-clean-tree.sh | 31 ---- etc/linux-release-build.sh | 5 - etc/windows-build.bat | 5 - forms/mainwindow.ui | 277 ++++++++++++++++++++++++++++ include/diagram/branchstatement.hpp | 35 ++++ include/diagram/iteratorstatement.hpp | 32 ++++ include/diagram/scope.hpp | 59 ++++++ include/diagram/statement.hpp | 67 +++++++ include/diagram/structogram.hpp | 17 ++ include/ui/mainwindow.h | 22 +++ res/mainwindow.ui | 277 ---------------------------- src/diagram/BranchStatement.cpp | 21 --- src/diagram/BranchStatement.hpp | 35 ---- src/diagram/IteratorStatement.cpp | 23 --- src/diagram/IteratorStatement.hpp | 32 ---- src/diagram/Scope.cpp | 87 --------- src/diagram/Scope.hpp | 59 ------ src/diagram/Statement.cpp | 23 --- src/diagram/Statement.hpp | 67 ------- src/diagram/Structogram.hpp | 17 -- src/diagram/branchstatement.cpp | 14 ++ src/diagram/iteratorstatement.cpp | 16 ++ src/diagram/scope.cpp | 82 +++++++++ src/diagram/statement.cpp | 16 ++ src/main.cpp | 28 +-- src/ui/Window.cpp | 33 ---- src/ui/Window.hpp | 28 --- src/ui/mainwindow.cpp | 14 ++ 32 files changed, 1038 insertions(+), 817 deletions(-) delete mode 100644 CMakeLists.txt create mode 100644 OrbitingYeti.pro create mode 100644 OrbitingYeti.pro.user delete mode 100755 etc/linux-build.sh delete mode 100755 etc/linux-clean-tree.sh delete mode 100755 etc/linux-release-build.sh delete mode 100644 etc/windows-build.bat create mode 100644 forms/mainwindow.ui create mode 100644 include/diagram/branchstatement.hpp create mode 100644 include/diagram/iteratorstatement.hpp create mode 100644 include/diagram/scope.hpp create mode 100644 include/diagram/statement.hpp create mode 100644 include/diagram/structogram.hpp create mode 100644 include/ui/mainwindow.h delete mode 100644 res/mainwindow.ui delete mode 100644 src/diagram/BranchStatement.cpp delete mode 100644 src/diagram/BranchStatement.hpp delete mode 100644 src/diagram/IteratorStatement.cpp delete mode 100644 src/diagram/IteratorStatement.hpp delete mode 100644 src/diagram/Scope.cpp delete mode 100644 src/diagram/Scope.hpp delete mode 100644 src/diagram/Statement.cpp delete mode 100644 src/diagram/Statement.hpp delete mode 100644 src/diagram/Structogram.hpp create mode 100644 src/diagram/branchstatement.cpp create mode 100644 src/diagram/iteratorstatement.cpp create mode 100644 src/diagram/scope.cpp create mode 100644 src/diagram/statement.cpp delete mode 100644 src/ui/Window.cpp delete mode 100644 src/ui/Window.hpp create mode 100644 src/ui/mainwindow.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 2a32638..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -cmake_minimum_required(VERSION 3.7) - -####################################################################### -# B-Circuit -project(OrbitingYeti) - -## Version -set(OrbitingYeti_VERSION_MAJOR 0) -set(OrbitingYeti_VERSION_MINOR 1) - -## Libraries - -# qt5 - -# Tell CMake to run moc when necessary: -set(CMAKE_AUTOMOC ON) -# As moc files are generated in the binary dir, tell CMake -# to always look for includes there: -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -find_package(Qt5Core REQUIRED) -find_package(Qt5Widgets REQUIRED) - -add_definitions(${Qt5Core_DEFINITIONS}) -add_definitions(${Qt5Widgets_DEFINITIONS}) - -include_directories(${Qt5core_INCLUDES}) -include_directories(${Qt5Widgets_INCLUDES}) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") - -## Compiler -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -Werror") - -## Source code -include_directories(${CMAKE_SOURCE_DIR}/inc) -file(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR} "src/*.cpp") - -## Executable -add_executable(OrbitingYeti ${SOURCES}) -target_link_libraries(OrbitingYeti Qt5::Core Qt5::Widgets) - -## Toolchain -# enable useful output for linters -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/OrbitingYeti.pro b/OrbitingYeti.pro new file mode 100644 index 0000000..6067137 --- /dev/null +++ b/OrbitingYeti.pro @@ -0,0 +1,44 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-12-18T22:36:52 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = OrbitingYeti +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as 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 you use 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 + +INCLUDEPATH += include + +SOURCES += \ + src/main.cpp \ + src/ui/mainwindow.cpp \ + src/diagram/branchstatement.cpp \ + src/diagram/iteratorstatement.cpp \ + src/diagram/scope.cpp \ + src/diagram/statement.cpp \ + +HEADERS += \ + include/ui/mainwindow.h \ + include/diagram/branchstatement.hpp \ + include/diagram/iteratorstatement.hpp \ + include/diagram/scope.hpp \ + include/diagram/statement.hpp \ + include/diagram/structogram.hpp + +FORMS += \ + forms/mainwindow.ui diff --git a/OrbitingYeti.pro.user b/OrbitingYeti.pro.user new file mode 100644 index 0000000..bc37fea --- /dev/null +++ b/OrbitingYeti.pro.user @@ -0,0 +1,336 @@ + + + + + + EnvironmentId + {421296f8-de97-4da3-8d90-fc6d8f409aba} + + + 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 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {50507059-f35a-45a5-9e10-bd5fe65048d4} + 0 + 0 + 0 + + /home/naopross/docs/projects/build-OrbitingYeti-Desktop-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/naopross/docs/projects/build-OrbitingYeti-Desktop-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/naopross/docs/projects/build-OrbitingYeti-Desktop-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + OrbitingYeti + + Qt4ProjectManager.Qt4RunConfiguration:/home/naopross/docs/projects/OrbitingYeti/OrbitingYeti.pro + true + + OrbitingYeti.pro + false + + /home/naopross/docs/projects/build-OrbitingYeti-Desktop-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/etc/linux-build.sh b/etc/linux-build.sh deleted file mode 100755 index a7b08ae..0000000 --- a/etc/linux-build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -mkdir -p build/debug -cmake -DCMAKE_BUILD_TYPE=Debug -H. -Bbuild/debug -cmake --build build/debug -- clean all diff --git a/etc/linux-clean-tree.sh b/etc/linux-clean-tree.sh deleted file mode 100755 index 80a858c..0000000 --- a/etc/linux-clean-tree.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# WARNING: -# -# this script will delete *everything* that is not -# under version control -# - -POSITIONAL=() -CLEAN_ALL=false - -while [[ $# -gt 0 ]]; do - key="$1" - - case $key in - -a|--all) - CLEAN_ALL=true - shift - ;; - *) - POSITIONAL+=("$1") - shift - ;; - esac -done - -if [ "$CLEAN_ALL" = true ]; then - git clean -d -x -f -else - git clean -d -X -f -fi diff --git a/etc/linux-release-build.sh b/etc/linux-release-build.sh deleted file mode 100755 index 1f0dd08..0000000 --- a/etc/linux-release-build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -mkdir -p build/release -cmake -DCMAKE_BUILD_TYPE=Release -H. -Bbuild/release -cmake --build build/release -- clean all diff --git a/etc/windows-build.bat b/etc/windows-build.bat deleted file mode 100644 index 5d57706..0000000 --- a/etc/windows-build.bat +++ /dev/null @@ -1,5 +0,0 @@ -cd .. -mkdir build/debug -cmake -DCMAKE_BUILD_TYPE=Debug -H. -G "MinGW Makefiles" -Bbuild/debug -cmake --build build/debug -- clean all -pause diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui new file mode 100644 index 0000000..a41e446 --- /dev/null +++ b/forms/mainwindow.ui @@ -0,0 +1,277 @@ + + + MainWindow + + + + 0 + 0 + 824 + 601 + + + + MainWindow + + + Qt::ToolButtonIconOnly + + + + true + + + + 0 + 0 + + + + + 824 + 548 + + + + Qt::LeftToRight + + + + + + QLayout::SetMaximumSize + + + + + + + New Diagram + + + + + + + + + + Open + + + + + + + + + + Save + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + Refresh View + + + + + + + + + + New Statement + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + 0 + 824 + 28 + + + + + File + + + + Export + + + + + + + + + + + + + + + + Edit + + + + + + + About + + + + + + + Style + + + + + + + + + + + + Quit + + + Ctrl+Q + + + + + OrbitingYeti + + + + + NS Diagrams + + + + + New + + + Ctrl+N + + + + + Save + + + Ctrl+S + + + + + Open + + + Ctrl+O + + + + + Open Recent + + + + + PDF + + + + + LaTeX TikZ + + + + + Copy + + + Ctrl+C + + + + + Paste + + + Ctrl+V + + + + + Save As + + + Ctrl+Shift+S + + + + + Font + + + + + Settings + + + + + + diff --git a/include/diagram/branchstatement.hpp b/include/diagram/branchstatement.hpp new file mode 100644 index 0000000..b7cc495 --- /dev/null +++ b/include/diagram/branchstatement.hpp @@ -0,0 +1,35 @@ +/* + * BranchStatement.hpp + * + * Created on: Nov 28, 2017 + * Author: naopross + */ + +#ifndef SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ +#define SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ + +#include "Statement.hpp" + +#include + +namespace samb { + +class BranchStatement: public Statement { +public: + BranchStatement(Type t, const std::string& condition, pointer next); + + /* accessors */ + const std::map& branches() const { return m_branches; } + std::size_t branchesCount() const { return m_branchesCount; } + + inline const std::string& condition() const { return text(); } + inline void condition(const std::string& condition) { return text(condition); } + +private: + std::map m_branches; + std::size_t m_branchesCount = 0; +}; + +} /* namespace samb */ + +#endif /* SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ */ diff --git a/include/diagram/iteratorstatement.hpp b/include/diagram/iteratorstatement.hpp new file mode 100644 index 0000000..a14d78d --- /dev/null +++ b/include/diagram/iteratorstatement.hpp @@ -0,0 +1,32 @@ +/* + * IteratorStatement.hpp + * + * Created on: Nov 28, 2017 + * Author: naopross + */ + +#ifndef SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ +#define SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ + +#include "Statement.hpp" +#include "Scope.hpp" + +namespace samb { + +class IteratorStatement: public Statement { +public: + IteratorStatement(Type t, const std::string& condition, pointer next); + + /* accessors */ + const Scope& inner() const { return m_inner; } + + inline const std::string& condition() const { return text(); } + inline void condition(const std::string& condition) { return text(condition); } + +private: + Scope m_inner; +}; + +} /* namespace samb */ + +#endif /* SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ */ diff --git a/include/diagram/scope.hpp b/include/diagram/scope.hpp new file mode 100644 index 0000000..bf85759 --- /dev/null +++ b/include/diagram/scope.hpp @@ -0,0 +1,59 @@ +/* + * Created on: Nov 28, 2017 + * Author: naopross + */ + +#ifndef SRC_DIAGRAM_SCOPE_HPP_ +#define SRC_DIAGRAM_SCOPE_HPP_ + +#include "Statement.hpp" + +namespace samb { + +/* The Scope is a forward-iterable object that contains statements. + * A scope is also a valid type of statement. + * + * The Scope object is used inside other complex types of statements such as + * BranchStatement or a IteratorStatement, to hold the statements within their + * scope. + */ +class Scope : public Statement { +public: + class iterator { + public: + explicit iterator(pointer statement); + ~iterator(); + + iterator& operator++(); + iterator& operator++(int); + + Statement& operator*() const; + Statement::pointer operator->() const; + + private: + Statement::pointer m_current; + }; + + explicit Scope(std::string label); + Scope(std::string label, Statement::pointer first); + ~Scope(); + + iterator insert_after(iterator it, Statement::pointer statement); + iterator erase_after(iterator it); + + /* accessors */ + std::size_t size() const { return m_size; } + + /* iterator */ + iterator begin() { return iterator(m_head); } + iterator end() { return iterator(m_tail); } + +private: + Statement::pointer m_head; + Statement::pointer m_tail; + std::size_t m_size = 0; +}; + +} /* namespace samb */ + +#endif /* SRC_DIAGRAM_SCOPE_HPP_ */ diff --git a/include/diagram/statement.hpp b/include/diagram/statement.hpp new file mode 100644 index 0000000..ab8c5b7 --- /dev/null +++ b/include/diagram/statement.hpp @@ -0,0 +1,67 @@ +/* + * Statement.h + * + * Created on: Nov 23, 2017 + * Author: naopross + */ + +#ifndef SRC_DIAGRAM_STATEMENT_H_ +#define SRC_DIAGRAM_STATEMENT_H_ + +#include +#include + +namespace samb { + +/* Possible types of statement, according to the NS diagram paper + * + * PROCESS : a statement that does something + * SCOPE : simple scope to isolate variables + * DECISION : splits the program in 2 branches based on a condition + * SWITCH : splits the program in n branches depending on a value + * WHILE : check first loop + * UNTIL : check last loop + * PARALLEL : parallel operations + */ + +/* This struct is a statement (link) of the iterable object Scope + * (linked list), that is also a common interface for the various types of + * statements. + */ +class Statement { +public: + using pointer = std::shared_ptr; + + enum Type { + PROCESS, + SCOPE, + DECISION, + SWITCH, + WHILE, + UNTIL, + PARALLEL, + }; + + const Type type; + + Statement(Type t, const std::string& text); + Statement(Type t, const std::string& text, pointer next); + virtual ~Statement(); + + bool operator==(const Statement& other) const; + + /* accessors */ + void next(pointer next) { m_next = next; } + pointer next() const { return m_next; } + + void text(const std::string& text) { m_text = text; } + const std::string& text() const { return m_text; } + +private: + std::string m_text; + pointer m_next; +}; + +} /* namespace samb */ + +#endif /* SRC_DIAGRAM_STATEMENT_H_ */ diff --git a/include/diagram/structogram.hpp b/include/diagram/structogram.hpp new file mode 100644 index 0000000..84a4b84 --- /dev/null +++ b/include/diagram/structogram.hpp @@ -0,0 +1,17 @@ +/* + * Structogram.hpp + * + * Created on: Nov 28, 2017 + * Author: naopross + */ + +#ifndef SRC_DIAGRAM_STRUCTOGRAM_HPP_ +#define SRC_DIAGRAM_STRUCTOGRAM_HPP_ + +#include "Scope.hpp" + +namespace samb { + typedef Scope Structogram; +} + +#endif /* SRC_DIAGRAM_STRUCTOGRAM_HPP_ */ diff --git a/include/ui/mainwindow.h b/include/ui/mainwindow.h new file mode 100644 index 0000000..a3948a9 --- /dev/null +++ b/include/ui/mainwindow.h @@ -0,0 +1,22 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/res/mainwindow.ui b/res/mainwindow.ui deleted file mode 100644 index a41e446..0000000 --- a/res/mainwindow.ui +++ /dev/null @@ -1,277 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 824 - 601 - - - - MainWindow - - - Qt::ToolButtonIconOnly - - - - true - - - - 0 - 0 - - - - - 824 - 548 - - - - Qt::LeftToRight - - - - - - QLayout::SetMaximumSize - - - - - - - New Diagram - - - - - - - - - - Open - - - - - - - - - - Save - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - - - - Refresh View - - - - - - - - - - New Statement - - - - - - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - 824 - 28 - - - - - File - - - - Export - - - - - - - - - - - - - - - - Edit - - - - - - - About - - - - - - - Style - - - - - - - - - - - - Quit - - - Ctrl+Q - - - - - OrbitingYeti - - - - - NS Diagrams - - - - - New - - - Ctrl+N - - - - - Save - - - Ctrl+S - - - - - Open - - - Ctrl+O - - - - - Open Recent - - - - - PDF - - - - - LaTeX TikZ - - - - - Copy - - - Ctrl+C - - - - - Paste - - - Ctrl+V - - - - - Save As - - - Ctrl+Shift+S - - - - - Font - - - - - Settings - - - - - - diff --git a/src/diagram/BranchStatement.cpp b/src/diagram/BranchStatement.cpp deleted file mode 100644 index 6345c1b..0000000 --- a/src/diagram/BranchStatement.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * BranchStatement.cpp - * - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#include "BranchStatement.hpp" - -using namespace samb; - -BranchStatement::BranchStatement(Type t, const std::string& condition, pointer next): Statement(t, condition, next) { - switch (t) { - case Statement::Type::DECISION: - case Statement::Type::SWITCH: - break; - - default: - throw std::invalid_argument("BranchStatement can only be of type DECISION or SWITCH"); - } -} diff --git a/src/diagram/BranchStatement.hpp b/src/diagram/BranchStatement.hpp deleted file mode 100644 index b7cc495..0000000 --- a/src/diagram/BranchStatement.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * BranchStatement.hpp - * - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ -#define SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ - -#include "Statement.hpp" - -#include - -namespace samb { - -class BranchStatement: public Statement { -public: - BranchStatement(Type t, const std::string& condition, pointer next); - - /* accessors */ - const std::map& branches() const { return m_branches; } - std::size_t branchesCount() const { return m_branchesCount; } - - inline const std::string& condition() const { return text(); } - inline void condition(const std::string& condition) { return text(condition); } - -private: - std::map m_branches; - std::size_t m_branchesCount = 0; -}; - -} /* namespace samb */ - -#endif /* SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ */ diff --git a/src/diagram/IteratorStatement.cpp b/src/diagram/IteratorStatement.cpp deleted file mode 100644 index 02a7318..0000000 --- a/src/diagram/IteratorStatement.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * IteratorStatement.cpp - * - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#include "IteratorStatement.hpp" - -using namespace samb; - -IteratorStatement::IteratorStatement(Statement::Type t, const std::string& condition, Statement::pointer next) - : Statement(t, condition, next), m_inner("") { - - switch (t) { - case Statement::Type::WHILE: - case Statement::Type::UNTIL: - break; - - default: - throw std::invalid_argument("IteratorStatement can only be of type WHILE or UNTIL"); - } -} diff --git a/src/diagram/IteratorStatement.hpp b/src/diagram/IteratorStatement.hpp deleted file mode 100644 index a14d78d..0000000 --- a/src/diagram/IteratorStatement.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * IteratorStatement.hpp - * - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ -#define SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ - -#include "Statement.hpp" -#include "Scope.hpp" - -namespace samb { - -class IteratorStatement: public Statement { -public: - IteratorStatement(Type t, const std::string& condition, pointer next); - - /* accessors */ - const Scope& inner() const { return m_inner; } - - inline const std::string& condition() const { return text(); } - inline void condition(const std::string& condition) { return text(condition); } - -private: - Scope m_inner; -}; - -} /* namespace samb */ - -#endif /* SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ */ diff --git a/src/diagram/Scope.cpp b/src/diagram/Scope.cpp deleted file mode 100644 index 721ee4b..0000000 --- a/src/diagram/Scope.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#include "Scope.hpp" - -using namespace samb; - -/* Scope::iterator */ - -Scope::iterator::iterator(Statement::pointer statement): m_current(statement) { - -} - -Scope::iterator::~iterator() { - -} - -Scope::iterator& Scope::iterator::operator++() { - if (m_current->next() == nullptr) { - // TODO: remove throw - throw std::logic_error("Statement::iterator::operator++() m_current->next() is nullptr"); - } - - m_current = m_current->next(); - - return *this; -} - -Scope::iterator& Scope::iterator::operator++(int) { - static Scope::iterator old(*this); - - old = *this; - operator++(); - return old; -} - -Statement& Scope::iterator::operator*() const { - if (m_current == nullptr) { - throw std::logic_error("Statement::iterator::operator*() m_current is nullptr"); - } - - return *m_current; -} - -Statement::pointer Scope::iterator::operator->() const { - return m_current; -} - - -/* Scope */ - -Scope::Scope(std::string label): Statement(Statement::Type::SCOPE, label, nullptr), m_head(nullptr), m_tail(nullptr) { - -} - -Scope::Scope(std::string label, Statement::pointer first): Statement(Statement::Type::SCOPE, label, first), m_head(first), m_tail(first) { - -} - -Scope::~Scope() { - -} - -Scope::iterator Scope::insert_after(Scope::iterator it, Statement::pointer statement) { - if (statement == nullptr) { - throw std::invalid_argument("Statement::insert_after() cannot insert nullptr"); - } - - statement->next(it->next()); - it->next(statement); - - m_size++; - - return it; -} - -Scope::iterator Scope::erase_after(Scope::iterator it) { - if (it->next() == nullptr) { - return end(); - } - - it->next(it->next()->next()); - - return it; -} diff --git a/src/diagram/Scope.hpp b/src/diagram/Scope.hpp deleted file mode 100644 index bf85759..0000000 --- a/src/diagram/Scope.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_SCOPE_HPP_ -#define SRC_DIAGRAM_SCOPE_HPP_ - -#include "Statement.hpp" - -namespace samb { - -/* The Scope is a forward-iterable object that contains statements. - * A scope is also a valid type of statement. - * - * The Scope object is used inside other complex types of statements such as - * BranchStatement or a IteratorStatement, to hold the statements within their - * scope. - */ -class Scope : public Statement { -public: - class iterator { - public: - explicit iterator(pointer statement); - ~iterator(); - - iterator& operator++(); - iterator& operator++(int); - - Statement& operator*() const; - Statement::pointer operator->() const; - - private: - Statement::pointer m_current; - }; - - explicit Scope(std::string label); - Scope(std::string label, Statement::pointer first); - ~Scope(); - - iterator insert_after(iterator it, Statement::pointer statement); - iterator erase_after(iterator it); - - /* accessors */ - std::size_t size() const { return m_size; } - - /* iterator */ - iterator begin() { return iterator(m_head); } - iterator end() { return iterator(m_tail); } - -private: - Statement::pointer m_head; - Statement::pointer m_tail; - std::size_t m_size = 0; -}; - -} /* namespace samb */ - -#endif /* SRC_DIAGRAM_SCOPE_HPP_ */ diff --git a/src/diagram/Statement.cpp b/src/diagram/Statement.cpp deleted file mode 100644 index 711bcf4..0000000 --- a/src/diagram/Statement.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Statement.cpp - * - * Created on: Nov 23, 2017 - * Author: naopross - */ - -#include "Statement.hpp" - -using namespace samb; - -/* Statement */ - -Statement::Statement(Type t, const std::string& text): type(t), m_text(text), m_next(nullptr) {} -Statement::Statement(Type t, const std::string& text, Statement::pointer p): type(t), m_text(text), m_next(p) {} - -Statement::~Statement() {} - -bool Statement::operator==(const Statement& other) const { - // comparison by pointers - return (this == &other); -} - diff --git a/src/diagram/Statement.hpp b/src/diagram/Statement.hpp deleted file mode 100644 index ab8c5b7..0000000 --- a/src/diagram/Statement.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Statement.h - * - * Created on: Nov 23, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_STATEMENT_H_ -#define SRC_DIAGRAM_STATEMENT_H_ - -#include -#include - -namespace samb { - -/* Possible types of statement, according to the NS diagram paper - * - * PROCESS : a statement that does something - * SCOPE : simple scope to isolate variables - * DECISION : splits the program in 2 branches based on a condition - * SWITCH : splits the program in n branches depending on a value - * WHILE : check first loop - * UNTIL : check last loop - * PARALLEL : parallel operations - */ - -/* This struct is a statement (link) of the iterable object Scope - * (linked list), that is also a common interface for the various types of - * statements. - */ -class Statement { -public: - using pointer = std::shared_ptr; - - enum Type { - PROCESS, - SCOPE, - DECISION, - SWITCH, - WHILE, - UNTIL, - PARALLEL, - }; - - const Type type; - - Statement(Type t, const std::string& text); - Statement(Type t, const std::string& text, pointer next); - virtual ~Statement(); - - bool operator==(const Statement& other) const; - - /* accessors */ - void next(pointer next) { m_next = next; } - pointer next() const { return m_next; } - - void text(const std::string& text) { m_text = text; } - const std::string& text() const { return m_text; } - -private: - std::string m_text; - pointer m_next; -}; - -} /* namespace samb */ - -#endif /* SRC_DIAGRAM_STATEMENT_H_ */ diff --git a/src/diagram/Structogram.hpp b/src/diagram/Structogram.hpp deleted file mode 100644 index 84a4b84..0000000 --- a/src/diagram/Structogram.hpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Structogram.hpp - * - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_STRUCTOGRAM_HPP_ -#define SRC_DIAGRAM_STRUCTOGRAM_HPP_ - -#include "Scope.hpp" - -namespace samb { - typedef Scope Structogram; -} - -#endif /* SRC_DIAGRAM_STRUCTOGRAM_HPP_ */ diff --git a/src/diagram/branchstatement.cpp b/src/diagram/branchstatement.cpp new file mode 100644 index 0000000..2835f35 --- /dev/null +++ b/src/diagram/branchstatement.cpp @@ -0,0 +1,14 @@ +#include "diagram/BranchStatement.hpp" + +using namespace samb; + +BranchStatement::BranchStatement(Type t, const std::string& condition, pointer next): Statement(t, condition, next) { + switch (t) { + case Statement::Type::DECISION: + case Statement::Type::SWITCH: + break; + + default: + throw std::invalid_argument("BranchStatement can only be of type DECISION or SWITCH"); + } +} diff --git a/src/diagram/iteratorstatement.cpp b/src/diagram/iteratorstatement.cpp new file mode 100644 index 0000000..675d8eb --- /dev/null +++ b/src/diagram/iteratorstatement.cpp @@ -0,0 +1,16 @@ +#include "diagram/IteratorStatement.hpp" + +using namespace samb; + +IteratorStatement::IteratorStatement(Statement::Type t, const std::string& condition, Statement::pointer next) + : Statement(t, condition, next), m_inner("") { + + switch (t) { + case Statement::Type::WHILE: + case Statement::Type::UNTIL: + break; + + default: + throw std::invalid_argument("IteratorStatement can only be of type WHILE or UNTIL"); + } +} diff --git a/src/diagram/scope.cpp b/src/diagram/scope.cpp new file mode 100644 index 0000000..a1074a3 --- /dev/null +++ b/src/diagram/scope.cpp @@ -0,0 +1,82 @@ +#include "diagram/Scope.hpp" + +using namespace samb; + +/* Scope::iterator */ + +Scope::iterator::iterator(Statement::pointer statement): m_current(statement) { + +} + +Scope::iterator::~iterator() { + +} + +Scope::iterator& Scope::iterator::operator++() { + if (m_current->next() == nullptr) { + // TODO: remove throw + throw std::logic_error("Statement::iterator::operator++() m_current->next() is nullptr"); + } + + m_current = m_current->next(); + + return *this; +} + +Scope::iterator& Scope::iterator::operator++(int) { + static Scope::iterator old(*this); + + old = *this; + operator++(); + return old; +} + +Statement& Scope::iterator::operator*() const { + if (m_current == nullptr) { + throw std::logic_error("Statement::iterator::operator*() m_current is nullptr"); + } + + return *m_current; +} + +Statement::pointer Scope::iterator::operator->() const { + return m_current; +} + + +/* Scope */ + +Scope::Scope(std::string label): Statement(Statement::Type::SCOPE, label, nullptr), m_head(nullptr), m_tail(nullptr) { + +} + +Scope::Scope(std::string label, Statement::pointer first): Statement(Statement::Type::SCOPE, label, first), m_head(first), m_tail(first) { + +} + +Scope::~Scope() { + +} + +Scope::iterator Scope::insert_after(Scope::iterator it, Statement::pointer statement) { + if (statement == nullptr) { + throw std::invalid_argument("Statement::insert_after() cannot insert nullptr"); + } + + statement->next(it->next()); + it->next(statement); + + m_size++; + + return it; +} + +Scope::iterator Scope::erase_after(Scope::iterator it) { + if (it->next() == nullptr) { + return end(); + } + + it->next(it->next()->next()); + + return it; +} diff --git a/src/diagram/statement.cpp b/src/diagram/statement.cpp new file mode 100644 index 0000000..9cbcdb4 --- /dev/null +++ b/src/diagram/statement.cpp @@ -0,0 +1,16 @@ +#include "diagram/Statement.hpp" + +using namespace samb; + +/* Statement */ + +Statement::Statement(Type t, const std::string& text): type(t), m_text(text), m_next(nullptr) {} +Statement::Statement(Type t, const std::string& text, Statement::pointer p): type(t), m_text(text), m_next(p) {} + +Statement::~Statement() {} + +bool Statement::operator==(const Statement& other) const { + // comparison by pointers + return (this == &other); +} + diff --git a/src/main.cpp b/src/main.cpp index b4a143b..a425e2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,26 +1,12 @@ -#include "diagram/Structogram.hpp" -#include "ui/Window.hpp" - -#include -#include - +#include "ui/mainwindow.h" #include +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); -using namespace samb; - -int main(int argc, char *argv[]) { - - QApplication app(argc, argv); - - Window window; - window.show(); + MainWindow w; + w.show(); - Structogram st("Example"); - - return app.exec(); + return a.exec(); } - - - - diff --git a/src/ui/Window.cpp b/src/ui/Window.cpp deleted file mode 100644 index 7f28ffe..0000000 --- a/src/ui/Window.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Window.cpp - * - * Created on: Nov 26, 2017 - * Author: naopross - */ - -#include "Window.hpp" - -#include -#include -#include - - -using namespace samb; - -Window::Window(QWidget *parent): QWidget(parent) { - setWindowTitle("OrbitingYeti"); - - QVBoxLayout *vBox = new QVBoxLayout(this); - QHBoxLayout *hBox = new QHBoxLayout(); - - m_quitBtn = new QPushButton("Quit", this); - connect(m_quitBtn, SIGNAL(clicked()), qApp, SLOT(quit())); - - hBox->addWidget(m_quitBtn, 0, Qt::AlignRight); - vBox->addStretch(1); - vBox->addLayout(hBox); -} - -Window::~Window() { - -} diff --git a/src/ui/Window.hpp b/src/ui/Window.hpp deleted file mode 100644 index 9f48f12..0000000 --- a/src/ui/Window.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Window.hpp - * - * Created on: Nov 26, 2017 - * Author: naopross - */ - -#ifndef SRC_UI_WINDOW_HPP_ -#define SRC_UI_WINDOW_HPP_ - -#include -#include - -namespace samb { - -class Window : public QWidget { -Q_OBJECT -public: - explicit Window(QWidget *parent = 0); - ~Window(); - -private: - QPushButton *m_quitBtn; -}; - -} /* namespace samb */ - -#endif /* SRC_UI_WINDOW_HPP_ */ diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp new file mode 100644 index 0000000..7e4ca77 --- /dev/null +++ b/src/ui/mainwindow.cpp @@ -0,0 +1,14 @@ +#include "ui/mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} -- cgit v1.2.1