7#ifndef vtkDeserializer_h
8#define vtkDeserializer_h
12#include "vtkCommonCoreModule.h"
18#include "vtk_nlohmannjson.h"
19#include VTK_NLOHMANN_JSON(json_fwd.hpp)
25VTK_ABI_NAMESPACE_BEGIN
58 const std::string& className,
const std::vector<std::string>& superClassNames);
81 const std::string& className,
const std::vector<std::string>& superClassNames);
141 std::unique_ptr<vtkInternals> Internals;
147#define VTK_DESERIALIZE_VALUE_FROM_STATE(name, type, state, object) \
150 const auto iter = state.find(#name); \
151 if ((iter != state.end()) && !iter->is_null()) \
153 object->Set##name(iter->get<type>()); \
162#define VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE_DIFFERENT_NAMES( \
163 stateKey, propertyName, cls, state, object, deserializer) \
166 const auto iter = state.find(#stateKey); \
167 if ((iter != state.end()) && !iter->is_null()) \
169 const auto* context = deserializer->GetContext(); \
170 const auto identifier = iter->at("Id").get<vtkTypeUInt32>(); \
171 auto subObject = context->GetObjectAtId(identifier); \
172 deserializer->DeserializeJSON(identifier, subObject); \
173 if (auto* asVtkType = cls::SafeDownCast(subObject)) \
175 object->Set##propertyName(asVtkType); \
183#define VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE(name, cls, state, object, deserializer) \
184 VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE_DIFFERENT_NAMES( \
185 name, name, cls, state, object, deserializer)
191#define VTK_DESERIALIZE_VECTOR_FROM_STATE(name, type, state, object) \
194 const auto iter = state.find(#name); \
195 if ((iter != state.end()) && !iter->is_null()) \
197 using namespace std; \
198 const auto elements = iter->get<vector<type>>(); \
199 object->Set##name(elements.data()); \
Deserialize VTK objects from JSON.
bool UnRegisterHandler(const std::type_info &type)
The handlers are invoked to deserialize a json state into a vtkObjectBase derived instance of type ty...
void SetDeserializerLogVerbosity(vtkLogger::Verbosity verbosity)
Set/Get the log verbosity of messages that are emitted when data is uploaded to GPU memory.
std::function< void(const nlohmann::json &, vtkObjectBase *, vtkDeserializer *)> HandlerType
vtkLogger::Verbosity GetDeserializerLogVerbosity()
Set/Get the log verbosity of messages that are emitted when data is uploaded to GPU memory.
void RegisterConstructor(const std::string &className, ConstructorType constructor)
The constructors are invoked to construct an instance of className.
vtkSmartPointer< vtkMarshalContext > Context
ConstructorType GetConstructor(const std::string &className, const std::vector< std::string > &superClassNames)
The constructors are invoked to construct an instance of className.
static vtkDeserializer * New()
void UnRegisterConstructor(const std::string &className)
The constructors are invoked to construct an instance of className.
HandlerType GetHandler(const std::type_info &type) const
The handlers are invoked to deserialize a json state into a vtkObjectBase derived instance of type ty...
std::function< vtkObjectBase *()> ConstructorType
~vtkDeserializer() override
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool DeserializeJSON(const vtkTypeUInt32 &identifier, vtkSmartPointer< vtkObjectBase > &objectBase)
Deserialize a state registered with the context at identifier into objectBase.
vtkObjectBase * ConstructObject(const std::string &className, const std::vector< std::string > &superClassNames)
Constructs an object of type className.
void RegisterHandler(const std::type_info &type, HandlerType deserializer)
The handlers are invoked to deserialize a json state into a vtkObjectBase derived instance of type ty...
a simple class to control print indentation
Shared context used by vtkSerializer and vtkDeserializer
abstract base class for most VTK objects
abstract base class for most VTK objects
Hold a reference to a vtkObjectBase instance.