From 7f7e6fe30ef4f9ba4507b89174676f57c42c0000 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 26 Nov 2017 23:36:26 +0100 Subject: Implementation for Structogram iterator and Statement type The interator is not (yet) aware of the scope in which it is iterating. --- src/diagram/Structogram.hpp | 53 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 7 deletions(-) (limited to 'src/diagram/Structogram.hpp') diff --git a/src/diagram/Structogram.hpp b/src/diagram/Structogram.hpp index 2234142..9318ee4 100644 --- a/src/diagram/Structogram.hpp +++ b/src/diagram/Structogram.hpp @@ -10,21 +10,60 @@ #include #include -#include "../diagram/Statement.h" + +#include "Statement.hpp" namespace samb { -/* object that holds statements */ +/* A Structogram is a Nassi-Schneiderman diagram, in this implementation it is + * simply and iterable object that holds statements. + * + * The first statement inside a structogram (m_head) is a SCOPE + * statement that holds the entire program inside it. + */ class Structogram { -private: - std::list m_statements; - std::string m_title; - public: + /* forward only iterator */ + class iterator { + public: + iterator(Statement::pointer first); + ~iterator(); + + iterator& operator++(); + iterator& operator++(int); + + bool operator==(const iterator& other) const; + bool operator!=(const iterator& other) const; + Statement& operator*() const; + Statement::pointer operator->() const; + + private: + Statement::pointer m_current; + }; + Structogram(std::string title); virtual ~Structogram(); - const std::list& getStatements() const; + std::size_t size() const; + + // cannot be implemented because iter is forward only +// iterator insert(iterator it, Statement::pointer statement); +// iterator erase(iterator it); + + iterator insert_after(iterator it, Statement::pointer statement); + iterator erase_after(iterator it); + + /* iterator */ + iterator begin() const; + const iterator end() const; + const Statement& operator[](const Statement& it) = delete; + +private: + std::size_t m_size; + std::string m_title; + + Statement::pointer m_head; + Statement::pointer m_tail; }; } /* namespace structograms */ -- cgit v1.2.1