2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/object/propimp.h,v 1.17 2000/01/29 13:24:30 adurant Exp $
23 ////////////////////////////////////////////////////////////
27 // An interface for creating, copying, terminating and instantiating
28 // a property's values.
30 ////////////////////////////////////////////////////////////
32 typedef void PropFile
;
34 typedef BOOL (*PropReadFunc
)(PropFile
* file
, void* buf
, int len
);
35 typedef BOOL (*PropWriteFunc
)(PropFile
* file
, void* buf
, int len
);
40 // return the current version of the data structure
41 virtual uint
Version(void);
42 // initalize a value, grabbing resources, etc
43 virtual void Init(ObjID obj
, void* value
) = 0;
44 // Fill in an initalized value with a "default" value, based on
45 // the suggestion, which may be NULL.
46 virtual void New(ObjID obj
, void* value
, void *sug
= NULL
) = 0;
47 // Terminate a value, freeing resources grabbed by init, etc.
48 virtual void Term(ObjID obj
, void* value
) = 0;
49 // Copy one initialized value to another.
50 virtual void Copy(ObjID obj
, void* targ
, void* src
) = 0;
51 // Read a value in from disk using the read func
52 virtual void Read(ObjID obj
, void* value
, uint version
, PropReadFunc read
, PropFile
* file
) = 0;
53 // write a value to disk using the write func
54 virtual void Write(ObjID obj
, void* value
, PropWriteFunc write
, PropFile
* file
) = 0;
58 ////////////////////////////////////////////////////////////
62 // Implements the storage for a property. Cares about nothing about the
63 // property itself except its size. All it has to do is maintain
64 // mappings between ObjID's and blocks of elem_size_ bytes.
66 // Possible implementations of this interface:
67 // List of pairs, implemented as an array
68 // List of pairs, implemented as a linked list
70 // Dynamic array with one entry for each ObjID. But how do we
71 // represent irrelevant entries (or tell the cPropertyImpl that
72 // irrelevant == FALSE?)
74 ////////////////////////////////////////////////////////////
79 // Constructor; tell it the size of the property
80 cPropertyImpl (int elem_size
, cPropValueFuncs
* f
= NULL
);
83 virtual ~cPropertyImpl ();
85 // Stuffs a pointer to the value into *pptr, returns whether relevant
86 virtual BOOL
Get (ObjID obj
, PropertyID propid
, void **pptr
) const = 0;
88 // Sets obj's value to what's pointed to by ptr
89 // return true iff newly relevant
90 virtual BOOL
Set (ObjID obj
, PropertyID propid
, void *ptr
) = 0;
92 // Makes the property no longer relevant for obj, return whether it was there
93 virtual BOOL
Delete(ObjID obj
, PropertyID propid
) = 0;
95 // Makes a property newly relevant for obj, inits but does not new the value.
97 virtual void* Create(ObjID obj
, PropertyID propid
) = 0;
99 // Do any necessary set up for the creation of a new object.
100 virtual void Prep(ObjID
, PropertyID
) {};
102 // Reset the database to empty
103 virtual void Reset(PropertyID id
) = 0;
106 virtual void IterStart(PropertyID id
, sPropertyObjIter
* iter
) const = 0;
107 virtual BOOL
IterNext(PropertyID id
, sPropertyObjIter
* iter
, ObjID
* next
, void** value
) const
109 virtual void IterStop(PropertyID id
, sPropertyObjIter
* iter
) const = 0;
112 // Is this property relevant to the given obj?
113 virtual BOOL
Relevant (ObjID obj
, PropertyID propid
) const = 0;
115 // Set the value funcs
116 void SetValueFuncs(cPropValueFuncs
* f
);
117 cPropValueFuncs
* GetValueFuncs() { return vfunc_
;};
118 BOOL
SetValueFuncSponsorship(BOOL sponsored
)
120 BOOL retval
= sponsored_
;
121 sponsored_
= sponsored
;
128 // Value funcs interface for subclasses
129 // (Useful if there's common code)
130 void Init(ObjID obj
, void* value
) { vfunc_
->Init(obj
,value
);};
131 void New (ObjID obj
, void *value
, void* sug
= NULL
) { vfunc_
->New(obj
,value
,sug
);}
132 void Term(ObjID obj
, void* value
) { vfunc_
->Term(obj
,value
);};
133 void Copy(ObjID obj
, void* targ
, void* src
)
134 {if (targ
!= src
) vfunc_
->Copy(obj
,targ
,src
);}
135 void Read(ObjID obj
, void* v
, uint ver
, PropReadFunc r
, PropFile
* f
) { vfunc_
->Read(obj
,v
,ver
,r
,f
);}
136 void Write(ObjID obj
, void* value
, PropWriteFunc write
, PropFile
* file
)
137 { vfunc_
->Write(obj
,value
,write
,file
);}
138 uint
Version(void) { return vfunc_
->Version(); }
140 // Get size of elements
141 int ElemSize () const {return elem_size_
;}
145 // Prevent copying by value
146 cPropertyImpl (const cPropertyImpl
&) {};
147 cPropertyImpl
& operator= (const cPropertyImpl
&);
154 cPropValueFuncs
* vfunc_
;
158 ////////////////////////////////////////////////////////////
159 // Create an impl of a particular type size, from the enum
161 EXTERN cPropertyImpl
*CreatePropertyImpl (ePropertyImpl impl
, int size
, cPropValueFuncs
* vfunc
= NULL
);
167 typedefs:("BOOL" "GUID" "IComplexProperty" "IMPL" "IFACE" "IProperty" "ISimpleProperty" "LlistHead" "LlistHeader" "MetaPropertyAlistElt" "ObjID" "PropertyID" "TYPE" "cComplexProperty" "cDynArray" "cLlistPropertyImpl" "cMetaPropertyImpl" "cMetaPropertyIterator" "cProperty" "cPropertyImpl" "cPropertyManager" "cPropertyManagerKnower" "cPropertyTable" "cSimpleProperty" "cStr" "cStrHashSet" "propsElt" "tHashSetKey" "tHashSetNode")