2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/object/relatio_.h,v 1.10 2000/01/29 13:24:51 adurant Exp $
22 ////////////////////////////////////////////////////////////
26 // Common methods that almost every relation implementation would want to use.
28 ////////////////////////////////////////////////////////////
30 class cUnknownRelation
: public IRelation
33 DECLARE_UNAGGREGATABLE();
35 virtual ~cUnknownRelation() {};
39 class cBaseRelation
: public cUnknownRelation
, protected cLinkManagerKnower
44 cBaseRelation(const sRelationDesc
& desc
, const sRelationDataDesc
& datadesc
)
45 : Desc(desc
), DataDesc(datadesc
)
46 { ID
= LinkMan()->AddRelation(this);};
47 ~cBaseRelation() { delete DataDesc
.data_ops
; };
53 STDMETHOD_(const sRelationDesc
*, Describe
)() const;
54 STDMETHOD_(RelationID
,GetID
)() const;
55 STDMETHOD_(const sRelationDataDesc
*, DescribeData
)() const;
56 STDMETHOD_(IRelation
*, Inverse
)();
57 STDMETHOD(Listen
)(RelationListenMsgSet interests
, RelationListenFunc func
, RelationListenerData data
);
59 STDMETHOD_(LinkID
, GetSingleLink
)(ObjID source
, ObjID dest
);
60 STDMETHOD_(BOOL
, AnyLinks
)(ObjID source
, ObjID dest
);
66 void CallListeners(eRelationListenMsg msg
, LinkID id
, sLink
* linkdata
= NULL
);
69 sRelationDataDesc DataDesc
;
74 RelationListenMsgSet interests
;
75 RelationListenFunc func
;
76 RelationListenerData data
;
77 Listener(RelationListenMsgSet i
, RelationListenFunc f
,
78 RelationListenerData d
)
79 :interests(i
),func(f
),data(d
) {};
81 cDynArray
<Listener
> Listeners
;
83 // Interfaces that are needed by & shared by all properties.
84 static INetManager
*gmNetMan
;
85 static IObjectNetworking
*gmObjNet
;
87 // Temporary flag variables, to prevent loops in networking. These
88 // are global solely because they are needed in static methods.
89 static ObjID gmRespondSourceObj
;
90 static ObjID gmRespondDestObj
;
92 // Private networking function which must be implemented by any descendent.
93 virtual void SendLinkMsg(eRelationListenMsg ops
, LinkID id
, sLink
* linkdata
) = 0;
96 ////////////////////////////////////////////////////////////
100 // The standard relation implementation.
101 // Basically, since queries over a single relation fall in
102 // to four cases (enumerated in linkbase.h), there is a separate
103 // query database for each case.
105 ////////////////////////////////////////////////////////////
108 class cLinkQueryDatabaseSet
110 ILinkQueryDatabase
* DB
[kRelationNumQueryCases
];
114 cLinkQueryDatabaseSet(ILinkQueryDatabase
* none
,
115 ILinkQueryDatabase
* source
= NULL
,
116 ILinkQueryDatabase
* dest
= NULL
,
117 ILinkQueryDatabase
* both
= NULL
);
118 cLinkQueryDatabaseSet(const cLinkQueryDatabaseSet
& db
);
119 cLinkQueryDatabaseSet(IUnknown
* db
);
120 ~cLinkQueryDatabaseSet();
122 ILinkQueryDatabase
* operator[](int n
) const {return DB
[n
];};
123 int Size() const { return sizeof(DB
)/sizeof(DB
[0]);};
126 class cStandardRelation
: public cBaseRelation
128 void Init(); // Common constructor stuff
131 // Constructor, takes a store and a database.
132 cStandardRelation(const sRelationDesc
& desc
, const sRelationDataDesc
& ddesc
, IUnknown
* store
, IUnknown
* Database
, IUnknown
* datastor
= NULL
);
133 // Takes the whole set of four
134 cStandardRelation(const sRelationDesc
& desc
, const sRelationDataDesc
& ddesc
, IUnknown
* store
, const cLinkQueryDatabaseSet
& dbs
, IUnknown
* datastor
= NULL
);
135 virtual ~cStandardRelation();
140 STDMETHOD(SetID
)(RelationID id
);
141 STDMETHOD_(LinkID
, Add
)(ObjID source
, ObjID dest
);
142 STDMETHOD_(LinkID
, AddFull
)(ObjID source
, ObjID desc
, void* data
);
143 STDMETHOD(Remove
)(LinkID id
);
144 STDMETHOD_(BOOL
,Get
)(LinkID id
, sLink
* out
) const;
145 STDMETHOD(SetData
)(LinkID id
, void* data
);
146 STDMETHOD_(void*,GetData
)(LinkID id
);
147 STDMETHOD_(ILinkQuery
*,Query
)(ObjID source
, ObjID dest
) const;
148 STDMETHOD(Notify
)(eRelationNotifyMsg msg
, RelationNotifyData data
);
151 cLinkQueryDatabaseSet DB
;
153 ILinkDataStore
* DataStore
;
155 static tNetMsgHandlerID gmNetMsgHandlerID
; // handler ID included at top of network messages
157 // private networking functions
158 void SendLinkMsg(eRelationListenMsg ops
, LinkID id
, sLink
* linkdata
);
159 static void ReceiveLinkMsg(const sNetMsg_Generic
*pMsg
, ulong size
, ObjID from
, void*);
162 #endif // __RELATIO__H