7#ifndef vtkDeserializer_h
8#define vtkDeserializer_h
12#include "vtkCommonCoreModule.h"
17#include "vtk_nlohmannjson.h"
18#include VTK_NLOHMANN_JSON(json_fwd.hpp)
24VTK_ABI_NAMESPACE_BEGIN
57 const std::string& className,
const std::vector<std::string>& superClassNames);
80 const std::string& className,
const std::vector<std::string>& superClassNames);
121 std::unique_ptr<vtkInternals> Internals;
127#define VTK_DESERIALIZE_VALUE_FROM_STATE(name, type, state, object) \
130 const auto iter = state.find(#name); \
131 if ((iter != state.end()) && !iter->is_null()) \
133 object->Set##name(iter->get<type>()); \
142#define VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE_DIFFERENT_NAMES( \
143 stateKey, propertyName, cls, state, object, deserializer) \
146 const auto iter = state.find(#stateKey); \
147 if ((iter != state.end()) && !iter->is_null()) \
149 const auto* context = deserializer->GetContext(); \
150 const auto identifier = iter->at("Id").get<vtkTypeUInt32>(); \
151 auto subObject = context->GetObjectAtId(identifier); \
152 deserializer->DeserializeJSON(identifier, subObject); \
153 if (auto* asVtkType = cls::SafeDownCast(subObject)) \
155 object->Set##propertyName(asVtkType); \
163#define VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE(name, cls, state, object, deserializer) \
164 VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE_DIFFERENT_NAMES( \
165 name, name, cls, state, object, deserializer)
171#define VTK_DESERIALIZE_VECTOR_FROM_STATE(name, type, state, object) \
174 const auto iter = state.find(#name); \
175 if ((iter != state.end()) && !iter->is_null()) \
177 using namespace std; \
178 const auto elements = iter->get<vector<type>>(); \
179 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...
std::function< void(const nlohmann::json &, vtkObjectBase *, vtkDeserializer *)> HandlerType
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.