diff options
author | Nao Pross <naopross@thearcway.org> | 2017-12-18 00:00:21 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2017-12-18 00:00:21 +0100 |
commit | 2e27a93e3ed189b4d96ec7df6e05b102dd2e841a (patch) | |
tree | 6952edd5db3b4075532c4ce75bda764d5a67051b | |
parent | Update .gitignore and minor changes (mostly formatting) (diff) | |
download | OrbitingYeti-2e27a93e3ed189b4d96ec7df6e05b102dd2e841a.tar.gz OrbitingYeti-2e27a93e3ed189b4d96ec7df6e05b102dd2e841a.zip |
Replace tabs with spaces, set up CMake build system
Other changes:
- update gitignore
- build scripts under `etc`
- fix window
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 43 | ||||
-rw-r--r-- | CMakeLists.txt | 48 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rwxr-xr-x | etc/linux-build.sh | 5 | ||||
-rwxr-xr-x | etc/linux-clean-tree.sh | 31 | ||||
-rwxr-xr-x | etc/linux-release-build.sh | 5 | ||||
-rw-r--r-- | etc/windows-build.bat | 5 | ||||
-rw-r--r-- | src/diagram/BranchStatement.cpp | 18 | ||||
-rw-r--r-- | src/diagram/BranchStatement.hpp | 16 | ||||
-rw-r--r-- | src/diagram/IteratorStatement.cpp | 20 | ||||
-rw-r--r-- | src/diagram/IteratorStatement.hpp | 12 | ||||
-rw-r--r-- | src/diagram/Scope.cpp | 80 | ||||
-rw-r--r-- | src/diagram/Scope.hpp | 48 | ||||
-rw-r--r-- | src/diagram/Statement.cpp | 7 | ||||
-rw-r--r-- | src/diagram/Statement.hpp | 48 | ||||
-rw-r--r-- | src/diagram/Structogram.hpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 12 | ||||
-rw-r--r-- | src/ui/Window.cpp | 20 | ||||
-rw-r--r-- | src/ui/Window.hpp | 6 |
19 files changed, 286 insertions, 147 deletions
@@ -1,9 +1,44 @@ +####################################################################### +# EDITORS / IDEs +####################################################################### +# vim +**/*.swp + +# Eclipse Debug Release +.cproject +.project +.settings + +# VS +**.sln +**.vcxproj +**.filters +**.vs/ +**.vcxproj.user + +# sublime text +*.sublime-workspace +*.sublime-project -# editors +####################################################################### +# BUILD SYSTEM +####################################################################### +# binary +OrbitingYeti +OrbitingYeti.exe -**/*.sublime-workspace -**/*.sublime-project +build -**/*.swp
\ No newline at end of file +# cmake +**/makefile +**/Makefile +**/CMakeFiles +**/CmakeScripts +**/CMakeCache.txt +**/Testing +**/install_manifest.txt +**/cmake_install.cmake +**/compile_commands.json +**/CTestTestfile.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2a32638 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,48 @@ +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) @@ -1,8 +1,7 @@ # OrbitingYeti: a tool to write Nassi-Schneidermann diagrams - ## TO DO list / Roadmap -[ ] Structogram data structure -[ ] GUI with Qt4 / Qt5 -[ ] PDF Generator
\ No newline at end of file +- [ ] Structogram data structure +- [ ] GUI with Qt5 +- [ ] PDF Generator diff --git a/etc/linux-build.sh b/etc/linux-build.sh new file mode 100755 index 0000000..a7b08ae --- /dev/null +++ b/etc/linux-build.sh @@ -0,0 +1,5 @@ +#!/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 new file mode 100755 index 0000000..80a858c --- /dev/null +++ b/etc/linux-clean-tree.sh @@ -0,0 +1,31 @@ +#!/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 new file mode 100755 index 0000000..1f0dd08 --- /dev/null +++ b/etc/linux-release-build.sh @@ -0,0 +1,5 @@ +#!/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 new file mode 100644 index 0000000..5d57706 --- /dev/null +++ b/etc/windows-build.bat @@ -0,0 +1,5 @@ +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/src/diagram/BranchStatement.cpp b/src/diagram/BranchStatement.cpp index d960ef9..6345c1b 100644 --- a/src/diagram/BranchStatement.cpp +++ b/src/diagram/BranchStatement.cpp @@ -7,17 +7,15 @@ #include "BranchStatement.hpp" -namespace samb { +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; + 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"); - } + default: + throw std::invalid_argument("BranchStatement can only be of type DECISION or SWITCH"); + } } - -} /* namespace samb */ diff --git a/src/diagram/BranchStatement.hpp b/src/diagram/BranchStatement.hpp index 1f07e5a..b7cc495 100644 --- a/src/diagram/BranchStatement.hpp +++ b/src/diagram/BranchStatement.hpp @@ -16,18 +16,18 @@ namespace samb { class BranchStatement: public Statement { public: - BranchStatement(Type t, const std::string& condition, pointer next); + BranchStatement(Type t, const std::string& condition, pointer next); - /* accessors */ - const std::map<std::string, pointer>& branches() const { return m_branches; } - std::size_t branchesCount() const { return m_branchesCount; } + /* accessors */ + const std::map<std::string, pointer>& 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); } + inline const std::string& condition() const { return text(); } + inline void condition(const std::string& condition) { return text(condition); } private: - std::map<std::string, pointer> m_branches; - std::size_t m_branchesCount = 0; + std::map<std::string, pointer> m_branches; + std::size_t m_branchesCount = 0; }; } /* namespace samb */ diff --git a/src/diagram/IteratorStatement.cpp b/src/diagram/IteratorStatement.cpp index efb5236..02a7318 100644 --- a/src/diagram/IteratorStatement.cpp +++ b/src/diagram/IteratorStatement.cpp @@ -7,19 +7,17 @@ #include "IteratorStatement.hpp" -namespace samb { +using namespace samb; IteratorStatement::IteratorStatement(Statement::Type t, const std::string& condition, Statement::pointer next) - : Statement(t, condition, next), m_inner("") { + : Statement(t, condition, next), m_inner("") { - switch (t) { - case Statement::Type::WHILE: - case Statement::Type::UNTIL: - break; + 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"); - } + default: + throw std::invalid_argument("IteratorStatement can only be of type WHILE or UNTIL"); + } } - -} /* namespace samb */ diff --git a/src/diagram/IteratorStatement.hpp b/src/diagram/IteratorStatement.hpp index 82a40d9..a14d78d 100644 --- a/src/diagram/IteratorStatement.hpp +++ b/src/diagram/IteratorStatement.hpp @@ -15,16 +15,16 @@ namespace samb { class IteratorStatement: public Statement { public: - IteratorStatement(Type t, const std::string& condition, pointer next); + IteratorStatement(Type t, const std::string& condition, pointer next); - /* accessors */ - const Scope& inner() const { return m_inner; } + /* 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); } + inline const std::string& condition() const { return text(); } + inline void condition(const std::string& condition) { return text(condition); } private: - Scope m_inner; + Scope m_inner; }; } /* namespace samb */ diff --git a/src/diagram/Scope.cpp b/src/diagram/Scope.cpp index 335cd20..721ee4b 100644 --- a/src/diagram/Scope.cpp +++ b/src/diagram/Scope.cpp @@ -5,73 +5,83 @@ #include "Scope.hpp" -namespace samb { +using namespace samb; /* Scope::iterator */ -Scope::iterator::iterator(Statement::pointer statement): m_current(statement) {} -Scope::iterator::~iterator() {} +Scope::iterator::iterator(Statement::pointer statement): m_current(statement) { + +} + +Scope::iterator::~iterator() { + +} Scope::iterator& Scope::iterator::operator++() { - if (m_current->next() == nullptr) { - // TODO: remote throw - throw std::logic_error("Statement::iterator::operator++() m_current->next() is nullptr"); - } + 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(); + m_current = m_current->next(); - return *this; + return *this; } Scope::iterator& Scope::iterator::operator++(int) { - static Scope::iterator old(*this); + static Scope::iterator old(*this); - old = *this; - operator++(); - return old; + 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"); - } + if (m_current == nullptr) { + throw std::logic_error("Statement::iterator::operator*() m_current is nullptr"); + } - return *m_current; + return *m_current; } Statement::pointer Scope::iterator::operator->() const { - return m_current; + 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(std::string label): Statement(Statement::Type::SCOPE, label, nullptr), m_head(nullptr), m_tail(nullptr) { + +} -Scope::~Scope() {} +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"); - } + if (statement == nullptr) { + throw std::invalid_argument("Statement::insert_after() cannot insert nullptr"); + } - statement->next(it->next()); - it->next(statement); + statement->next(it->next()); + it->next(statement); - m_size++; + m_size++; - return it; + return it; } Scope::iterator Scope::erase_after(Scope::iterator it) { - if (it->next() == nullptr) { - return end(); - } + if (it->next() == nullptr) { + return end(); + } - it->next(it->next()->next()); + it->next(it->next()->next()); - return it; + return it; } - -} /* namespace samb */ diff --git a/src/diagram/Scope.hpp b/src/diagram/Scope.hpp index b1fe2f0..bf85759 100644 --- a/src/diagram/Scope.hpp +++ b/src/diagram/Scope.hpp @@ -19,39 +19,39 @@ namespace samb { */ class Scope : public Statement { public: - class iterator { - public: - iterator(pointer statement); - ~iterator(); + class iterator { + public: + explicit iterator(pointer statement); + ~iterator(); - iterator& operator++(); - iterator& operator++(int); + iterator& operator++(); + iterator& operator++(int); - Statement& operator*() const; - Statement::pointer operator->() const; + Statement& operator*() const; + Statement::pointer operator->() const; - private: - Statement::pointer m_current; - }; + private: + Statement::pointer m_current; + }; - Scope(std::string label); - Scope(std::string label, Statement::pointer first); - ~Scope(); + 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); + iterator insert_after(iterator it, Statement::pointer statement); + iterator erase_after(iterator it); - /* accessors */ - std::size_t size() const { return m_size; } + /* accessors */ + std::size_t size() const { return m_size; } - /* iterator */ - iterator begin() { return iterator(m_head); } - iterator end() { return iterator(m_tail); } + /* 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; + Statement::pointer m_head; + Statement::pointer m_tail; + std::size_t m_size = 0; }; } /* namespace samb */ diff --git a/src/diagram/Statement.cpp b/src/diagram/Statement.cpp index dc4bfb7..711bcf4 100644 --- a/src/diagram/Statement.cpp +++ b/src/diagram/Statement.cpp @@ -7,7 +7,7 @@ #include "Statement.hpp" -namespace samb { +using namespace samb; /* Statement */ @@ -17,8 +17,7 @@ Statement::Statement(Type t, const std::string& text, Statement::pointer p): typ Statement::~Statement() {} bool Statement::operator==(const Statement& other) const { - // comparison by pointers - return (this == &other); + // comparison by pointers + return (this == &other); } -} /* namespace samb */ diff --git a/src/diagram/Statement.hpp b/src/diagram/Statement.hpp index 0c769ba..ab8c5b7 100644 --- a/src/diagram/Statement.hpp +++ b/src/diagram/Statement.hpp @@ -19,8 +19,8 @@ namespace samb { * 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 : repeat first loop - * UNTIL : repeat last loop + * WHILE : check first loop + * UNTIL : check last loop * PARALLEL : parallel operations */ @@ -30,36 +30,36 @@ namespace samb { */ class Statement { public: - using pointer = std::shared_ptr<Statement>; + using pointer = std::shared_ptr<Statement>; - enum Type { - PROCESS, - SCOPE, - DECISION, - SWITCH, - WHILE, - UNTIL, - PARALLEL, - }; + enum Type { + PROCESS, + SCOPE, + DECISION, + SWITCH, + WHILE, + UNTIL, + PARALLEL, + }; - const Type type; + const Type type; - Statement(Type t, const std::string& text); - Statement(Type t, const std::string& text, pointer next); - virtual ~Statement(); + Statement(Type t, const std::string& text); + Statement(Type t, const std::string& text, pointer next); + virtual ~Statement(); - bool operator==(const Statement& other) const; + bool operator==(const Statement& other) const; - /* accessors */ - void next(pointer next) { m_next = next; } - pointer next() const { return m_next; } + /* 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; } + 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; + std::string m_text; + pointer m_next; }; } /* namespace samb */ diff --git a/src/diagram/Structogram.hpp b/src/diagram/Structogram.hpp index 05c2d4d..84a4b84 100644 --- a/src/diagram/Structogram.hpp +++ b/src/diagram/Structogram.hpp @@ -11,7 +11,7 @@ #include "Scope.hpp" namespace samb { - typedef Scope Structogram; + typedef Scope Structogram; } #endif /* SRC_DIAGRAM_STRUCTOGRAM_HPP_ */ diff --git a/src/main.cpp b/src/main.cpp index 83bba4c..b4a143b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,24 @@ #include "diagram/Structogram.hpp" +#include "ui/Window.hpp" #include <iostream> #include <memory> +#include <QApplication> + using namespace samb; int main(int argc, char *argv[]) { - Structogram st("Example"); + QApplication app(argc, argv); + + Window window; + window.show(); + + Structogram st("Example"); - return 0; + return app.exec(); } diff --git a/src/ui/Window.cpp b/src/ui/Window.cpp index e3d5b52..7f28ffe 100644 --- a/src/ui/Window.cpp +++ b/src/ui/Window.cpp @@ -12,24 +12,22 @@ #include <QApplication> -namespace samb { +using namespace samb; Window::Window(QWidget *parent): QWidget(parent) { - setWindowTitle("OrbitingYeti"); + setWindowTitle("OrbitingYeti"); - QVBoxLayout *vBox = new QVBoxLayout(this); - QHBoxLayout *hBox = new QHBoxLayout(); + QVBoxLayout *vBox = new QVBoxLayout(this); + QHBoxLayout *hBox = new QHBoxLayout(); - m_quitBtn = new QPushButton("Quit", this); - connect(m_quitBtn, SIGNAL(clicked()), qApp, SLOT(quit())); + 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); + hBox->addWidget(m_quitBtn, 0, Qt::AlignRight); + vBox->addStretch(1); + vBox->addLayout(hBox); } Window::~Window() { } - -} /* namespace samb */ diff --git a/src/ui/Window.hpp b/src/ui/Window.hpp index 9b04ebb..9f48f12 100644 --- a/src/ui/Window.hpp +++ b/src/ui/Window.hpp @@ -16,11 +16,11 @@ namespace samb { class Window : public QWidget { Q_OBJECT public: - explicit Window(QWidget *parent = 0); - ~Window(); + explicit Window(QWidget *parent = 0); + ~Window(); private: - QPushButton *m_quitBtn; + QPushButton *m_quitBtn; }; } /* namespace samb */ |