10#ifndef vtkDeserializer_h
11#define vtkDeserializer_h
15#include "vtkCommonCoreModule.h"
21#include "vtk_nlohmannjson.h"
22#include VTK_NLOHMANN_JSON(json_fwd.hpp)
28VTK_ABI_NAMESPACE_BEGIN
61 const std::string& className,
const std::vector<std::string>& superClassNames);
84 const std::string& className,
const std::vector<std::string>& superClassNames);
144 std::unique_ptr<vtkInternals> Internals;
150#define VTK_DESERIALIZE_VALUE_FROM_STATE(name, type, state, object) \
153 const auto iter = state.find(#name); \
154 if ((iter != state.end()) && !iter->is_null()) \
156 object->Set##name(iter->get<type>()); \
165#define VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE_DIFFERENT_NAMES( \
166 stateKey, propertyName, cls, state, object, deserializer) \
169 const auto iter = state.find(#stateKey); \
170 if ((iter != state.end()) && !iter->is_null()) \
172 const auto* context = deserializer->GetContext(); \
173 const auto identifier = iter->at("Id").get<vtkTypeUInt32>(); \
174 auto subObject = context->GetObjectAtId(identifier); \
175 deserializer->DeserializeJSON(identifier, subObject); \
176 if (auto* asVtkType = cls::SafeDownCast(subObject)) \
178 object->Set##propertyName(asVtkType); \
186#define VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE(name, cls, state, object, deserializer) \
187 VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE_DIFFERENT_NAMES( \
188 name, name, cls, state, object, deserializer)
194#define VTK_DESERIALIZE_VECTOR_FROM_STATE(name, type, state, object) \
197 const auto iter = state.find(#name); \
198 if ((iter != state.end()) && !iter->is_null()) \
200 using namespace std; \
201 const auto elements = iter->get<vector<type>>(); \
202 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.