convert line ends
[canaan.git] / prj / cam / src / object / propimp.cpp
blobfba6903602cb43010fbaee881de03c39b2cbf4a0
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/object/propimp.cpp,v 1.14 1997/10/14 23:05:03 mahk Exp $
7 #include <propbase.h>
8 #include <propimp.h>
9 #include <proplist.h>
10 #include <prophash.h>
11 #include <propbig.h>
12 #include <propbit.h>
13 #include <propdb.h>
14 #include <propval_.h>
16 #include <stdlib.h>
17 #include <string.h>
20 // Must be last header
21 #include <dbmem.h>
23 uint cPropValueFuncs::Version(void)
25 return 0;
28 ////////////////////////////////////////////////////////////
30 // cDefaultPropValueFuncs
32 ////////////////////////////////////////////////////////////
34 cDefaultPropValueFuncs::~cDefaultPropValueFuncs()
38 uint cDefaultPropValueFuncs::Version(void)
40 return (uint)size_;
43 void cDefaultPropValueFuncs::Init(ObjID , void* )
47 void cDefaultPropValueFuncs::New(ObjID obj, void* value, void *sug)
49 if (sug != NULL)
50 Copy(obj,value,sug);
51 else
52 memset(value,0,size_);
55 void cDefaultPropValueFuncs::Term(ObjID, void*)
59 void cDefaultPropValueFuncs::Copy(ObjID, void* t, void* s)
61 memcpy(t,s,size_);
64 void cDefaultPropValueFuncs::Read (ObjID obj, void* value, uint version, PropReadFunc read, PropFile* file)
66 // in default, version == size
67 if (version < size_)
69 New(obj,value);
70 read(file,value,version);
72 else
73 read(file,value,size_);
76 void cDefaultPropValueFuncs::Write(ObjID, void* value, PropWriteFunc write, PropFile* file)
78 write(file,value,size_);
81 ////////////////////////////////////////////////////////////
83 // cPropertyImpl
85 ////////////////////////////////////////////////////////////
88 cPropertyImpl::cPropertyImpl(int size, cPropValueFuncs* f)
89 : elem_size_(size),vfunc_(f), sponsored_(TRUE)
91 if (vfunc_ == NULL)
92 vfunc_ = new cDefaultPropValueFuncs(size);
95 ////////////////////////////////////////
97 cPropertyImpl::~cPropertyImpl()
99 if (sponsored_)
100 delete vfunc_;
103 ////////////////////////////////////////
105 void cPropertyImpl::SetValueFuncs(cPropValueFuncs* f)
107 if (sponsored_)
108 delete vfunc_;
109 vfunc_ = f;
110 sponsored_ = FALSE;
117 ////////////////////////////////////////////////////////////
119 // CreatePropertyImpl
121 // Creates an impl based on the ePropertyImpl value.
124 cPropertyImpl *CreatePropertyImpl (ePropertyImpl impl, int size, cPropValueFuncs* f)
126 sPropertyDatabases* db = sPropertyDatabases::DB;
127 cPropertyImpl *pimpl;
129 switch (impl)
131 case kPropertyImplLlist:
132 pimpl = new cPropertyImplLlist(size);
133 break;
135 case kPropertyImplHash:
136 pimpl = CreateUniHashImpl(size);
137 break;
139 case kPropertyImplSparseHash:
140 pimpl = CreateMultiHashImpl(size,db->PropHash);
141 break;
143 case kPropertyImplBigArray:
144 pimpl = CreateArrayImpl(size);
145 break;
147 case kPropertyImplBoolean:
148 pimpl = new cPImpBitVec(size);
149 break;
152 // Add more implementation types here
154 default: Warning (("CreateProperty: Bad impl %d\n", impl)); return NULL;
157 if (f != NULL)
158 pimpl->SetValueFuncs(f);
160 return pimpl;
167 Local Variables:
168 typedefs:("BOOL" "GUID" "IComplexProperty" "IID" "INTERFACE" "IProperty" "ISimpleProperty" "LlistHeader" "ObjID" "PropertyID" "REFIID" "TYPE" "cComplexProperty" "cMetaPropertyImpl" "cMetaPropertyIterator" "cProperty" "cPropertyImpl" "cPropertyManager" "cSimpleProperty" "ePropertyImpl")
169 End: