aboutsummaryrefslogtreecommitdiffstats
path: root/include/diagram/scope.h
blob: 63698dd0d788492c4273626c7b703e5ea074e468 (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
#ifndef DIAGRAM_SCOPE_H
#define DIAGRAM_SCOPE_H

#include "diagram/statement.h"

#include <QString>

namespace samb {

/* The Scope is a forward-iterable object that contains statements.
 * A scope is also a valid type of statement.
 *
 * The Scope object is used inside other complex types of statements such as
 * BranchStatement or a IteratorStatement, to hold the statements within their
 * scope.
 */
class Scope : public Statement
{
public:
    class iterator {
    public:
        explicit iterator(pointer statement);
        ~iterator();

        iterator& operator++();
        iterator& operator++(int);

        Statement& operator*() const;
        Statement::pointer operator->() const;

    private:
        Statement::pointer _current;
    };

    explicit Scope(const QString &label);
    Scope(const QString &label, Statement::pointer first);
    virtual ~Scope();

    iterator insert_after(iterator it, Statement::pointer statement);
    iterator erase_after(iterator it);

    /* accessors */
    std::size_t size() const { return _size; }

    /* iterator */
    iterator begin() { return iterator(_head); }
    iterator end() { return iterator(_tail); }

private:
    Statement::pointer _head;
    Statement::pointer _tail;
    std::size_t _size = 0;
};

} /* namespace samb */

#endif /* SRC_DIAGRAM_SCOPE_HPP_ */