1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
3 |
Copyright (C) 2006 Carnegie Mellon University |
4 |
|
5 |
This program is free software; you can redistribute it and/or modify |
6 |
it under the terms of the GNU General Public License as published by |
7 |
the Free Software Foundation; either version 2, or (at your option) |
8 |
any later version. |
9 |
|
10 |
This program is distributed in the hope that it will be useful, |
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
GNU General Public License for more details. |
14 |
|
15 |
You should have received a copy of the GNU General Public License |
16 |
along with this program; if not, write to the Free Software |
17 |
Foundation, Inc., 59 Temple Place - Suite 330, |
18 |
Boston, MA 02111-1307, USA. |
19 |
*//** @file |
20 |
Routines to Process Set Instance Values. |
21 |
|
22 |
This group of routines is used to process the value fields of set |
23 |
instances. |
24 |
|
25 |
Requires: |
26 |
#include <stdio.h> |
27 |
#include "utilities/ascConfig.h" |
28 |
#include "compiler.h" |
29 |
#include "list.h" |
30 |
*//* |
31 |
by Tom Epperly |
32 |
11/16/89 |
33 |
Version: $Revision: 1.7 $ |
34 |
Version control file: $RCSfile: setinstval.h,v $ |
35 |
Date last modified: $Date: 1998/02/05 16:37:52 $ |
36 |
Last modified by: $Author: ballan $ |
37 |
*/ |
38 |
|
39 |
#ifndef ASC_SETINSTVAL_H |
40 |
#define ASC_SETINSTVAL_H |
41 |
|
42 |
/** addtogroup compiler Compiler |
43 |
@{ |
44 |
*/ |
45 |
|
46 |
#include <utilities/ascConfig.h> |
47 |
|
48 |
enum set_kind { |
49 |
integer_set, /**< set of integer values */ |
50 |
string_set, /**< set of string values */ |
51 |
empty_set /**< set with nothing in it */ |
52 |
}; |
53 |
|
54 |
/** Do not confuse this set with the struct Set in types.h */ |
55 |
struct set_t { |
56 |
enum set_kind kind; |
57 |
struct gl_list_t *list; |
58 |
}; |
59 |
|
60 |
extern void InitSetManager(void); |
61 |
/**< |
62 |
* This function initializes the pool. |
63 |
* We pool the set stubs for reuse, since there are so many used in |
64 |
* most ASCEND models of any complexity. |
65 |
* The pool grows as needed. It does not shrink until destroyed. |
66 |
* It is a fatal error to call this a second time unless |
67 |
* DestroySetManager has been called first. |
68 |
* In the pooling operation we only keep the set stubs, not the |
69 |
* gl_lists associated.<br><br> |
70 |
* |
71 |
* This exits if it cannot init the pool because of insufficient |
72 |
* memory. |
73 |
*/ |
74 |
|
75 |
extern void DestroySetManager(void); |
76 |
/**< |
77 |
* Destroys the set pool. Bombs if no pool exists. |
78 |
*/ |
79 |
|
80 |
extern void ReportSetManager(FILE*f); |
81 |
/**< |
82 |
* Reports on the set pool to f. |
83 |
*/ |
84 |
|
85 |
extern struct set_t *CreateEmptySet(void); |
86 |
/**< |
87 |
* Creates an empty set. |
88 |
*/ |
89 |
|
90 |
extern void InsertInteger(struct set_t *set, long i); |
91 |
/**< |
92 |
* Insert i into set. You can insert i multiple times without causing |
93 |
* problems. Set must be non-NULL. This will coerce an empty set type |
94 |
* into an integer set type; after that no symbols can be inserted into |
95 |
* the set. |
96 |
*/ |
97 |
|
98 |
extern void InsertIntegerRange(struct set_t *set, long lower, long upper); |
99 |
/**< |
100 |
* Insert the elements i such that i >= lower and i <= upper. Note if |
101 |
* lower > upper, no elements are inserted. This will coerce an empty |
102 |
* set type into an integer set type. |
103 |
*/ |
104 |
|
105 |
extern void InsertString(struct set_t *set, symchar *str); |
106 |
/**< |
107 |
* Insert str into set. This will coerce an empty set type into |
108 |
* a string set type; after which no integers can be inserted. |
109 |
*/ |
110 |
|
111 |
extern struct set_t *SetUnion(CONST struct set_t *s1, CONST struct set_t *s2); |
112 |
/**< |
113 |
* Create a set which is the union of s1 and s2. s1 and s2 are uneffected. |
114 |
* Union with empty set is always okay. |
115 |
*/ |
116 |
|
117 |
extern struct set_t *SetIntersection(CONST struct set_t *s1, |
118 |
CONST struct set_t *s2); |
119 |
/**< |
120 |
* Create a set which is the intersection of s1 and s2. s1 and s2 are |
121 |
* uneffected. Intersection with empty set is okay. |
122 |
*/ |
123 |
|
124 |
extern struct set_t *SetDifference(CONST struct set_t *s1, CONST struct set_t *s2); |
125 |
/**< |
126 |
* Create a set which is define as follows: |
127 |
* return set := { i | (i IN s1) and (NOT (i IN s2))} |
128 |
*/ |
129 |
|
130 |
extern struct set_t *CopySet(CONST struct set_t *set); |
131 |
/**< |
132 |
* Copy a set. |
133 |
*/ |
134 |
|
135 |
extern int IntMember(long i, CONST struct set_t *set); |
136 |
/**< |
137 |
* Return a TRUE value if i is a member of set; otherwise, return a false |
138 |
* value. |
139 |
*/ |
140 |
|
141 |
extern int StrMember(symchar *str, CONST struct set_t *set); |
142 |
/**< |
143 |
* Return a TRUE value if str is a member of set; otherwise, return a false |
144 |
* value. |
145 |
*/ |
146 |
|
147 |
extern void DestroySet(struct set_t *set); |
148 |
/**< "Free up" set pointer. Actually returns it to the pool of set stubs. */ |
149 |
|
150 |
extern int NullSet(CONST struct set_t *set); |
151 |
/**< Testing if the set is empty. TRUE if set is empty. */ |
152 |
|
153 |
ASC_DLLSPEC unsigned long Cardinality(CONST struct set_t *set); |
154 |
/**< Return the number of members. */ |
155 |
|
156 |
ASC_DLLSPEC symchar*FetchStrMember(CONST struct set_t *set, unsigned long n); |
157 |
/**< Returns the nth (internal sort order ) member symbol. */ |
158 |
|
159 |
ASC_DLLSPEC long FetchIntMember(CONST struct set_t *set, unsigned long n); |
160 |
/**< Returns the nth (internal sort order ) member number. */ |
161 |
|
162 |
extern void SetIterate(struct set_t *set, void (*func)()); |
163 |
/**< Calls func for every element in set. */ |
164 |
|
165 |
ASC_DLLSPEC enum set_kind SetKind(CONST struct set_t *set); |
166 |
/**< Returns the type of the set. */ |
167 |
|
168 |
extern int SetsEqual(CONST struct set_t *s1, CONST struct set_t *s2); |
169 |
/**< |
170 |
* Returns a true value if the two sets are equal. Set equality is |
171 |
* defined as: |
172 |
* (i IN s1) <==> (i IN s2) |
173 |
* This always returns FALSE if the sets are of different type. |
174 |
*/ |
175 |
|
176 |
extern int Subset(CONST struct set_t *s1, CONST struct set_t *s2); |
177 |
/**< |
178 |
* Returns a true value if s1 is contained in s2. It always returns FALSE |
179 |
* if the sets are of different type(even if they are empty sets). |
180 |
* |
181 |
* - TRUE if (i IN s1) ==> (i IN s2) |
182 |
* - FALSE otherwise |
183 |
*/ |
184 |
|
185 |
extern int CmpSetInstVal(CONST struct set_t *s1, CONST struct set_t *s2); |
186 |
/**< |
187 |
* Returns -1, 0, 1 from comparing s1,s2. |
188 |
*/ |
189 |
|
190 |
/* |
191 |
* Some ordered set processing. The elements of the below sets are |
192 |
* not necessarily unique and not necessarily ordered. In this way they |
193 |
* behave more like lists. For TRUE sets use the InsertInteger and |
194 |
* InsertString functions above. |
195 |
*/ |
196 |
|
197 |
extern void AppendIntegerElement(struct set_t *set, long int i ); |
198 |
/**< |
199 |
* This function will append an integer to a set. In so doing it will NOT |
200 |
* attempt to sort the elements of the set or to make the elements of the |
201 |
* set unique. In this way the set is treated as a list. |
202 |
*/ |
203 |
|
204 |
extern void AppendStringElement(struct set_t *set, symchar *str); |
205 |
/**< |
206 |
* This function will append an string to a set. In so doing it will NOT |
207 |
* attempt to sort the elements of the set or to make the elements of the |
208 |
* set unique. In this way the set is treated as a list. |
209 |
*/ |
210 |
|
211 |
/* @} */ |
212 |
|
213 |
#endif /* ASC_SETINSTVAL_H */ |
214 |
|