convert line ends
[canaan.git] / prj / cam / src / object / linkset.cpp
blobe52fd8f97b8e4d4de40fdd915cdc44b585f8b25f
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/object/linkset.cpp,v 1.4 1998/01/27 18:49:35 mahk Exp $
7 #include <lnkquer_.h>
8 #include <linkset.h>
9 #include <lststtem.h>
10 #include <linkid.h>
12 // Must be last header
13 #include <dbmem.h>
15 #ifdef __MSVC
16 template cDList<cSimpleDListNode<LinkID>,1>;
17 template cSimpleDList<LinkID>;
18 template cSimpleListSet<LinkID>;
19 #endif
22 ////////////////////////////////////////////////////////////
24 // INTERNAL CLASS: cSimpleLinkSetQuery
26 ////////////////////////////////////////////////////////////
28 class cSimpleLinkSetQuery : public cBaseLinkQuery
30 cLinkSet::cIter Iter;
32 BOOL Eligible(LinkID id);
33 public:
35 cSimpleLinkSetQuery(const cLinkSet* set,
36 tQueryDate bday = QUERY_DATE_NONE)
37 : Iter(set->Iter()),
38 cBaseLinkQuery(bday)
39 { while (!Iter.Done() && !Eligible(Iter.Value())) Iter.Next();} ;
41 virtual ~cSimpleLinkSetQuery() {};
43 STDMETHOD_(BOOL,Done)() const;
44 STDMETHOD(Link)(sLink* link) const;
45 STDMETHOD(Next)();
46 STDMETHOD_(LinkID,ID)() const { return (LinkID)Iter.Value();};
50 STDMETHODIMP_(BOOL) cSimpleLinkSetQuery::Done() const
52 return Iter.Done();
55 STDMETHODIMP cSimpleLinkSetQuery::Link(sLink* link) const
57 if (Iter.Done()) return E_FAIL;
58 LinkID val = Iter.Value();
59 LinkMan()->Get(val,link);
60 return S_OK;
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()))
73 return S_OK;
75 return E_FAIL;
78 ////////////////////////////////////////////////////////////
80 // INTERNAL CLASS: cLinkSetQuery
82 ////////////////////////////////////////////////////////////
84 class cLinkSetQuery : public cBaseLinkQuery
86 sLinkTemplate Pattern;
87 cLinkSet::cIter Iter;
89 BOOL Eligible(LinkID id);
90 public:
92 cLinkSetQuery(const cLinkSet& set,
93 const sLinkTemplate& pattern,
94 tQueryDate bday = QUERY_DATE_NONE)
95 : Iter(set.Iter()),
96 Pattern(pattern),
97 cBaseLinkQuery(bday)
98 { while (!Iter.Done() && !Eligible(Iter.Value())) Iter.Next();} ;
100 virtual ~cLinkSetQuery() {};
102 STDMETHOD_(BOOL,Done)() const;
103 STDMETHOD(Link)(sLink* link) const;
104 STDMETHOD(Next)();
105 STDMETHOD_(LinkID,ID)() const { return (LinkID)Iter.Value();};
109 STDMETHODIMP_(BOOL) cLinkSetQuery::Done() const
111 return Iter.Done();
114 STDMETHODIMP cLinkSetQuery::Link(sLink* link) const
116 if (Iter.Done()) return E_FAIL;
117 LinkID val = Iter.Value();
118 LinkMan()->Get(val,link);
119 return S_OK;
122 BOOL cLinkSetQuery::Eligible(LinkID link)
124 if (!VerifyLink(link)) return FALSE;
126 // check relation
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))
133 return FALSE;
135 // we always assume the source is right.
136 if (Pattern.dest != LINKOBJ_WILDCARD) // must test dest
138 sLinkTemplate temp;
139 LinkMan()->Get(link,(sLink*)&temp);
140 if (temp != Pattern) return FALSE;
142 return TRUE;
145 STDMETHODIMP cLinkSetQuery::Next()
147 for (Iter.Next(); !Iter.Done(); Iter.Next())
149 if (Eligible(Iter.Value()))
150 return S_OK;
152 return E_FAIL;
157 ////////////////////////////////////////////////////////////
159 // CLASS: cLinkSet
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);