~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/sd/bv/stchecks.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
4
// (c) copyright 1997, Vrije Universiteit Amsterdam.
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
//
 
7
// TCM is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// TCM is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with TCM; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "stchecks.h"
 
23
#include "graph.h"
 
24
#include "node.h"
 
25
#include "transition.h"
 
26
#include "diagram.h"
 
27
#include "initialstate.h"
 
28
 
 
29
STChecks::STChecks(Diagram *d, Graph *g): DiagramChecks(d,g) { }
 
30
 
 
31
unsigned STChecks::CheckUnreachableStates(string &chkbuf) {
 
32
        unsigned total = 0;
 
33
        List<Subject *> initStates, States;
 
34
        Subject *initState;
 
35
        GetGraph()->GetNodes(&initStates, Code::INITIAL_STATE);
 
36
        GetGraph()->GetNodes(&States, Code::STATE);
 
37
        GetGraph()->GetNodes(&States, Code::DECISION_POINT);
 
38
        if (initStates.count() == 0)
 
39
                return 0;
 
40
        else
 
41
                initState = initStates[0];
 
42
        for (States.first(); !States.done(); States.next()) {
 
43
                Subject *state = States.cur();
 
44
                if (!GetGraph()->PathExists(initState, state)) {
 
45
                        chkbuf += "* Error: ";
 
46
                        chkbuf += Code::GetName(state->GetClassType());
 
47
                        chkbuf += " '";
 
48
                        chkbuf += *state->GetName();
 
49
                        chkbuf += "' ";
 
50
                        chkbuf += "is not reachable from the initial state\n";
 
51
                        GetDiagram()->SelectSubject(state);
 
52
                        total++;
 
53
                }
 
54
        } 
 
55
        return total;
 
56
}
 
57
 
 
58
unsigned STChecks::CheckNoActions(string &chkbuf) {
 
59
        List<Subject *> transitions;
 
60
        GetGraph()->GetEdges(&transitions, Code::TRANSITION);
 
61
        for (transitions.first(); !transitions.done(); transitions.next()) {
 
62
                Transition *transition = (Transition *)transitions.cur();
 
63
                if (transition->NrActions() > 0)
 
64
                        // ok there is an action in a transition.
 
65
                        return 0;
 
66
        }
 
67
        List<Subject *> initStates;
 
68
        GetGraph()->GetNodes(&initStates, Code::INITIAL_STATE);
 
69
        for (initStates.first(); !initStates.done(); initStates.next()) {
 
70
                InitialState *initState = (InitialState *)initStates.cur();
 
71
                if (initState->NrActions() > 0)
 
72
                        // ok there is an action in an initial state.
 
73
                        return 0;
 
74
        }
 
75
        // there is no action.
 
76
        chkbuf += "* Error: the diagram does not contain any action\n";
 
77
        return 1;
 
78
}
 
79
 
 
80
unsigned STChecks::CheckEmptyActions(string &chkbuf) {
 
81
        unsigned total = 0;
 
82
        List<Subject *> transitions;
 
83
        GetGraph()->GetEdges(&transitions, Code::TRANSITION);
 
84
        for (transitions.first(); !transitions.done(); transitions.next()) {
 
85
                Transition *transition = (Transition *)transitions.cur();
 
86
                // transitions from and to the same node should have
 
87
                // an action.
 
88
                if (transition->GetSubject1() == transition->GetSubject2()) {
 
89
                        if (transition->NrActions() > 0)
 
90
                                continue;
 
91
                        chkbuf += "* Error: the transition from and to ";
 
92
                        Subject *n = transition->GetSubject1();
 
93
                        chkbuf += Code::GetName(n->GetClassType());
 
94
                        chkbuf += " '";
 
95
                        chkbuf += *n->GetName();
 
96
                        chkbuf += "' should have actions\n";
 
97
                        GetDiagram()->SelectSubject(transition);
 
98
                        total++;
 
99
                }
 
100
        }
 
101
        return total;
 
102
}
 
103
 
 
104
unsigned STChecks::CheckEmptyEvents(string &chkbuf) {
 
105
        unsigned total = 0;
 
106
        List<Subject *> transitions;
 
107
        GetGraph()->GetEdges(&transitions, Code::TRANSITION);
 
108
        for (transitions.first(); !transitions.done(); transitions.next()) {
 
109
                Transition *transition = (Transition *)transitions.cur();
 
110
                const string *event = transition->GetEvent();
 
111
                if (*event == "") {
 
112
                        GetDiagram()->SelectSubject(transition);                
 
113
                        total++;
 
114
                }
 
115
        }
 
116
        if (total > 0) {
 
117
                chkbuf += "* Error: there ";
 
118
                if (total == 1)
 
119
                        chkbuf += "is a Transition";
 
120
                else {
 
121
                        chkbuf += "are ";
 
122
                        chkbuf += total;
 
123
                        chkbuf += " Transitions";
 
124
                }
 
125
                chkbuf += " without an event\n";
 
126
        } 
 
127
        return total; 
 
128
}
 
129
 
 
130
unsigned STChecks::CheckDoubleEvents(string &chkbuf) {
 
131
        unsigned total = 0;
 
132
        List<Subject *> transitions;  // all transitions.
 
133
        List<Subject *> transitions2; // transitions between same states.
 
134
        List<Subject *> transitions3; // already checked transitions.
 
135
        GetGraph()->GetEdges(&transitions, Code::TRANSITION);
 
136
        for (transitions.first(); !transitions.done(); transitions.next()) {
 
137
                Transition *transition = (Transition *)transitions.cur();
 
138
                if (transitions3.find(transition) == -1) {
 
139
                        const string *event = transition->GetEvent();
 
140
                        if (*event == "")
 
141
                                continue;
 
142
                        transitions2.empty();
 
143
                        GetGraph()->GetEdges(&transitions2, 
 
144
                                                transition->GetSubject1(), 
 
145
                                                transition->GetSubject2(), 
 
146
                                                Code::TRANSITION);
 
147
                        int card = 0;
 
148
                        for (transitions2.first(); !transitions2.done(); 
 
149
                                        transitions2.next()) {
 
150
                                Transition *transition2 = 
 
151
                                        (Transition *)transitions2.cur();
 
152
                                if (transition2 != transition && 
 
153
                                        *event == *transition2->GetEvent()) {
 
154
                                        transitions3.add(transition2);
 
155
                                        GetDiagram()->SelectSubject(transition);
 
156
                                        GetDiagram()->SelectSubject(transition2);
 
157
                                        card++;
 
158
                                }
 
159
 
 
160
                        }
 
161
                        if (card > 0) {
 
162
                                chkbuf += "* Error: there are ";
 
163
                                chkbuf += card+1;
 
164
                                chkbuf += " transitions between node '";
 
165
                                chkbuf += *transition->GetSubject1()->GetName();
 
166
                                chkbuf += "' and node '";
 
167
                                chkbuf += *transition->GetSubject2()->GetName();
 
168
                                chkbuf += "' having event ";
 
169
                                chkbuf += *event;
 
170
                                chkbuf += " \n";
 
171
                        }
 
172
                }
 
173
                transitions3.add(transition);
 
174
        }
 
175
        return total;
 
176
}