forked from stepcode/stepcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmgrnodearray.cc
More file actions
241 lines (202 loc) · 6.99 KB
/
mgrnodearray.cc
File metadata and controls
241 lines (202 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* NIST STEP Editor Class Library
* cleditor/mgrnodearray.cc
* April 1997
* David Sauder
* K. C. Morris
* Development of this software was funded by the United States Government,
* and is not subject to copyright.
*/
/* $Id: mgrnodearray.cc,v 3.0.1.3 1997/11/05 22:11:38 sauderd DP3.1 $ */
/*
* MgrNodeArray - dynamic array object of MgrNodes.
* the array part of this is copied from Unidraws UArray - dynamic array object
* Copyright (c) 1990 Stanford University
*/
///////////////////////////////////////////////////////////////////////////////
// debug_level >= 2 => tells when a command is chosen
// debug_level >= 3 => prints values within functions:
// e.g. 1) entity type list when read
// 2) entity instance list when read
///////////////////////////////////////////////////////////////////////////////
static int debug_level = 1;
// if debug_level is greater than this number then
// function names get printed out when executed
static int PrintFunctionTrace = 2;
// if debug_level is greater than this number then
// values within functions get printed out
//static int PrintValues = 3;
#include "clstepcore/mgrnodearray.h"
//#include <STEPentity.h>
#include "clstepcore/sdai.h"
#include <string.h> // to get bcopy() - ANSI
//////////////////////////////////////////////////////////////////////////////
// class MgrNodeArray member functions
//////////////////////////////////////////////////////////////////////////////
MgrNodeArray::MgrNodeArray( int defaultSize )
: GenNodeArray( defaultSize ) {
}
void MgrNodeArray::AssignIndexAddress( int index ) {
// if(debug_level >= PrintFunctionTrace)
// cout << "MgrNodeArray::AssignIndexAddress()\n";
( ( MgrNode * )_buf[index] )->ArrayIndex( index );
}
MgrNodeArray::~MgrNodeArray() {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArray::~MgrNodeArray()\n";
}
DeleteEntries();
}
/*****************************************************************************/
void MgrNodeArray::ClearEntries() {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArray::ClearEntries()\n";
}
int i;
for( i = 0 ; i < _count; i++ ) {
_buf[i] = 0;
}
_count = 0;
}
/*****************************************************************************/
void MgrNodeArray::DeleteEntries() {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArray::DeleteEntries()\n";
}
int i;
for( i = 0 ; i < _count; i++ ) {
delete( ( MgrNode * )_buf[i] );
}
_count = 0;
}
/*****************************************************************************/
int MgrNodeArray::Insert( GenericNode * gn, int index ) {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArray::Insert()\n";
}
int AssignedIndex = GenNodeArray::Insert( gn, index );
int i;
for( i = AssignedIndex ; i < _count; i++ ) {
( ( MgrNode * )_buf[i] )->ArrayIndex( i );
}
return AssignedIndex;
}
/*****************************************************************************/
void MgrNodeArray::Remove( int index ) {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArray::Remove()\n";
}
if( 0 <= index && index < _count ) {
GenNodeArray::Remove( index );
int i;
for( i = index; i < _count; i++ ) {
( ( MgrNode * )_buf[i] )->ArrayIndex( i );
}
}
}
/*****************************************************************************/
int MgrNodeArray::MgrNodeIndex( int fileId ) {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArray::MgrNodeIndex()\n";
}
int i;
for( i = 0; i < _count; ++i ) {
if( ( ( MgrNode * )_buf[i] )->GetApplication_instance()->GetFileId() == fileId ) {
return i;
}
}
return -1;
}
//////////////////////////////////////////////////////////////////////////////
// class MgrNodeArraySorted member functions
//////////////////////////////////////////////////////////////////////////////
MgrNodeArraySorted::MgrNodeArraySorted( int defaultSize )
: GenNodeArray( defaultSize ) {
}
int MgrNodeArraySorted::Insert( GenericNode * gn ) {
// if(debug_level >= PrintFunctionTrace)
// cout << "MgrNodeArraySorted::Insert()\n";
// since gn is really a MgrNode
int fileId = ( ( MgrNode * )gn )->GetApplication_instance()->GetFileId();
int index = FindInsertPosition( fileId );
return GenNodeArray::Insert( gn, index );
}
int MgrNodeArraySorted::Index( GenericNode * gn ) {
// if(debug_level >= PrintFunctionTrace)
// cout << "MgrNodeArraySorted::Index()\n";
// since gn is really a MgrNode
return MgrNodeIndex( ( ( MgrNode * )gn )->GetFileId() );
}
int MgrNodeArraySorted::Index( GenericNode ** gn ) {
// if(debug_level >= PrintFunctionTrace)
// cout << "MgrNodeArraySorted::Index()\n";
// since gn is really a MgrNode
return MgrNodeIndex( ( ( MgrNode * )( *gn ) )->GetFileId() );
}
void MgrNodeArraySorted::ClearEntries() {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArraySorted::ClearEntries()\n";
}
int i;
for( i = 0 ; i < _count; i++ ) {
_buf[i] = 0;
}
_count = 0;
}
/*****************************************************************************/
void MgrNodeArraySorted::DeleteEntries() {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArraySorted::DeleteEntries()\n";
}
int i;
for( i = 0 ; i < _count; i++ ) {
delete( ( MgrNode * )_buf[i] );
}
_count = 0;
}
/*****************************************************************************/
// the reason this is written this way is because most of the
// time the file id will be higher than any seen so far and
// thus the insert position will be at the end
int MgrNodeArraySorted::FindInsertPosition( const int fileId ) {
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArraySorted::FindInsertPosition()\n";
}
int i;
int curFileId;
for( i = _count - 1; i >= 0; --i ) {
curFileId = ( ( MgrNode * )_buf[i] )->GetApplication_instance()->GetFileId();
if( curFileId < fileId /*|| curFileId == fileId*/ ) {
return i + 1;
}
}
return 0;
}
/*****************************************************************************/
int MgrNodeArraySorted::MgrNodeIndex( int fileId ) {
// this function assumes that _buf[0] to _buf[_count] ALL point to MgrNodes
// that are sorted by fileId
if( debug_level >= PrintFunctionTrace ) {
cout << "MgrNodeArraySorted::MgrNodeIndex()\n";
}
int low = 0;
int high = _count - 1;
int mid = 0;
int found = 0;
int curFileId;
while( !found && ( low <= high ) ) {
mid = ( low + high ) / 2;
curFileId = ( ( MgrNode * )_buf[mid] )->GetApplication_instance()->GetFileId();
if( curFileId == fileId ) {
found = 1;
} else if( curFileId < fileId ) {
low = mid + 1;
} else {
high = mid - 1;
}
}
if( found ) {
return mid;
}
return -1;
}