From a7e74749a1c4edb2f8bc34c79e9bd1562de86ee9 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 19 Dec 2017 01:54:28 +0100 Subject: Change to Qt5 conding conventions Data structure changes: - Structogram is no longer just a scope, because it needs to store metadata - All structures now use QString instead of std::string, to integrate better in the Qt framework New code: - MainWindow ui code, building layout - MetadataDialog to change the metadata stored in the Structogram - Painter is a widget (still unimplemented) to show the structogram on the GUI --- include/diagram/branchstatement.h | 30 ++++++++++++++++ include/diagram/branchstatement.hpp | 35 ------------------ include/diagram/iteratorstatement.h | 28 +++++++++++++++ include/diagram/iteratorstatement.hpp | 32 ----------------- include/diagram/scope.h | 57 +++++++++++++++++++++++++++++ include/diagram/scope.hpp | 59 ------------------------------ include/diagram/statement.h | 63 ++++++++++++++++++++++++++++++++ include/diagram/statement.hpp | 67 ----------------------------------- include/diagram/structogram.h | 29 +++++++++++++++ include/diagram/structogram.hpp | 17 --------- 10 files changed, 207 insertions(+), 210 deletions(-) create mode 100644 include/diagram/branchstatement.h delete mode 100644 include/diagram/branchstatement.hpp create mode 100644 include/diagram/iteratorstatement.h delete mode 100644 include/diagram/iteratorstatement.hpp create mode 100644 include/diagram/scope.h delete mode 100644 include/diagram/scope.hpp create mode 100644 include/diagram/statement.h delete mode 100644 include/diagram/statement.hpp create mode 100644 include/diagram/structogram.h delete mode 100644 include/diagram/structogram.hpp (limited to 'include/diagram') diff --git a/include/diagram/branchstatement.h b/include/diagram/branchstatement.h new file mode 100644 index 0000000..6c5e416 --- /dev/null +++ b/include/diagram/branchstatement.h @@ -0,0 +1,30 @@ +#ifndef DIAGRAM_BRANCHSTATEMENT_H +#define DIAGRAM_BRANCHSTATEMENT_H + +#include "diagram/statement.h" + +#include +#include + +namespace samb { + +class BranchStatement : public Statement +{ +public: + BranchStatement(Type t, const QString &condition, pointer next); + + /* accessors */ + const std::map& branches() const { return _branches; } + std::size_t branches_count() const { return _branchesCount; } + + inline const QString& condition() const { return text(); } + inline void condition(const QString &condition) { return text(condition); } + +private: + std::map _branches; + std::size_t _branchesCount = 0; +}; + +} /* namespace samb */ + +#endif /* DIAGRAM_BRANCHSTATEMENT_H */ diff --git a/include/diagram/branchstatement.hpp b/include/diagram/branchstatement.hpp deleted file mode 100644 index b7cc495..0000000 --- a/include/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/include/diagram/iteratorstatement.h b/include/diagram/iteratorstatement.h new file mode 100644 index 0000000..a8f6d59 --- /dev/null +++ b/include/diagram/iteratorstatement.h @@ -0,0 +1,28 @@ +#ifndef DIAGRAM_ITERATORSTATEMENT_H +#define DIAGRAM_ITERATORSTATEMENT_H + +#include "diagram/statement.h" +#include "diagram/scope.h" + +#include + +namespace samb { + +class IteratorStatement : public Statement +{ +public: + IteratorStatement(Type t, const QString &condition, pointer next); + + /* accessors */ + const Scope& inner() const { return _inner; } + + inline const QString& condition() const { return text(); } + inline void condition(const QString &condition) { return text(condition); } + +private: + Scope _inner; +}; + +} /* namespace samb */ + +#endif /* DIAGRAM_ITERATORSTATEMENT_H */ diff --git a/include/diagram/iteratorstatement.hpp b/include/diagram/iteratorstatement.hpp deleted file mode 100644 index a14d78d..0000000 --- a/include/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/include/diagram/scope.h b/include/diagram/scope.h new file mode 100644 index 0000000..63698dd --- /dev/null +++ b/include/diagram/scope.h @@ -0,0 +1,57 @@ +#ifndef DIAGRAM_SCOPE_H +#define DIAGRAM_SCOPE_H + +#include "diagram/statement.h" + +#include + +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 _current; + }; + + explicit Scope(const QString &label); + Scope(const QString &label, Statement::pointer first); + virtual ~Scope(); + + iterator insert_after(iterator it, Statement::pointer statement); + iterator erase_after(iterator it); + + /* accessors */ + std::size_t size() const { return _size; } + + /* iterator */ + iterator begin() { return iterator(_head); } + iterator end() { return iterator(_tail); } + +private: + Statement::pointer _head; + Statement::pointer _tail; + std::size_t _size = 0; +}; + +} /* namespace samb */ + +#endif /* SRC_DIAGRAM_SCOPE_HPP_ */ diff --git a/include/diagram/scope.hpp b/include/diagram/scope.hpp deleted file mode 100644 index bf85759..0000000 --- a/include/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/include/diagram/statement.h b/include/diagram/statement.h new file mode 100644 index 0000000..5cce908 --- /dev/null +++ b/include/diagram/statement.h @@ -0,0 +1,63 @@ +#ifndef DIAGRAM_STATEMENT_H +#define DIAGRAM_STATEMENT_H + +#include +#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 QString &text); + Statement(Type t, const QString &text, pointer next); + virtual ~Statement(); + + bool operator==(const Statement& other) const; + + /* accessors */ + void next(pointer next) { _next = next; } + pointer next() const { return _next; } + + void text(const QString &text) { _text = text; } + const QString& text() const { return _text; } + +private: + QString _text; + pointer _next; +}; + +} /* namespace samb */ + +#endif /* DIAGRAM_STATEMENT_H */ diff --git a/include/diagram/statement.hpp b/include/diagram/statement.hpp deleted file mode 100644 index ab8c5b7..0000000 --- a/include/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/include/diagram/structogram.h b/include/diagram/structogram.h new file mode 100644 index 0000000..6b2e0db --- /dev/null +++ b/include/diagram/structogram.h @@ -0,0 +1,29 @@ +#ifndef DIAGRAM_STRUCTOGRAM_H +#define DIAGRAM_STRUCTOGRAM_H + +#include "diagram/scope.h" + +#include + +namespace samb { + +class Structogram : public Scope +{ +public: + Structogram(const QString &title, const QString &author); + ~Structogram(); + + /* accessors */ + void title(const QString &title) { text(title); } + const QString& title() const { return text(); } + + void author(const QString &author) { _author = author; } + const QString& author() const { return _author; } + +private: + QString _author; +}; + +} + +#endif /* DIAGRAM_STRUCTOGRAM_H */ diff --git a/include/diagram/structogram.hpp b/include/diagram/structogram.hpp deleted file mode 100644 index 84a4b84..0000000 --- a/include/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_ */ -- cgit v1.2.1