forked from stepcode/stepcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuperInvAttrIter.h
More file actions
72 lines (69 loc) · 2.11 KB
/
superInvAttrIter.h
File metadata and controls
72 lines (69 loc) · 2.11 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
#ifndef SUPERINVATTRITER_H
#define SUPERINVATTRITER_H
#include "clstepcore/SubSuperIterators.h"
#include "clstepcore/ExpDict.h"
/**
* this class implements an iterator for inverse attributes in an EntityDescriptor's supertypes
* makes use of supertypesIterator and InverseAItr
*
* TODO verify that this iterates correctly!
*/
class superInvAttrIter {
protected:
supertypesIterator sit;
InverseAItr * invIter;
const Inverse_attribute * nextInv;
bool isempty; ///< if true, don't try to access invIter - it is not initialized
public:
/// WARNING this will not iterate over the ia's in the first ed, only in its supertypes! change that?
superInvAttrIter( const EntityDescriptor * ed ): sit( ed ), invIter(0), nextInv( 0 ), isempty( false ) {
reset();
}
void reset( const EntityDescriptor * ed = 0 ) {
sit.reset( ed );
if( invIter ) {
delete invIter;
invIter = 0;
}
if( sit.empty() ) {
isempty = true;
} else {
invIter = new InverseAItr( &( sit.current()->InverseAttr() ) );
nextInv = invIter->NextInverse_attribute();
if( !nextInv ) {
next();
}
}
}
~superInvAttrIter() {
if( invIter ) {
delete invIter;
invIter = 0;
}
}
const EntityDescriptor * currentEDesc() {
if( isempty ) {
return NULL;
}
return sit.current();
}
bool empty() {
if( isempty ) {
return true;
}
return ( !sit.hasNext() && !nextInv );
}
const Inverse_attribute * next() {
if( isempty ) {
return NULL;
}
const Inverse_attribute * ia = nextInv;
/* if we're on the last inverse attr for the current super, go to the next super
* keep going until we find an ia or run out of supers */
while( ( 0 == ( nextInv = invIter->NextInverse_attribute() ) ) && sit.hasNext() ) {
invIter->ResetItr( &( sit.next()->InverseAttr() ) );
}
return ia;
}
};
#endif //SUPERINVATTRITER_H