C4 Engine
C4 Engine API Documentation

Unpacker::AddObjectLink

Defined in:  C4Packing.h
Adds an object link that will be resolved after unpacking is complete.
Prototype

void AddObjectLink(int32 index, ObjectLink::Linker *linker, void *cookie);

Parameters
index The index of the object to be linked.
linker A pointer to the linker function.
cookie A user-defined pointer that is passed to the linker function.
Description
The AddObjectLink function registers a linker function that is called after unpacking is complete in order to resolve an object index to the actual pointer to an object. The AddObjectLink function should be called from within an overridden Packable::Unpack function or the callback passed to the Packable::UnpackChunkList function. The index parameter should be set to the object index, which would typically have just been unpacked.

The ObjectLink::Linker type is defined as follows.

typedef void Linker(Object *, void *);

The linker parameter should be set to a pointer to a static function having this prototype, and the cookie parameter should be any pointer that the calling function needs. The value of the cookie parameter is passed to the linker function as its second parameter. The object pointer received in the first parameter of the linker function will be the object whose index was previously specified by the index parameter when the AddObjectLink function was called. Note that the object pointer can be nullptr if the object could not be constructed during the unpacking process.
See Also

Unpacker::AddNodeLink