~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/sd/fv/dataprocess.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 1996, 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 "dataprocess.h"
 
23
#include "inputfile.h"
 
24
#include "outputfile.h"
 
25
#include "dfgraph.h"
 
26
#include "util.h"
 
27
 
 
28
DataProcess::DataProcess(DFGraph *g): DFProcess(g) {
 
29
        minispec = "";
 
30
        instantaneous = True;
 
31
        activationMechanism = UNSPECIFIED;
 
32
        timeExpression = "";
 
33
        processGroup = False;
 
34
        stimulus = "";
 
35
}
 
36
 
 
37
bool DataProcess::SetReferences(AssocList *al) {
 
38
        return DFNode::SetReferences(al);
 
39
}
 
40
 
 
41
void DataProcess::SetProcessGroup(bool b) {
 
42
        processGroup = b;
 
43
        if (b) {
 
44
                instantaneous = True;
 
45
                minispec = "";
 
46
                activationMechanism = UNSPECIFIED;
 
47
                stimulus = "";
 
48
                timeExpression = "";
 
49
        }
 
50
}
 
51
 
 
52
void DataProcess::SetInstantaneous(bool b) {
 
53
        if (check(!processGroup))
 
54
                instantaneous = b;
 
55
        if (!instantaneous) {
 
56
                activationMechanism = UNSPECIFIED;
 
57
                stimulus = "";
 
58
                timeExpression = "";
 
59
        }
 
60
}
 
61
 
 
62
void DataProcess::SetMinispec(const string *s) {
 
63
        if (check(!processGroup))
 
64
                minispec = *s;
 
65
        else
 
66
                minispec = "";
 
67
}
 
68
 
 
69
void DataProcess::SetActivationMechanism(ActivationType a) {
 
70
        if (check(!processGroup && instantaneous))
 
71
                activationMechanism = a;
 
72
        else
 
73
                activationMechanism = UNSPECIFIED;
 
74
        if (activationMechanism != TIME)
 
75
                timeExpression = "";
 
76
        if (activationMechanism != STIMULUS)
 
77
                stimulus = "";
 
78
}
 
79
 
 
80
void DataProcess::SetStimulus(const string *s) {
 
81
        if (check(activationMechanism == STIMULUS))
 
82
                stimulus = *s;
 
83
        else
 
84
                stimulus = "";
 
85
}
 
86
 
 
87
void DataProcess::SetTimeExpression(const string *s) {
 
88
        if (check(activationMechanism == TIME))
 
89
                timeExpression = *s;
 
90
        else
 
91
                timeExpression = "";
 
92
}
 
93
 
 
94
void DataProcess::WriteMembers(OutputFile *ofile) {
 
95
        DFProcess::WriteMembers(ofile);
 
96
        (*ofile) << "\t{ ProcessGroup " << (processGroup?"True":"False") << " }\n";
 
97
        if (!processGroup) {
 
98
                (*ofile) << "\t{ Persistence " <<
 
99
                          (instantaneous?"Instantaneous":"Continuing") << " }\n";
 
100
                (*ofile) << "\t{ Minispec " << '"' << minispec << '"' << " }\n";
 
101
                if (instantaneous) {
 
102
                        string nm;
 
103
                        ActivationType2String(activationMechanism, &nm);
 
104
                        (*ofile) << "\t{ ActivationMechanism " << nm << " }\n";
 
105
                        if (activationMechanism == STIMULUS) {
 
106
                                (*ofile) << "\t{ Stimulus " << '"' <<
 
107
                                        stimulus << '"' << " }\n";
 
108
                        }
 
109
                        else if (activationMechanism == TIME) {
 
110
                                (*ofile) << "\t{ TimeExpression " << '"' << timeExpression 
 
111
                                         << '"' << " }\n";
 
112
                        }
 
113
                }
 
114
        }
 
115
}
 
116
 
 
117
bool DataProcess::ReadMembers(InputFile *ifile, double format) {
 
118
        if (!DFProcess::ReadMembers(ifile, format))
 
119
                return False;
 
120
        if (format >= 1.13) {
 
121
                string val;
 
122
                if (!ifile->ReadAttribute("ProcessGroup", &val))
 
123
                        return False;
 
124
                processGroup = (val %= "True");
 
125
                if (!processGroup) {
 
126
                        // it's a data process.
 
127
                        if (!ifile->ReadAttribute("Persistence", &val))
 
128
                                return False;
 
129
                        instantaneous = (val %= "Instantaneous");
 
130
                        if (!ifile->ReadStringAttribute("Minispec", &minispec))
 
131
                                return False;
 
132
                        if (instantaneous) {
 
133
                                if (!ifile->ReadAttribute("ActivationMechanism", &val))
 
134
                                        return False;
 
135
                                activationMechanism = String2ActivationType(&val);
 
136
                                if (activationMechanism == STIMULUS) {
 
137
                                        if (!ifile->ReadStringAttribute("Stimulus", &stimulus))
 
138
                                                return False;
 
139
                                }
 
140
                                else if (activationMechanism == TIME) {
 
141
                                        if (!ifile->ReadStringAttribute("TimeExpression", 
 
142
                                                                        &timeExpression))
 
143
                                                return False;
 
144
                                }
 
145
                        }
 
146
                }
 
147
        }
 
148
        return True;
 
149
}
 
150
 
 
151
void DataProcess::ActivationType2String(DataProcess::ActivationType tp, string *nm) {
 
152
        if (tp == UNSPECIFIED)
 
153
                *nm = "Unspecified";
 
154
        else if (tp == TRIGGER)
 
155
                *nm = "Trigger";
 
156
        else if (tp == STIMULUS)
 
157
                *nm = "Stimulus";
 
158
        else if (tp == TIME)
 
159
                *nm = "Time";
 
160
        else {
 
161
                error("%s, line %d: unknown activation mechanism\n",
 
162
                                __FILE__, __LINE__);
 
163
                *nm = "Unspecified";
 
164
        }
 
165
}
 
166
 
 
167
DataProcess::ActivationType DataProcess::String2ActivationType(const string *nm) {
 
168
        if (*nm == "Unspecified")
 
169
                return UNSPECIFIED;
 
170
        else if (*nm == "Trigger")
 
171
                return TRIGGER;
 
172
        else if (*nm == "Stimulus")
 
173
                return STIMULUS;
 
174
        else if (*nm == "Time")
 
175
                return TIME;
 
176
        else {
 
177
                error("%s, line %d: unknown activation mechanism\n", __FILE__, __LINE__);
 
178
                return UNSPECIFIED;
 
179
        }
 
180
}