1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1996, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
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.
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.
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
21
////////////////////////////////////////////////////////////////////////////////
22
#include "transition.h"
24
#include "inputfile.h"
25
#include "outputfile.h"
26
#include "stringlist.h"
29
Transition::Transition(STGraph *g, Subject *n1, Subject *n2): Edge(g, n1, n2) {
32
actions = new List<string *>;
35
Transition::Transition(const Transition &t): Edge(t) {
37
actions = new List<string *>;
38
for (t.actions->first(); !t.actions->done(); t.actions->next()) {
39
string *a = t.actions->cur();
40
string *b = new string (*a);
45
Transition::~Transition() {
50
Subject::NameErrType Transition::SetName(const string *) {
51
error("transition label can't be edited\n");
52
return Subject::WRONG_NAME;
55
Subject::NameErrType Transition::SetEvent(const string *s) {
56
if (*s != "" && s->letters() == 0)
57
return Subject::IMPOSSIBLE_NAME;
58
// Check for double event strings between same pair of nodes.
59
List<Subject *> edges;
60
if (*s != "" && *s != event) {
61
GetGraph()->GetEdges(&edges, GetSubject1(),
62
GetSubject2(), Code::TRANSITION);
63
for (edges.first(); !edges.done(); edges.next()) {
64
Transition *t = (Transition *)edges.cur();
65
if (t != this && *t->GetEvent() == *s)
66
return Subject::DOUBLE_EDGE;
73
Subject::NameErrType Transition::SetAction(const string *s, unsigned n, bool update) {
74
if (*s != "" && s->letters() == 0)
75
return Subject::IMPOSSIBLE_NAME;
76
// Check for double actions.
78
if (n >= actions->count() || *(*actions)[n] != *s || !update)
79
return Subject::HAS_ACTION;
81
StringList::Insert(actions, s, n, update);
85
const string *Transition::GetAction(unsigned n) {
86
if (n < actions->count()) {
92
bool Transition::HasAction(const string *s) {
93
for (actions->first(); !actions->done(); actions->next()) {
94
string *at = actions->cur();
101
void Transition::WriteMembers(OutputFile *ofile) {
102
Edge::WriteMembers(ofile);
103
(*ofile) << "\t{ Event " << '"' << event << '"' << " }\n";
105
unsigned num = actions->count();
106
(*ofile) << "\t{ Actions " << num << " }\n";
107
for (unsigned i=0; i<num; i++)
108
(*ofile) << "\t{ Action " << '"'
109
<< *(*actions)[i] << '"' << " }\n";
112
bool Transition::ReadMembers(InputFile *ifile, double format) {
113
if (!Edge::ReadMembers(ifile, format))
115
if (!ifile->ReadStringAttribute("Event", &event))
118
if (!ifile->ReadAttribute("Actions", &val))
120
unsigned numItems = val.toint();
121
for (unsigned i=0; i<numItems; i++) {
122
string *a = new string;
123
if (!ifile->ReadStringAttribute("Action", a)) {