2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/object/linkset.cpp,v 1.4 1998/01/27 18:49:35 mahk Exp $
12 // Must be last header
16 template cDList
<cSimpleDListNode
<LinkID
>,1>;
17 template cSimpleDList
<LinkID
>;
18 template cSimpleListSet
<LinkID
>;
22 ////////////////////////////////////////////////////////////
24 // INTERNAL CLASS: cSimpleLinkSetQuery
26 ////////////////////////////////////////////////////////////
28 class cSimpleLinkSetQuery
: public cBaseLinkQuery
32 BOOL
Eligible(LinkID id
);
35 cSimpleLinkSetQuery(const cLinkSet
* set
,
36 tQueryDate bday
= QUERY_DATE_NONE
)
39 { while (!Iter
.Done() && !Eligible(Iter
.Value())) Iter
.Next();} ;
41 virtual ~cSimpleLinkSetQuery() {};
43 STDMETHOD_(BOOL
,Done
)() const;
44 STDMETHOD(Link
)(sLink
* link
) const;
46 STDMETHOD_(LinkID
,ID
)() const { return (LinkID
)Iter
.Value();};
50 STDMETHODIMP_(BOOL
) cSimpleLinkSetQuery::Done() const
55 STDMETHODIMP
cSimpleLinkSetQuery::Link(sLink
* link
) const
57 if (Iter
.Done()) return E_FAIL
;
58 LinkID val
= Iter
.Value();
59 LinkMan()->Get(val
,link
);
63 BOOL
cSimpleLinkSetQuery::Eligible(LinkID link
)
65 return VerifyLink(link
);
68 STDMETHODIMP
cSimpleLinkSetQuery::Next()
70 for (Iter
.Next(); !Iter
.Done(); Iter
.Next())
72 if (Eligible(Iter
.Value()))
78 ////////////////////////////////////////////////////////////
80 // INTERNAL CLASS: cLinkSetQuery
82 ////////////////////////////////////////////////////////////
84 class cLinkSetQuery
: public cBaseLinkQuery
86 sLinkTemplate Pattern
;
89 BOOL
Eligible(LinkID id
);
92 cLinkSetQuery(const cLinkSet
& set
,
93 const sLinkTemplate
& pattern
,
94 tQueryDate bday
= QUERY_DATE_NONE
)
98 { while (!Iter
.Done() && !Eligible(Iter
.Value())) Iter
.Next();} ;
100 virtual ~cLinkSetQuery() {};
102 STDMETHOD_(BOOL
,Done
)() const;
103 STDMETHOD(Link
)(sLink
* link
) const;
105 STDMETHOD_(LinkID
,ID
)() const { return (LinkID
)Iter
.Value();};
109 STDMETHODIMP_(BOOL
) cLinkSetQuery::Done() const
114 STDMETHODIMP
cLinkSetQuery::Link(sLink
* link
) const
116 if (Iter
.Done()) return E_FAIL
;
117 LinkID val
= Iter
.Value();
118 LinkMan()->Get(val
,link
);
122 BOOL
cLinkSetQuery::Eligible(LinkID link
)
124 if (!VerifyLink(link
)) return FALSE
;
127 RelationID relid
= LINKID_RELATION(link
);
129 // don't yield inverse links on wildcard.
130 // cuz that's the spec
132 if (!RELID_MATCH(Pattern
.flavor
,relid
))
135 // we always assume the source is right.
136 if (Pattern
.dest
!= LINKOBJ_WILDCARD
) // must test dest
139 LinkMan()->Get(link
,(sLink
*)&temp
);
140 if (temp
!= Pattern
) return FALSE
;
145 STDMETHODIMP
cLinkSetQuery::Next()
147 for (Iter
.Next(); !Iter
.Done(); Iter
.Next())
149 if (Eligible(Iter
.Value()))
157 ////////////////////////////////////////////////////////////
163 ILinkQuery
* cLinkSet::Query(tQueryDate bday
)
165 return new cSimpleLinkSetQuery(this,bday
);
168 ILinkQuery
* cLinkSet::PatternQuery(const struct sLinkTemplate
* pattern
, tQueryDate bday
)
170 return new cLinkSetQuery(*this,*pattern
,bday
);