aboutsummaryrefslogtreecommitdiffstats
path: root/src/diagram/Statement.hpp
blob: ab8c5b7d2dc9f8f3d557920561e2a52e4bb5273a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Statement.h
 *
 *  Created on: Nov 23, 2017
 *      Author: naopross
 */

#ifndef SRC_DIAGRAM_STATEMENT_H_
#define SRC_DIAGRAM_STATEMENT_H_

#include <string>
#include <memory>

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<Statement>;

    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_ */