From 7ea534dd1c8bf72200a999cae554d842d9035ba9 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 1 Jan 2018 18:44:35 +0100 Subject: New StatementDialog, rename diagram classes Other changes: - Use raw pointer instead of smart pointers to manage resources - Initial Painter implementation --- include/diagram/branch.h | 32 ++++++++++++++++++++++++++++++++ include/diagram/branchstatement.h | 32 -------------------------------- include/diagram/iterator.h | 30 ++++++++++++++++++++++++++++++ include/diagram/iteratorstatement.h | 30 ------------------------------ include/diagram/scope.h | 11 ++++++++--- include/diagram/statement.h | 6 +++++- 6 files changed, 75 insertions(+), 66 deletions(-) create mode 100644 include/diagram/branch.h delete mode 100644 include/diagram/branchstatement.h create mode 100644 include/diagram/iterator.h delete mode 100644 include/diagram/iteratorstatement.h (limited to 'include/diagram') diff --git a/include/diagram/branch.h b/include/diagram/branch.h new file mode 100644 index 0000000..2024d78 --- /dev/null +++ b/include/diagram/branch.h @@ -0,0 +1,32 @@ +#ifndef DIAGRAM_BRANCHSTATEMENT_H +#define DIAGRAM_BRANCHSTATEMENT_H + +#include "diagram/statement.h" + +#include +#include + +namespace samb { + +/* Implementation for Statement::DECISION, Statement::SWITCH + */ +class Branch : public Statement +{ +public: + Branch(Type t, const QString &condition, pointer next); + + /* accessors */ + std::map& branches() { return _branches; } + std::size_t branchesCount() 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.h b/include/diagram/branchstatement.h deleted file mode 100644 index 3d8c385..0000000 --- a/include/diagram/branchstatement.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef DIAGRAM_BRANCHSTATEMENT_H -#define DIAGRAM_BRANCHSTATEMENT_H - -#include "diagram/statement.h" - -#include -#include - -namespace samb { - -/* Implementation for Statement::DECISION, Statement::SWITCH - */ -class BranchStatement : public Statement -{ -public: - BranchStatement(Type t, const QString &condition, pointer next); - - /* accessors */ - std::map& branches() { 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/iterator.h b/include/diagram/iterator.h new file mode 100644 index 0000000..71c6a34 --- /dev/null +++ b/include/diagram/iterator.h @@ -0,0 +1,30 @@ +#ifndef DIAGRAM_ITERATORSTATEMENT_H +#define DIAGRAM_ITERATORSTATEMENT_H + +#include "diagram/statement.h" +#include "diagram/scope.h" + +#include + +namespace samb { + +/* Implementation for Statement::WHILE Statement::UNTIL + */ +class Iterator : public Statement +{ +public: + Iterator(Type t, const QString &condition, pointer next); + + /* accessors */ + Scope& inner() { 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.h b/include/diagram/iteratorstatement.h deleted file mode 100644 index e7fbba0..0000000 --- a/include/diagram/iteratorstatement.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef DIAGRAM_ITERATORSTATEMENT_H -#define DIAGRAM_ITERATORSTATEMENT_H - -#include "diagram/statement.h" -#include "diagram/scope.h" - -#include - -namespace samb { - -/* Implementation for Statement::WHILE Statement::UNTIL - */ -class IteratorStatement : public Statement -{ -public: - IteratorStatement(Type t, const QString &condition, pointer next); - - /* accessors */ - Scope& inner() { 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/scope.h b/include/diagram/scope.h index 63698dd..8ae7e79 100644 --- a/include/diagram/scope.h +++ b/include/diagram/scope.h @@ -22,6 +22,9 @@ public: explicit iterator(pointer statement); ~iterator(); + bool operator==(const iterator &other) const; + bool operator!=(const iterator &other) const; + iterator& operator++(); iterator& operator++(int); @@ -32,7 +35,7 @@ public: Statement::pointer _current; }; - explicit Scope(const QString &label); + Scope(const QString &label); Scope(const QString &label, Statement::pointer first); virtual ~Scope(); @@ -43,8 +46,10 @@ public: std::size_t size() const { return _size; } /* iterator */ - iterator begin() { return iterator(_head); } - iterator end() { return iterator(_tail); } + iterator begin(); + const iterator begin() const; + iterator end(); + const iterator end() const; private: Statement::pointer _head; diff --git a/include/diagram/statement.h b/include/diagram/statement.h index 5cce908..1d44d6a 100644 --- a/include/diagram/statement.h +++ b/include/diagram/statement.h @@ -26,7 +26,8 @@ namespace samb { class Statement { public: - using pointer = std::shared_ptr; +// using pointer = std::shared_ptr; + using pointer = Statement*; enum Type { PROCESS, @@ -40,6 +41,9 @@ public: const Type type; + template + static pointer make(Type t, Args&& ...args); + Statement(Type t, const QString &text); Statement(Type t, const QString &text, pointer next); virtual ~Statement(); -- cgit v1.2.1