convert line ends
[canaan.git] / prj / cam / src / object / relatio_.h
blob10af9bc9d7ff2e7cc972b7a791a4ef901bb2c920
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/object/relatio_.h,v 1.10 2000/01/29 13:24:51 adurant Exp $
7 #pragma once
9 #ifndef __RELATIO__H
10 #define __RELATIO__H
11 #include <relation.h>
12 #include <linkbase.h>
13 #include <linkknow.h>
14 #include <dynarray.h>
15 #include <linkqdb.h>
16 #include <linkstor.h>
17 #include <linkint.h>
18 #include <dataops.h>
19 #include <iobjnet.h>
20 #include <netman.h>
22 ////////////////////////////////////////////////////////////
24 // cBaseRelation
26 // Common methods that almost every relation implementation would want to use.
28 ////////////////////////////////////////////////////////////
30 class cUnknownRelation : public IRelation
32 public:
33 DECLARE_UNAGGREGATABLE();
35 virtual ~cUnknownRelation() {};
39 class cBaseRelation : public cUnknownRelation, protected cLinkManagerKnower
41 public:
44 cBaseRelation(const sRelationDesc& desc, const sRelationDataDesc& datadesc)
45 : Desc(desc), DataDesc(datadesc)
46 { ID = LinkMan()->AddRelation(this);};
47 ~cBaseRelation() { delete DataDesc.data_ops; };
50 // IRelation Methods
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);
63 // Helper functions
66 void CallListeners(eRelationListenMsg msg, LinkID id, sLink* linkdata = NULL);
67 protected:
68 sRelationDesc Desc;
69 sRelationDataDesc DataDesc;
70 RelationID ID;
72 struct Listener
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 ////////////////////////////////////////////////////////////
98 // cStandardRelation
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];
111 void Init(void);
113 public:
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
130 public:
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();
138 // IRelation methods
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);
150 private:
151 cLinkQueryDatabaseSet DB;
152 ILinkStore* Store;
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