9 #ifndef Navigation_BaseBlobBuilder_H
10 #define Navigation_BaseBlobBuilder_H
29 class BaseBlobBuilder :
public NewOverrideBase<MemStat_BlobBuilder>
37 , m_buildingPart(BUILDING_SHALLOW_PART)
38 , m_shallowBlobSize(0)
79 const bool isBuildingShallowPart = (m_buildingPart == BUILDING_SHALLOW_PART);
81 KY_DEBUG_ASSERTN(isBuildingShallowPart,
82 (
"In BaseBlobBuilder::DoBuild(), BUILD_REFERENCED_BLOB must be called after all calls to BLOB_ARRAY, BLOB_ARRAY_COPY, BLOB_STRING, BLOB_BUILD"));
87 BlobBuffer* GetBlobBufferToBuildReference()
90 m_buildingPart = BUILDING_DEEP_PART;
96 if (m_buildingPart == BUILDING_SHALLOW_PART)
98 assert(m_shallowBlobSize == 0);
114 enum BuildingPart { BUILDING_SHALLOW_PART = 0, BUILDING_DEEP_PART = 1 };
115 BuildingPart m_buildingPart;
129 #define BLOB_SET(blob, value) \
130 if (this->IsWriteMode()) (blob) = (value)
138 #define BLOB_ARRAY(blobArray, count) \
139 this->GetBlobBufferToBuildThis()->AllocArray(this->IsWriteMode() ? &(blobArray) : KY_NULL, count)
150 #define BLOB_ARRAY_COPY(blobArray, src, count) \
151 this->GetBlobBufferToBuildThis()->AllocAndCopyArray(this->IsWriteMode() ? &(blobArray) : KY_NULL, (count) != 0 ? (src) : KY_NULL, (KyUInt32)(count))
154 #define BLOB_ARRAY_COPY_2(blobArray, ky_array) \
155 BLOB_ARRAY_COPY(blobArray, ky_array.GetDataPtr(), ky_array.GetSize())
165 #define BLOB_STRING(str, src) \
166 this->GetBlobBufferToBuildThis()->AllocAndCopyArray(this->IsWriteMode() ? &(str) : KY_NULL, src, (KyUInt32)SFstrlen(src) + 1)
174 #define BLOB_BUILD(blob, builder) \
175 builder.DoBuildAllocatedBlob(this->GetBlobBufferToBuildThis(), this->IsWriteMode() ? &(blob) : KY_NULL)
177 #define BUILD_BLOB(blob, builder) BLOB_BUILD(blob, builder)
181 #define BUILD_REFERENCED_BLOB(blobRef, builder) \
182 builder.DoAllocAndBuildReferencedBlob(this->GetBlobBufferToBuildReference(), this->IsWriteMode() ? &(blobRef) : KY_NULL)
186 #define COPY_REFERENCED_BLOB(blobRef, srcBlob, srcBlobDeepSize, srcBlobShallowSize) \
187 this->GetBlobBufferToBuildReference()->AllocAndCopyReferencedBlob( \
188 this->IsWriteMode() ? &(blobRef) : KY_NULL, srcBlob, srcBlobDeepSize, srcBlobShallowSize)
190 #define COPY_REFERENCED_BLOB_FROM_HANDLER(blobRef, blobHandler) \
191 this->GetBlobBufferToBuildReference()->AllocAndCopyReferencedBlobFromBlobHandler( \
192 this->IsWriteMode() ? &(blobRef) : KY_NULL, blobHandler)
200 BlobBuffer blobBuffer;
201 m_blobBuffer = &blobBuffer;
204 m_blobBuffer->Alloc<T>();
205 m_buildingPart = BUILDING_SHALLOW_PART;
206 m_shallowBlobSize = 0;
210 m_blobBuffer->SwitchToWriteMode(blobHandler, m_shallowBlobSize, m_heap, m_memStat);
213 m_blob = m_blobBuffer->Alloc<T>();
214 m_buildingPart = BUILDING_SHALLOW_PART;
215 m_shallowBlobSize = 0;
233 m_blobBuffer = blobBuffer;
242 m_blobBuffer = blobBuffer;
244 m_blobBuffer->BeginBlobRefBuffer(blobRef);
246 m_blob = m_blobBuffer->Alloc<T>();
249 m_blobBuffer->SetBlobRefInfoFromCurrentOffset();
void DoAllocAndBuildReferencedBlob(BlobBuffer *blobBuffer, BlobRef< T > *blobRef)
For internal use. Use BUILD_REFERENCED_BLOB instead.
Definition: baseblobbuilder.h:257
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
BlobBuffer * GetBlobBufferToBuildThis()
For internal use. Check if m_buildingPart == BUILDING_SHALLOW_PART and return this.
Definition: baseblobbuilder.h:81
The BlobHandler class is a top-level mechanism for serializing blobs between objects in memory and fi...
Definition: blobhandler.h:45
void DoBuildAllocatedBlob(BlobBuffer *blobBuffer, T *blob)
For internal use. Use BLOB_BUILD instead.
Definition: baseblobbuilder.h:248
A BlobRef is a type of reference that is compatible with the blob serialization framework.
Definition: blobref.h:58
BlobBuffer * m_blobBuffer
For internal use. Use BLOB_SET and BLOB_ARRAY instead.
Definition: baseblobbuilder.h:114
T * m_blob
The blob maintained by this builder. Only modify using the macros listed under DoBuild().
Definition: baseblobbuilder.h:117
Definition: gamekitcrowddispersion.h:20
bool IsWriteMode()
Indicates whether the builder is operating in COUNT mode or in WRITE mode.
Definition: baseblobbuilder.h:47
void BuildFlatBlob(T &blob)
Simple way to use DoBuild in case of flat blob (that is, a blob that does not have a BlobArray or Blo...
Definition: baseblobbuilder.h:240
BaseBlobBuilder is an abstract base class that builds a blob within a contiguous block of memory...
Definition: baseblobbuilder.h:30
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
virtual void DoBuild()=0
Implement this function in any class that derives from BaseBlobBuilder.
T * Build(BlobHandler< T > &blobHandler)
This method:Calls DoBuild() in COUNT mode to determine the amount of memory needed for the blob to be...
Definition: baseblobbuilder.h:215