1
//------------------------------------------------------------------------------
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1995, 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
//-----------------------------------------------------------------------------
33
/// (abstract) graph class.
35
/*@Doc: {\large {\bf scope:} diagram} */
42
void AddNode(Node *node);
44
void AddEdge(Edge *edge);
46
void RemoveNode(Node *node) {nodes->remove(node);}
48
void RemoveEdge(Edge *edge) {edges->remove(edge);}
50
bool HasNode(Node *node) {return nodes->find(node) != -1;}
52
bool HasEdge(Edge *edge) {return edges->find(edge) != -1;}
54
void ClearNodes() {nodes->clear();}
56
void ClearEdges() {edges->clear();}
58
/// checks if edge type may connect subject types 1 and 2.
59
bool CheckConnection(int stype1, int stype2, int edgetype);
61
/// checks if there is an edge in the graph that connects s1 and s2.
62
bool IsConnected(Subject *s1, Subject *s2);
64
/// same as above, but edge should also have name n.
65
bool IsConnected(Subject *s1, Subject *s2, const string *n);
67
/// here edge should also be of type t.
68
bool IsConnected(Subject *s1, Subject *s2, int t);
70
/// combination of the two members above.
71
bool IsConnected(Subject *s1, Subject *s2, const string *n, int t);
73
// the "Get" and "Complete" functions return the number of
74
// elements added to the given output list.
76
/// add to l all edges which connect the subjects.
77
int CompleteSubjects(List<Subject *> *l);
79
/// add to l all edges of which subject s is part.
80
int CompleteSubject(List<Subject *> *l, Subject *s);
82
/// add to l all edges which connect subjects s1 and s2.
83
int CompleteSubject(List<Subject *> *l, Subject *s1, Subject *s2);
85
/// add to l all subjects which are connected by edges already in l.
86
int CompleteEdges(List<Subject *> *l);
88
/// add to l the subjects that are directly connected to subject s.
89
int GetConnected(List<Subject *> *l, Subject *s);
91
/// add to l all nodes in the graph.
92
int GetNodes(List<Subject *> *l);
94
/// add to l all nodes of type t in the graph.
95
int GetNodes(List<Subject *> *l, int t);
97
/// add to l all nodes having name n in the graph.
98
int GetNodes(List<Subject *> *l, const string *n);
100
/// combination of two above members.
101
int GetNodes(List<Subject *> *l, const string *n, int t);
103
/// add to l all edges in the graph.
104
int GetEdges(List<Subject *> *l);
106
/// add to l all edges of type t in the graph.
107
int GetEdges(List<Subject *> *l, int t);
109
/// add to l all edges having name n in the graph.
110
int GetEdges(List<Subject *> *l, const string *n);
112
/// combination of two above members.
113
int GetEdges(List<Subject *> *l, const string *n, int t);
115
/// add to l all edges departing from subject s in the graph.
116
int GetEdgesFrom(List<Subject *> *l, Subject *s);
118
/// add to l all edges of type t departing from subject s.
119
int GetEdgesFrom(List<Subject *> *l, Subject *s, int t);
121
/// add to l all edges having name n departing from subject s.
122
int GetEdgesFrom(List<Subject *> *l, Subject *s, const string *n);
124
/// combination of two above members.
125
int GetEdgesFrom(List<Subject *> *l, Subject *s, const string *n, int t);
127
/// add to l all edges going to subject s.
128
int GetEdgesTo(List<Subject *> *l, Subject *s);
130
/// add to l all edges of type t going to subject s.
131
int GetEdgesTo(List<Subject *> *l, Subject *s, int t);
133
/// add to l all edges having name n going to subject s.
134
int GetEdgesTo(List<Subject *> *l, Subject *s, const string *n);
136
/// combination of the two above members.
137
int GetEdgesTo(List<Subject *> *l, Subject *s, const string *n, int t);
139
/// add to l all edges between subjects from and to
140
int GetEdges(List<Subject *> *l, Subject *from, Subject *to);
142
/// add to l all edges of type t between subjects from and to
143
int GetEdges(List<Subject *> *l, Subject *from, Subject *to, int t);
145
/// combination of the two above members.
146
int GetEdges(List<Subject *> *l, Subject *from, Subject *to, const string *n);
148
/// combination of two above members.
149
int GetEdges(List<Subject *> *l, Subject *from, Subject *to, const string *n, int t);
151
/// return number of nodes in the graph
154
/// return number of nodes of type t in the graph
155
int CountNodes(int t);
157
/// return number of nodes having name n in the graph
158
int CountNodes(const string *n);
160
/// return nr. of nodes of type t, having name n in the graph
161
int CountNodes(const string *n, int t);
163
/// return number of edges in the graph
166
/// return number of edges of type t in the graph
167
int CountEdges(int t);
169
/// return number of edges having name n in the graph
170
int CountEdges(const string *n);
172
/// return nr. of edges of type t, having name n in the graph
173
int CountEdges(const string *n, int t);
175
/// return nr. of edges departing from subject s
176
int CountEdgesFrom(Subject *s);
178
/// return nr. of edges of type t departing from subject s
179
int CountEdgesFrom(Subject *s, int t);
181
/// return number of edges having name n departing from subject s
182
int CountEdgesFrom(Subject *s, const string *n);
184
/// return number of edges of type t, having name n, departing from subject s
185
int CountEdgesFrom(Subject *s, const string *n, int t);
187
/// return nr. of edges going to subject s
188
int CountEdgesTo(Subject *s);
190
/// return nr. of edges of type t going to subject s
191
int CountEdgesTo(Subject *s, int t);
193
/// return number of edges having name n going to subject s
194
int CountEdgesTo(Subject *s, const string *n);
196
/// return number of edges of type t, having name n going to subject s
197
int CountEdgesTo(Subject *s, const string *n, int t);
199
/// return number of edges between subjects s1 and s2
200
int CountEdges(Subject *s1, Subject *s2);
202
/// return number of edges of type t between subjects s1 and s2
203
int CountEdges(Subject *s1, Subject *s2, int t);
205
/// return number of edges having name n between subjects s1 and s2
206
int CountEdges(Subject *s1, Subject *s2, const string *n);
208
/// return number of edges of type t, having name n between subjects s1 and s2
209
int CountEdges(Subject *s1, Subject *s2, const string *n, int t);
212
/// returns if there is some connected path of graph edges from s1 to s2.
213
bool PathExists(Subject *s1, Subject *s2);
215
/// returns if there is some conn. path of graph edges of type t from s1 to s2.
216
bool PathExists(Subject *s1, Subject *s2, int t);
218
// returns list of edges visited. takes edge direction into account.
219
// not implemented due to different implementation method
220
// by David Jansen <dnjansen@cs.utwente.nl>
221
// bool PathExists(Subject *s1, Subject *s2, List<Edge *> *path);
223
/// return if there's path from s1 to s2. irregardless edge direction.
224
bool UndirectedPathExists(Subject *s1, Subject *s2);
226
/// Writes all nodes and edges to outputfile f.
227
void WriteSubjects(OutputFile *f);
229
/// initializes the table containing all allowed connections.
230
virtual void InitConnections()=0;
232
/// some counter can be used
233
void SetCounter(int n) {counter = n;}
235
int GetCounter() {return counter;}
237
/// some string can be used as index prefix.
238
void SetIndexPrefix(const char *s) {indexPrefix = s;}
240
void SetIndexPrefix(const string *s) {indexPrefix = *s;}
242
const string *GetIndexPrefix() const {return &indexPrefix;}
244
/// index string := prefix + counter.
245
void GetIndex(string *s);
247
/// assign to index a new unique index
248
virtual void GetNextIndex(string *index);
250
/// return number of nodes in the graph having this index.
251
virtual int CountIndexes(const string *index);
254
/// Allowed 'connected' types in graph (depends on type of editor).
257
/// Allowed edges type in graph (depends on type of editor).
260
/// Max. number of different connected types and edge types.
263
/// matrix to store what types can be connected by what edge types.
264
int connections[MAX_TYPES][MAX_TYPES][MAX_TYPES];
272
// bool PathExists(Subject *s1, Subject *s2, List<Edge *> *path,
273
// int edgetype, bool Directed);
274
/// used by other PathExists.
275
bool PathExists(Subject *s1, Subject *s2,
276
int edgetype, bool Directed);
278
/// return number of nodes in l having this index
279
int CountIndex(const string *index, List<Subject *> *l);
282
/// current index prefix