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 --- 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 +++++++ 13 files changed, 128 insertions(+), 364 deletions(-) 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 (limited to 'src/diagram') 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); +} + -- cgit v1.2.1