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 /src/diagram | |
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 'src/diagram')
-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 |
9 files changed, 128 insertions, 123 deletions
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_ */ |