From 12e86e71ca36a58d7e2ed64f0454b65ed6f7eb56 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 28 Nov 2017 15:05:02 +0100 Subject: New data structure for Structogram and Statements --- src/diagram/Statement.hpp | 56 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'src/diagram/Statement.hpp') diff --git a/src/diagram/Statement.hpp b/src/diagram/Statement.hpp index 1781a97..4eb3b4d 100644 --- a/src/diagram/Statement.hpp +++ b/src/diagram/Statement.hpp @@ -10,35 +10,28 @@ #include #include +#include +#include namespace samb { - /* Possible types of statement, according to the NS diagram paper * - * PROCESS, - * DECISION, - * SWITCH, - * WHILE, - * UNTIL, - * SCOPE, - * PARALLEL, + * PROCESS : a statement that does something + * 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 + * SCOPE : simple scope to isolate variables + * PARALLEL : parallel operations */ -/* this struct is a link for linked list that stores the data in a tree-like - * structure, BUT it is not a tree because it allows 2 or more nodes to point - * at a single node - * - * Tree: Statements: - * A - B - C - D A - B - C - D - G - * \ \ / - * E - F E - F - * - * Because a statements can be branching elements. (if / switch) - * - * This class is also a *Factory* to make statements. +/* 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. */ -struct Statement { +class Statement { +public: using pointer = std::shared_ptr; enum Type { @@ -56,20 +49,25 @@ struct Statement { * TODO: think of something more elegant to solve this */ END - } type; + }; - std::string text; + const Type type; - pointer next; - pointer scope; // TODO: make iterator aware of scope + Statement(Type type, const std::string& text, pointer next); + virtual ~Statement(); - static Statement::pointer makeStatement(Type t); + bool operator==(const Statement& other) const; - virtual ~Statement(); - bool operator==(const Statement& other); + /* 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: - Statement(Type type, std::string txt, pointer next, pointer scope); + std::string m_text; + pointer m_next; }; } /* namespace samb */ -- cgit v1.2.1