VTK  9.4.2
vtkObjectManager.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
19#ifndef vtkObjectManager_h
20#define vtkObjectManager_h
21
22#include "vtkObject.h"
23
24#include "vtkDeserializer.h" // for vtkDeserializer
25#include "vtkNew.h" // for vtkNew
26#include "vtkSerializationManagerModule.h" // for export macro
27#include "vtkSerializer.h" // for vtkSerializer
28#include "vtkSmartPointer.h" // for vtkSmartPointer
29
30#include <string> // for string
31#include <vector> // for vector
32
33VTK_ABI_NAMESPACE_BEGIN
35class vtkTypeUInt8Array;
36
37class VTKSERIALIZATIONMANAGER_EXPORT vtkObjectManager : public vtkObject
38{
39public:
42 void PrintSelf(ostream& os, vtkIndent indent) override;
43
45
48 virtual bool Initialize();
51
55 using RegistrarType = std::function<int(void* ser, void* deser, const char** error)>;
56 bool InitializeExtensionModuleHandlers(const std::vector<RegistrarType>& registrars);
57
63
68 bool UnRegisterObject(vtkTypeUInt32 identifier);
69
76 bool RegisterState(const std::string& state);
77
81 bool UnRegisterState(vtkTypeUInt32 identifier);
82
88 vtkTypeUInt32 GetId(vtkSmartPointer<vtkObjectBase> objectBase);
89
95 std::string GetState(vtkTypeUInt32 id);
96
102
109 std::vector<vtkTypeUInt32> GetAllDependencies(vtkTypeUInt32 identifier);
110
115 std::vector<std::string> GetBlobHashes(const std::vector<vtkTypeUInt32>& ids);
116
120 vtkSmartPointer<vtkTypeUInt8Array> GetBlob(const std::string& hash) const;
121
126 bool RegisterBlob(const std::string& hash, vtkSmartPointer<vtkTypeUInt8Array> blob);
127
131 bool UnRegisterBlob(const std::string& hash);
132
138
143
148
152 void UpdateObjectFromState(const std::string& state);
153
157 void UpdateStateFromObject(vtkTypeUInt32 identifier);
158
165 void Clear();
166
169
174 void Export(const std::string& filename, int indentLevel = -1, char indentChar = ' ');
175
181 void Import(const std::string& stateFileName, const std::string& blobFileName);
182
183 static vtkTypeUInt32 ROOT() { return 0; }
184
185 vtkGetSmartPointerMacro(Serializer, vtkSerializer);
186 vtkGetSmartPointerMacro(Deserializer, vtkDeserializer);
187
188protected:
191
195
196 static const char* OWNERSHIP_KEY() { return "manager"; }
197
202
207
208private:
209 vtkObjectManager(const vtkObjectManager&) = delete;
210 void operator=(const vtkObjectManager&) = delete;
211};
212VTK_ABI_NAMESPACE_END
213#endif
Deserialize VTK objects from JSON.
a simple class to control print indentation
Definition vtkIndent.h:108
Shared context used by vtkSerializer and vtkDeserializer
Allocate and hold a VTK object.
Definition vtkNew.h:167
vtkObjectManager maintains internal instances of vtkSerializer and a vtkDeserializer to serialize and...
void Import(const std::string &stateFileName, const std::string &blobFileName)
Reads state from state file and blobs from blob file.
bool InitializeDefaultHandlers()
Loads the default (de)serialization handlers and constructors for VTK classes.
void UpdateObjectFromState(const std::string &state)
Deserialize the state into vtk object.
bool RegisterState(const std::string &state)
Adds state into an internal container and returns a unique identifier.
bool UnRegisterObject(vtkTypeUInt32 identifier)
Removes an object and it's state.
vtkNew< vtkDeserializer > Deserializer
vtkSmartPointer< vtkTypeUInt8Array > GetBlob(const std::string &hash) const
Returns a blob stored at hash.
void UpdateStatesFromObjects()
Serialize registered objects into vtk states.
bool UnRegisterBlob(const std::string &hash)
Removes a blob stored at hash.
vtkSmartPointer< vtkObjectBase > GetObjectAtId(vtkTypeUInt32 id)
Get object at id.
void Export(const std::string &filename, int indentLevel=-1, char indentChar=' ')
Writes state of all registered objects to filename.json The blobs are written into filename....
vtkSmartPointer< vtkMarshalContext > Context
bool InitializeExtensionModuleHandlers(const std::vector< RegistrarType > &registrars)
std::size_t GetTotalBlobMemoryUsage()
void PruneUnusedObjects()
Removes all objects that are neither referenced by this manager or any other object.
~vtkObjectManager() override
bool UnRegisterState(vtkTypeUInt32 identifier)
Removes a state at id.
void UpdateObjectsFromStates()
Deserialize registered states into vtk objects.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkNew< vtkSerializer > Serializer
void PruneUnusedStates()
Removes all objects that are neither referenced by this manager or any other object.
static vtkTypeUInt32 ROOT()
void UpdateStateFromObject(vtkTypeUInt32 identifier)
Serialize object at identifier into the state.
vtkTypeUInt32 RegisterObject(vtkSmartPointer< vtkObjectBase > objectBase)
Adds object into an internal container and returns a unique identifier.
vtkTypeUInt32 GetId(vtkSmartPointer< vtkObjectBase > objectBase)
Get the identifier for object.
bool RegisterBlob(const std::string &hash, vtkSmartPointer< vtkTypeUInt8Array > blob)
Specifies a blob for hash.
virtual bool Initialize()
Loads the default (de)serialization handlers and constructors for VTK classes.
void PruneUnusedBlobs()
Removes all blob(s) whose hash is not found in the state of any object registered directly or indirec...
std::vector< std::string > GetBlobHashes(const std::vector< vtkTypeUInt32 > &ids)
Returns a non-empty vector of hash strings that correspond to blobs used by the registered objects at...
std::size_t GetTotalVTKDataObjectMemoryUsage()
std::vector< vtkTypeUInt32 > GetAllDependencies(vtkTypeUInt32 identifier)
Returns a non-empty vector of identifiers of all objects that depend on an object with the given iden...
std::function< int(void *ser, void *deser, const char **error)> RegistrarType
Loads user provided handlers.
std::string GetState(vtkTypeUInt32 id)
Get state of the object at id.
static vtkObjectManager * New()
static const char * OWNERSHIP_KEY()
void Clear()
Reset to initial state.
abstract base class for most VTK objects
Definition vtkObject.h:162
Serialize VTK objects to JSON.
Hold a reference to a vtkObjectBase instance.