Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / tecsrc / SET.h
blob8fd926ead4b22677da413f76bc15f1c84a63165d
1 /*
2 * NOTICE and LICENSE for Tecplot Input/Output Library (TecIO) - OpenFOAM
4 * Copyright (C) 1988-2009 Tecplot, Inc. All rights reserved worldwide.
6 * Tecplot hereby grants OpenCFD limited authority to distribute without
7 * alteration the source code to the Tecplot Input/Output library, known
8 * as TecIO, as part of its distribution of OpenFOAM and the
9 * OpenFOAM_to_Tecplot converter. Users of this converter are also hereby
10 * granted access to the TecIO source code, and may redistribute it for the
11 * purpose of maintaining the converter. However, no authority is granted
12 * to alter the TecIO source code in any form or manner.
14 * This limited grant of distribution does not supersede Tecplot, Inc.'s
15 * copyright in TecIO. Contact Tecplot, Inc. for further information.
17 * Tecplot, Inc.
18 * 3535 Factoria Blvd, Ste. 550
19 * Bellevue, WA 98006, USA
20 * Phone: +1 425 653 1200
21 * http://www.tecplot.com/
24 #if defined EXTERN
25 #undef EXTERN
26 #endif
27 #if defined SETMODULE
28 #define EXTERN
29 #else
30 #define EXTERN extern
31 #endif
33 #ifndef _SET_H_INCLUDED
34 #define _SET_H_INCLUDED
37 *****************************************************************
38 *****************************************************************
39 ******* ********
40 ****** Copyright (C) 1988-2008 Tecplot, Inc. *******
41 ******* ********
42 *****************************************************************
43 *****************************************************************
46 #define PadOut(X,Y) ((int)(((X)-1)/(Y)+1)*(Y))
47 #define SetBitSize (8*sizeof(SetData_t))
48 #define SetLastBit (((unsigned long)1)<<(SetBitSize-1))
50 #if defined _DEBUG
51 # define USE_FUNCTIONS_FOR_SETS
52 #endif
54 /* *
55 * * NOTE: "Set_pa" is a pointer to an "abstract type",
56 * * hence the "_pa". Pointer here is akin to "handle".
57 * * Any routines dealing with the internals of Set_pa
58 * * or Set_a must be in the same file as these routines
59 * */
61 /* Set_a is intentionally not defined to further
62 * deter usage of this private structure */
63 struct _Set_a
65 /* * PRIVATE * */
66 SetIndex_t size;
67 SetData_pt data;
71 * Checks set for NULL.
73 #define IsSetNull(Set) ((Set)==NULL)
75 /**
76 * Indicates how many bytes are required to store the set data.
78 inline size_t SetDataSizeInBytes(Set_pa Set)
80 REQUIRE(VALID_REF(Set));
81 return Set->size / SetBitSize * sizeof(SetData_t);
85 * Allocates a new empty set. Returns NULL if not enough memory.
87 EXTERN Set_pa AllocSet(Boolean_t show_error_msg);
90 * Frees all memory associated with set "*set", and
91 * sets "*set" to NULL.
93 EXTERN void DeallocSet(Set_pa *Set);
95 /**
96 * This function adapts the DeallocSet function to work with the
97 * ArrayList's deallocation callback.
99 EXTERN Boolean_t SetItemDestructor(void *ItemRef,
100 ArbParam_t ClientData);
102 * Makes sure set "set" can hold at least "max_val" elements.
103 * Returns TRUE if successful, FALSE otherwise. A successful
104 * call to ExpandSet() guarentees that any calls to AddToSet()
105 * will be successful as long as the elements added are less
106 * than "max_val".
108 EXTERN Boolean_t ExpandSet(Set_pa Set,
109 SetIndex_t max_val,
110 Boolean_t show_error_msg);
113 * Copies set "src" to set "dst". Returns TRUE if successful,
114 * FALSE if "src" contains elements it is unable to add to "dst".
116 EXTERN Boolean_t CopySet(Set_pa dst,
117 Set_pa src,
118 Boolean_t show_error_msg);
121 * Appends set "src" to set "dst". Returns TRUE if successful,
122 * FALSE if "src" contains elements it is unable to add to "dst".
124 EXTERN Boolean_t AppendSet(Set_pa dst,
125 Set_pa src,
126 Boolean_t show_error_msg);
128 * Empties the set "set".
130 EXTERN void ClearSet(Set_pa Set);
133 * Adds "member" to set "set". Returns TRUE if successful,
134 * FALSE otherwise. AddToSet() can only return FALSE if
135 * "member" is greater than any previous member of "set" and
136 * also greater that any "max_val" set with ExpandSet().
138 #if defined USE_FUNCTIONS_FOR_SETS
139 EXTERN Boolean_t AddToSet(Set_pa Set,
140 SetIndex_t member,
141 Boolean_t show_error_msg);
142 #else
143 # if defined __cplusplus
144 inline Boolean_t AddToSet(Set_pa Set,
145 SetIndex_t member,
146 Boolean_t show_error_msg)
148 if (Set &&
149 (member + 1 <= Set->size ||
150 ExpandSet(Set, member + 1, show_error_msg)))
152 SetIndex_t word = member / SetBitSize;
153 SetData_t bit = (SetData_t)1 << (member % SetBitSize);
154 Set->data[word] |= bit;
155 return TRUE;
157 else
158 return FALSE;
159 } /* AddToSet() */
160 # else
161 # define AddToSet(Set,member,show_error_msg) \
162 (((Set) && \
163 ((member)+1 <= (Set)->size || \
164 ExpandSet((Set), (member)+1, (show_error_msg)))) \
165 ? (((Set)->data[(member) / SetBitSize] |= (SetData_t)1 << ((member) % SetBitSize)), TRUE) \
166 : FALSE)
167 # endif
168 #endif
171 * Removes "member" from set "set".
173 EXTERN void RemoveFromSet(Set_pa Set,
174 SetIndex_t member);
176 EXTERN void DeleteSetMember(Set_pa Set,
177 SetIndex_t Member);
178 EXTERN Boolean_t InsertSetMember(Set_pa Set,
179 SetIndex_t Member,
180 Boolean_t ShowErrMsg);
182 * Test for membership of "member" in set "set". This is the only
183 * function worth making into a macro or inline function.
185 #if defined USE_FUNCTIONS_FOR_SETS
186 EXTERN Boolean_t InSet(Set_pa Set,
187 SetIndex_t member);
188 #else
189 # if defined __cplusplus
190 inline Boolean_t InSet(Set_pa Set,
191 SetIndex_t member)
193 if (Set && (0 <= member && member < Set->size))
195 SetIndex_t word = member / SetBitSize;
196 SetData_t bit = (SetData_t)1 << (member % SetBitSize);
197 return (Set->data[word]&bit) != 0;
199 else
200 return FALSE;
201 } /* InSet() */
202 # else
203 # define InSet(Set,member) ((Set && (0<=(member) && (member)<(Set)->size)) \
204 ? ((Set)->data[(member)/SetBitSize]&((SetData_t)1<<((member)%SetBitSize)))!=0 \
205 : FALSE)
206 # endif
207 #endif
210 * Returns TRUE if set "set" is empty.
212 EXTERN Boolean_t IsEmpty(Set_pa Set);
215 * Returns TRUE if Set has voids.
217 EXTERN Boolean_t HasVoids(Set_pa Set);
220 * Returns number of members in Set "Set".
222 EXTERN SetIndex_t MemberCount(Set_pa Set);
225 * Returns the next member in set "set" after member "start_at".
226 * Use "start_at" of BAD_ZV_VALUE to find first member.
228 EXTERN SetIndex_t GetNextMember(Set_pa Set,
229 SetIndex_t start_at);
232 * Returns the previous member in set "set" before member
233 * "start_at". Use "start_at" of BAD_ZV_VALUE to find last member.
235 EXTERN SetIndex_t GetPrevMember(Set_pa Set,
236 SetIndex_t start_at);
239 * Returns TRUE if sets are equal (have same members). FALSE otherwise.
241 EXTERN Boolean_t EqualSets(Set_pa set1,
242 Set_pa set2);
245 * Returns TRUE if all members of childset are contained in parentset.
247 EXTERN Boolean_t IsSubSet(Set_pa childset,
248 Set_pa parentset);
250 EXTERN SetIndex_t MemberOffset(Set_pa Set,
251 SetIndex_t Member);
253 EXTERN SetIndex_t OffsetMember(Set_pa Set,
254 SetIndex_t Offset);
257 EXTERN Boolean_t CopySetMember(Set_pa DstSet,
258 SetIndex_t DstOffset,
259 Set_pa SrcSet,
260 SetIndex_t SrcOffset);
262 EXTERN void ShiftSet(Set_pa Set,
263 SetIndex_t ShiftPos1,
264 SetIndex_t ShiftPos2,
265 SetIndex_t ShiftAmount);
269 * Handy macros
271 #define GetFirstSetMember(Set) (GetNextMember((Set), BAD_SET_VALUE))
272 #define GetLastSetMember(Set) (GetPrevMember((Set), BAD_SET_VALUE))
274 #define ForAllMembersInSet(Member, Set) \
275 for (Member = GetFirstSetMember((Set)); \
276 Member != BAD_SET_VALUE; \
277 Member = GetNextMember((Set), (Member)))
278 #define ForAllMembersInReversedSet(Member, Set) \
279 for (Member = GetLastSetMember((Set)); \
280 Member != BAD_SET_VALUE; \
281 Member = GetPrevMember((Set), (Member)))
283 #endif // _SET_H_INCLUDED