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) // for json
28 VTK_ABI_NAMESPACE_BEGIN
37 using HandlerType = std::function<bool(const nlohmann::json&, vtkObjectBase*, vtkDeserializer*)>;
61 const std::string& className,
const std::vector<std::string>& superClassNames);
84 const std::string& className,
const std::vector<std::string>& superClassNames);
85 void UnRegisterConstructor(
const std::string& className);
97 void RegisterHandler(
const std::type_info&
type,
HandlerType deserializer);
99 bool UnRegisterHandler(
const std::type_info&
type);
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 success &= 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()); \
206 VTK_ABI_NAMESPACE_END
Deserialize VTK objects from JSON.
abstract base class for most VTK objects
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Hold a reference to a vtkObjectBase instance.
std::function< vtkObjectBase *()> ConstructorType
a simple class to control print indentation
std::function< bool(const nlohmann::json &, vtkObjectBase *, vtkDeserializer *)> HandlerType
abstract base class for most VTK objects
Shared context used by vtkSerializer and vtkDeserializer
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkSmartPointer< vtkMarshalContext > Context