VTK  9.4.20241221
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
vtkMarshalContext Class Reference

Shared context used by vtkSerializer and vtkDeserializer More...

#include <vtkMarshalContext.h>

Inheritance diagram for vtkMarshalContext:
[legend]
Collaboration diagram for vtkMarshalContext:
[legend]

Classes

class  ScopedParentTracker
 Convenient to push a parent as the 'active' identifier and add children to that parent when (de)serializing sub-states or sub-objects. More...
 

Public Types

typedef vtkObject Superclass
 
using WeakObjectStore = std::map< vtkTypeUInt32, vtkWeakPointer< vtkObjectBase > >
 
using StrongObjectStore = std::map< std::string, std::set< vtkSmartPointer< vtkObjectBase > > >
 

Public Member Functions

virtual vtkTypeBool IsA (const char *type)
 Return 1 if this class is the same type of (or a subclass of) the named class.
 
vtkMarshalContextNewInstance () const
 
void PrintSelf (ostream &os, vtkIndent indent) override
 Methods invoked by print to print information about the object including superclasses.
 
const nlohmann::json & Blobs () const
 Get blobs.
 
const nlohmann::json & States () const
 Get states.
 
const WeakObjectStoreWeakObjects () const
 Get map of weak objects.
 
const StrongObjectStoreStrongObjects () const
 Get map of strong objects.
 
void KeepAlive (const std::string &owner, vtkObjectBase *objectBase)
 This method creates a record of ownership between owner and objectBase.
 
void Retire (const std::string &owner, vtkObjectBase *objectBase)
 Release the strong reference kept by owner to the given objectBase.
 
bool RegisterState (nlohmann::json state)
 Add a state.
 
bool UnRegisterState (vtkTypeUInt32 identifier)
 Removes a state.
 
nlohmann::json & GetState (vtkTypeUInt32 identifier) const
 Find and get the state registered at identifier.
 
bool RegisterObject (vtkObjectBase *objectBase, vtkTypeUInt32 &identifier)
 Add an objectBase into the weak object store associated with identifier.
 
bool UnRegisterObject (vtkTypeUInt32 identifier)
 Removes an objectBase registered at identifier from the weak object store.
 
vtkSmartPointer< vtkObjectBaseGetObjectAtId (vtkTypeUInt32 identifier) const
 Find and get the objectBase registered at identifier.
 
vtkTypeUInt32 GetId (vtkObjectBase *objectBase) const
 Get the identifier associated with objectBase.
 
bool RegisterBlob (vtkSmartPointer< vtkTypeUInt8Array > blob, std::string &hash)
 Add a blob into the blob store associated with hash.
 
bool UnRegisterBlob (const std::string &hash)
 Removes a blob registered at hash from the blob store.
 
vtkSmartPointer< vtkTypeUInt8Array > GetBlob (const std::string &hash)
 Find and get the blob registered at hash.
 
std::vector< vtkTypeUInt32 > GetDirectDependencies (vtkTypeUInt32 identifier) const
 Return all direct dependencies of the object/state registered at identifier.
 
void ResetDirectDependencies ()
 Reset the dependency cache.
 
void ResetDirectDependenciesForNode (vtkTypeUInt32 identifier)
 Reset the dependency cache for the given identifier
 
vtkTypeUInt32 MakeId ()
 Make a new identifier.
 
void PushParent (vtkTypeUInt32 identifier)
 Make identifier the active identifier.
 
void PopParent ()
 Adds the 'active' identifier into the genealogy.
 
- Public Member Functions inherited from vtkObject
 vtkBaseTypeMacro (vtkObject, vtkObjectBase)
 
virtual void DebugOn ()
 Turn debugging output on.
 
virtual void DebugOff ()
 Turn debugging output off.
 
bool GetDebug ()
 Get the value of the debug flag.
 
void SetDebug (bool debugFlag)
 Set the value of the debug flag.
 
virtual void Modified ()
 Update the modification time for this object.
 
virtual vtkMTimeType GetMTime ()
 Return this object's modified time.
 
void PrintSelf (ostream &os, vtkIndent indent) override
 Methods invoked by print to print information about the object including superclasses.
 
void RemoveObserver (unsigned long tag)
 
void RemoveObservers (unsigned long event)
 
void RemoveObservers (const char *event)
 
void RemoveAllObservers ()
 
vtkTypeBool HasObserver (unsigned long event)
 
vtkTypeBool HasObserver (const char *event)
 
vtkTypeBool InvokeEvent (unsigned long event)
 
vtkTypeBool InvokeEvent (const char *event)
 
std::string GetObjectDescription () const override
 The object description printed in messages and PrintSelf output.
 
unsigned long AddObserver (unsigned long event, vtkCommand *, float priority=0.0f)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
unsigned long AddObserver (const char *event, vtkCommand *, float priority=0.0f)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
vtkCommandGetCommand (unsigned long tag)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
void RemoveObserver (vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
void RemoveObservers (unsigned long event, vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
void RemoveObservers (const char *event, vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
vtkTypeBool HasObserver (unsigned long event, vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
vtkTypeBool HasObserver (const char *event, vtkCommand *)
 Allow people to add/remove/invoke observers (callbacks) to any VTK object.
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f)
 Overloads to AddObserver that allow developers to add class member functions as callbacks for events.
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 Overloads to AddObserver that allow developers to add class member functions as callbacks for events.
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 Allow user to set the AbortFlagOn() with the return value of the callback method.
 
vtkTypeBool InvokeEvent (unsigned long event, void *callData)
 This method invokes an event and return whether the event was aborted or not.
 
vtkTypeBool InvokeEvent (const char *event, void *callData)
 This method invokes an event and return whether the event was aborted or not.
 
virtual void SetObjectName (const std::string &objectName)
 Set/get the name of this object for reporting purposes.
 
virtual std::string GetObjectName () const
 Set/get the name of this object for reporting purposes.
 
- Public Member Functions inherited from vtkObjectBase
const char * GetClassName () const
 Return the class name as a string.
 
virtual std::string GetObjectDescription () const
 The object description printed in messages and PrintSelf output.
 
virtual vtkTypeBool IsA (const char *name)
 Return 1 if this class is the same type of (or a subclass of) the named class.
 
virtual vtkIdType GetNumberOfGenerationsFromBase (const char *name)
 Given the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class).
 
virtual void Delete ()
 Delete a VTK object.
 
virtual void FastDelete ()
 Delete a reference to this object.
 
void InitializeObjectBase ()
 
void Print (ostream &os)
 Print an object to an ostream.
 
void Register (vtkObjectBase *o)
 Increase the reference count (mark as used by another object).
 
virtual void UnRegister (vtkObjectBase *o)
 Decrease the reference count (release by another object).
 
int GetReferenceCount ()
 Return the current reference count of this object.
 
void SetReferenceCount (int)
 Sets the reference count.
 
bool GetIsInMemkind () const
 A local state flag that remembers whether this object lives in the normal or extended memory space.
 
virtual void PrintHeader (ostream &os, vtkIndent indent)
 Methods invoked by print to print information about the object including superclasses.
 
virtual void PrintTrailer (ostream &os, vtkIndent indent)
 Methods invoked by print to print information about the object including superclasses.
 
virtual bool UsesGarbageCollector () const
 Indicate whether the class uses vtkGarbageCollector or not.
 

Static Public Member Functions

static vtkTypeBool IsTypeOf (const char *type)
 
static vtkMarshalContextSafeDownCast (vtkObjectBase *o)
 
static vtkMarshalContextNew ()
 
- Static Public Member Functions inherited from vtkObject
static vtkObjectNew ()
 Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
 
static void BreakOnError ()
 This method is called when vtkErrorMacro executes.
 
static void SetGlobalWarningDisplay (vtkTypeBool val)
 This is a global flag that controls whether any debug, warning or error messages are displayed.
 
static void GlobalWarningDisplayOn ()
 This is a global flag that controls whether any debug, warning or error messages are displayed.
 
static void GlobalWarningDisplayOff ()
 This is a global flag that controls whether any debug, warning or error messages are displayed.
 
static vtkTypeBool GetGlobalWarningDisplay ()
 This is a global flag that controls whether any debug, warning or error messages are displayed.
 
- Static Public Member Functions inherited from vtkObjectBase
static vtkTypeBool IsTypeOf (const char *name)
 Return 1 if this class type is the same type of (or a subclass of) the named class.
 
static vtkIdType GetNumberOfGenerationsFromBaseType (const char *name)
 Given a the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class).
 
static vtkObjectBaseNew ()
 Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
 
static void SetMemkindDirectory (const char *directoryname)
 The name of a directory, ideally mounted -o dax, to memory map an extended memory space within.
 
static bool GetUsingMemkind ()
 A global state flag that controls whether vtkObjects are constructed in the usual way (the default) or within the extended memory space.
 

Protected Member Functions

virtual vtkObjectBaseNewInstanceInternal () const
 
 vtkMarshalContext ()
 
 ~vtkMarshalContext () override
 
bool HasId (vtkObjectBase *objectBase, vtkTypeUInt32 &identifier)
 Return true if objectBase exists in the weak object store, false otherwise If the objectBase exists, it's id will be stored in identifier.
 
bool IsProcessing (vtkTypeUInt32 identfier)
 Return true if identifier has been through PushParent, but not yet been through PopParent, false otherwise.
 
bool IsProcessed (vtkTypeUInt32 identifier)
 Returnstrue if identifier exists in the genealogy of object(s)/state(s), false otherwise.
 
void AddChild (vtkTypeUInt32 identifier)
 Records identifier in the list of children of the 'active' identifier.
 
- Protected Member Functions inherited from vtkObject
 vtkObject ()
 
 ~vtkObject () override
 
void RegisterInternal (vtkObjectBase *, vtkTypeBool check) override
 
void UnRegisterInternal (vtkObjectBase *, vtkTypeBool check) override
 
void InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr)
 These methods allow a command to exclusively grab all events.
 
void InternalReleaseFocus ()
 These methods allow a command to exclusively grab all events.
 
- Protected Member Functions inherited from vtkObjectBase
 vtkObjectBase ()
 
virtual ~vtkObjectBase ()
 
virtual void RegisterInternal (vtkObjectBase *, vtkTypeBool check)
 
virtual void UnRegisterInternal (vtkObjectBase *, vtkTypeBool check)
 
virtual void ReportReferences (vtkGarbageCollector *)
 
virtual void ObjectFinalize ()
 
 vtkObjectBase (const vtkObjectBase &)
 
void operator= (const vtkObjectBase &)
 

Friends

class vtkDeserializer
 
class vtkSerializer
 

Additional Inherited Members

- Static Protected Member Functions inherited from vtkObjectBase
static vtkMallocingFunction GetCurrentMallocFunction ()
 
static vtkReallocingFunction GetCurrentReallocFunction ()
 
static vtkFreeingFunction GetCurrentFreeFunction ()
 
static vtkFreeingFunction GetAlternateFreeFunction ()
 
- Protected Attributes inherited from vtkObject
bool Debug
 
vtkTimeStamp MTime
 
vtkSubjectHelper * SubjectHelper
 
std::string ObjectName
 
- Protected Attributes inherited from vtkObjectBase
std::atomic< int32_t > ReferenceCount
 
vtkWeakPointerBase ** WeakPointers
 

Detailed Description

Shared context used by vtkSerializer and vtkDeserializer

This class is capable of tracking dependencies among VTK objects, their states and preventing recursion when the VTK serialization classes are used.

It also provides centralized storage and tracking of objects in a weak object map, recording ownership of objects using a strong object map, hashing the contents of blobs to minimize data redundancies in the state and finally an API to coordinate the registration and removal of states, objects and blobs.

Definition at line 34 of file vtkMarshalContext.h.

Member Typedef Documentation

◆ Superclass

Definition at line 37 of file vtkMarshalContext.h.

◆ WeakObjectStore

Definition at line 41 of file vtkMarshalContext.h.

◆ StrongObjectStore

using vtkMarshalContext::StrongObjectStore = std::map<std::string, std::set<vtkSmartPointer<vtkObjectBase> >>

Definition at line 42 of file vtkMarshalContext.h.

Constructor & Destructor Documentation

◆ vtkMarshalContext()

vtkMarshalContext::vtkMarshalContext ( )
protected

◆ ~vtkMarshalContext()

vtkMarshalContext::~vtkMarshalContext ( )
overrideprotected

Member Function Documentation

◆ IsTypeOf()

static vtkTypeBool vtkMarshalContext::IsTypeOf ( const char *  type)
static

◆ IsA()

virtual vtkTypeBool vtkMarshalContext::IsA ( const char *  name)
virtual

Return 1 if this class is the same type of (or a subclass of) the named class.

Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkObjectBase.

◆ SafeDownCast()

static vtkMarshalContext * vtkMarshalContext::SafeDownCast ( vtkObjectBase o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkMarshalContext::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkMarshalContext * vtkMarshalContext::NewInstance ( ) const

◆ New()

static vtkMarshalContext * vtkMarshalContext::New ( )
static

◆ PrintSelf()

void vtkMarshalContext::PrintSelf ( ostream &  os,
vtkIndent  indent 
)
overridevirtual

Methods invoked by print to print information about the object including superclasses.

Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from vtkObjectBase.

◆ Blobs()

const nlohmann::json & vtkMarshalContext::Blobs ( ) const

Get blobs.

◆ States()

const nlohmann::json & vtkMarshalContext::States ( ) const

Get states.

◆ WeakObjects()

const WeakObjectStore & vtkMarshalContext::WeakObjects ( ) const

Get map of weak objects.

◆ StrongObjects()

const StrongObjectStore & vtkMarshalContext::StrongObjects ( ) const

Get map of strong objects.

◆ KeepAlive()

void vtkMarshalContext::KeepAlive ( const std::string &  owner,
vtkObjectBase objectBase 
)

This method creates a record of ownership between owner and objectBase.

◆ Retire()

void vtkMarshalContext::Retire ( const std::string &  owner,
vtkObjectBase objectBase 
)

Release the strong reference kept by owner to the given objectBase.

This method does nothing if the records show that owner doesn't own objectBase.

◆ RegisterState()

bool vtkMarshalContext::RegisterState ( nlohmann::json  state)

Add a state.

Returns true if the state was registered, false otherwise.

Note
The state is successfully registered only if a key named "Id" exists in state and it's value is an unsigned integer.

◆ UnRegisterState()

bool vtkMarshalContext::UnRegisterState ( vtkTypeUInt32  identifier)

Removes a state.

Returns true if a state exists at identifier and it was removed, false otherwise.

◆ GetState()

nlohmann::json & vtkMarshalContext::GetState ( vtkTypeUInt32  identifier) const

Find and get the state registered at identifier.

Returns an empty json object if there is no state registered at identifier.

◆ RegisterObject()

bool vtkMarshalContext::RegisterObject ( vtkObjectBase objectBase,
vtkTypeUInt32 &  identifier 
)

Add an objectBase into the weak object store associated with identifier.

If identifier is 0, a new identifier will be created. Returns true if the objectBase was registered, false otherwise.

Note
The objectBase is successfully registered only if it is non-null.

◆ UnRegisterObject()

bool vtkMarshalContext::UnRegisterObject ( vtkTypeUInt32  identifier)

Removes an objectBase registered at identifier from the weak object store.

Returns true if a objectBase exists at identifier and it was removed, false otherwise.

◆ GetObjectAtId()

vtkSmartPointer< vtkObjectBase > vtkMarshalContext::GetObjectAtId ( vtkTypeUInt32  identifier) const

Find and get the objectBase registered at identifier.

◆ GetId()

vtkTypeUInt32 vtkMarshalContext::GetId ( vtkObjectBase objectBase) const

Get the identifier associated with objectBase.

◆ RegisterBlob()

bool vtkMarshalContext::RegisterBlob ( vtkSmartPointer< vtkTypeUInt8Array >  blob,
std::string &  hash 
)

Add a blob into the blob store associated with hash.

If hash is an empty string, the contents of blob will be hashed and the result of the hashing algorithm stored in hash. Returns true if the blob was registered, false otherwise.

Note
The blob is successfully registered only if it is non-null. This method accepts empty blobs.

◆ UnRegisterBlob()

bool vtkMarshalContext::UnRegisterBlob ( const std::string &  hash)

Removes a blob registered at hash from the blob store.

Returns true if a blob exists at hash and it was removed, false otherwise.

◆ GetBlob()

vtkSmartPointer< vtkTypeUInt8Array > vtkMarshalContext::GetBlob ( const std::string &  hash)

Find and get the blob registered at hash.

◆ GetDirectDependencies()

std::vector< vtkTypeUInt32 > vtkMarshalContext::GetDirectDependencies ( vtkTypeUInt32  identifier) const

Return all direct dependencies of the object/state registered at identifier.

Note
This method doesn't compute the dependencies on demand. Instead it relies upon the vtkSerializer/vtkDeserializer correctly using the ScopedParentTracker API to record the genealogy of object(s)/state(s) serialized/deserialized.

Technically, it's not a strict genealogy as it is possible to have circular dependencies.

◆ ResetDirectDependencies()

void vtkMarshalContext::ResetDirectDependencies ( )

Reset the dependency cache.

◆ ResetDirectDependenciesForNode()

void vtkMarshalContext::ResetDirectDependenciesForNode ( vtkTypeUInt32  identifier)

Reset the dependency cache for the given identifier

◆ MakeId()

vtkTypeUInt32 vtkMarshalContext::MakeId ( )

Make a new identifier.

◆ PushParent()

void vtkMarshalContext::PushParent ( vtkTypeUInt32  identifier)

Make identifier the active identifier.

All subsequent AddChild(child) will add child into the list of children for identifier until PopParent gets invoked.

◆ PopParent()

void vtkMarshalContext::PopParent ( )

Adds the 'active' identifier into the genealogy.

It's children are populated using the recorded children of the 'active' identifier using AddChild The active parent is reset to the previous identifier.

◆ HasId()

bool vtkMarshalContext::HasId ( vtkObjectBase objectBase,
vtkTypeUInt32 &  identifier 
)
protected

Return true if objectBase exists in the weak object store, false otherwise If the objectBase exists, it's id will be stored in identifier.

Note
This is just a convenient method that wraps around GetId.

◆ IsProcessing()

bool vtkMarshalContext::IsProcessing ( vtkTypeUInt32  identfier)
protected

Return true if identifier has been through PushParent, but not yet been through PopParent, false otherwise.

◆ IsProcessed()

bool vtkMarshalContext::IsProcessed ( vtkTypeUInt32  identifier)
protected

Returnstrue if identifier exists in the genealogy of object(s)/state(s), false otherwise.

◆ AddChild()

void vtkMarshalContext::AddChild ( vtkTypeUInt32  identifier)
protected

Records identifier in the list of children of the 'active' identifier.

Note
  1. This parent-child relationship is not commited into the genealogy until PopParent is invoked.
  2. This method does nothing if there is no 'active' identfier, i.e, when PushParent(identifier) was never called.

Friends And Related Symbol Documentation

◆ vtkDeserializer

friend class vtkDeserializer
friend

Definition at line 270 of file vtkMarshalContext.h.

◆ vtkSerializer

friend class vtkSerializer
friend

Definition at line 271 of file vtkMarshalContext.h.


The documentation for this class was generated from the following file: