blob: 7f64a0d8e2ded97b18c84a5c66c3cf1fada3c109 (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#include "diagram/scope.h"
#include "debugtools.h"
using namespace samb;
/* Scope::iterator */
Scope::iterator::iterator(Statement::pointer statement) :
_current(statement)
{
if (_current == nullptr) {
debug_err("invalid iterator interating nullptr");
}
}
Scope::iterator::~iterator()
{
}
bool Scope::iterator::operator==(const iterator &other) const
{
return *_current == *other;
}
bool Scope::iterator::operator!=(const iterator &other) const
{
return !(*_current == *other);
}
Scope::iterator& Scope::iterator::operator++()
{
if (_current->next() != nullptr) {
_current = _current->next();
} else {
// throw std::logic_error("Statement::iterator::operator++() m_current->next() is nullptr");
}
return *this;
}
Scope::iterator& Scope::iterator::operator++(int)
{
static Scope::iterator old(*this);
old = *this;
operator++();
return old;
}
Statement& Scope::iterator::operator*() const
{
if (_current == nullptr)
throw std::logic_error("Scope::iterator::operator*() m_current is nullptr");
return *_current;
}
Statement::pointer Scope::iterator::operator->() const
{
return _current;
}
/* Scope */
Scope::Scope(const QString &label) :
Statement(Statement::Type::SCOPE, label, nullptr),
_head(nullptr), _tail(nullptr)
{
_head = _tail = new Statement(Statement::PROCESS, "");
}
Scope::Scope(const QString &label, Statement::pointer first) :
Statement(Statement::Type::SCOPE, label, first),
_head(first), _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");
statement->next(it->next());
it->next(statement);
_size++;
return it;
}
Scope::iterator Scope::erase_after(Scope::iterator it)
{
if (it->next() == nullptr)
return end();
it->next(it->next()->next());
return it;
}
Scope::iterator Scope::begin()
{
return iterator(_head);
}
const Scope::iterator Scope::begin() const
{
return begin();
}
Scope::iterator Scope::end()
{
return iterator(_tail);
}
const Scope::iterator Scope::end() const
{
return end();
}
|