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 "initialstate.h"
25
#include "stringlist.h"
26
#include "inputfile.h"
27
#include "outputfile.h"
29
InitialState::InitialState(STGraph *g): State(g) {
31
actions = new List<string *>;
34
InitialState::InitialState(const InitialState &s): State(s) {
35
actions = new List<string *>;
36
for (s.actions->first(); !s.actions->done(); s.actions->next()) {
37
string *a = s.actions->cur();
38
string *b = new string(*a);
41
controlProcess = s.controlProcess;
44
InitialState::~InitialState() {
49
Subject::NameErrType InitialState::SetAction(const string *s, unsigned n, bool update) {
50
if (*s != "" && s->letters()==0)
51
return Subject::IMPOSSIBLE_NAME;
52
// Check for double actions.
54
if (n >= actions->count() || *(*actions)[n] != *s || !update)
55
return Subject::HAS_ACTION;
57
StringList::Insert(actions, s, n, update);
61
const string *InitialState::GetAction(unsigned n) {
62
if (n < actions->count())
67
bool InitialState::HasAction(const string *s) {
68
for (actions->first(); !actions->done(); actions->next()) {
69
string *at = actions->cur();
76
bool InitialState::ReadMembers(InputFile *ifile, double format) {
77
if (!State::ReadMembers(ifile, format))
79
// read control process name.
81
if (!ifile->ReadStringAttribute("ControlProcess", &controlProcess))
86
if (!ifile->ReadAttribute("Actions", &val))
88
unsigned numItems = val.toint();
89
for (unsigned i=0; i<numItems; i++) {
90
string *at = new string;
91
if (!ifile->ReadStringAttribute("Action", at)) {
100
void InitialState::WriteMembers(OutputFile *ofile) {
101
State::WriteMembers(ofile);
102
// write name of control process.
103
(*ofile) << "\t{ ControlProcess " << '"' << controlProcess << '"' << " }\n";
105
unsigned numItems = actions->count();
106
(*ofile) << "\t{ Actions " << numItems << " }\n";
107
for (unsigned i=0; i<numItems; i++) {
108
(*ofile) << "\t{ Action " << '"'
109
<< *(*actions)[i] << '"' << " } \n";