VTK  9.3.20240907
vtkSerializer.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
7#ifndef vtkSerializer_h
8#define vtkSerializer_h
9
10#include "vtkObject.h"
11
12#include "vtkCommonCoreModule.h" // for export macro
13#include "vtkMarshalContext.h" // for vtkMarshalContext
14#include "vtkSmartPointer.h" // for vktSmartPointer
15
16// clang-format off
17#include "vtk_nlohmannjson.h" // for json
18#include VTK_NLOHMANN_JSON(json.hpp) // for json
19// clang-format on
20
21#include <memory> // for unique_ptr
22#include <typeinfo> // for type_info
23
24VTK_ABI_NAMESPACE_BEGIN
25
26class VTKCOMMONCORE_EXPORT vtkSerializer : public vtkObject
27{
28public:
29 static vtkSerializer* New();
30 vtkTypeMacro(vtkSerializer, vtkObject);
31 void PrintSelf(ostream& os, vtkIndent indent) override;
32
33 using HandlerType = std::function<nlohmann::json(vtkObjectBase*, vtkSerializer*)>;
34
38 nlohmann::json SerializeJSON(vtkObjectBase* objectBase);
39
41
48 void RegisterHandler(const std::type_info& type, HandlerType handler);
49 HandlerType GetHandler(const std::type_info& type) const;
50 bool UnRegisterHandler(const std::type_info& type);
52
54
66
67protected:
69 ~vtkSerializer() override;
70
72
73private:
74 vtkSerializer(const vtkSerializer&) = delete;
75 void operator=(const vtkSerializer&) = delete;
76 class vtkInternals;
77 std::unique_ptr<vtkInternals> Internals;
78};
79VTK_ABI_NAMESPACE_END
80#endif
a simple class to control print indentation
Definition vtkIndent.h:108
Shared context used by vtkSerializer and vtkDeserializer
abstract base class for most VTK objects
abstract base class for most VTK objects
Definition vtkObject.h:162
Serialize VTK objects to JSON.
vtkGetSmartPointerMacro(Context, vtkMarshalContext)
Get/Set the marshalling context.
HandlerType GetHandler(const std::type_info &type) const
The handlers are invoked to serialize an object of type type.
nlohmann::json SerializeJSON(vtkObjectBase *objectBase)
Serialize the VTK object.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool UnRegisterHandler(const std::type_info &type)
The handlers are invoked to serialize an object of type type.
static vtkSerializer * New()
vtkSmartPointer< vtkMarshalContext > Context
vtkSetSmartPointerMacro(Context, vtkMarshalContext)
Get/Set the marshalling context.
std::function< nlohmann::json(vtkObjectBase *, vtkSerializer *)> HandlerType
~vtkSerializer() override
void RegisterHandler(const std::type_info &type, HandlerType handler)
The handlers are invoked to serialize an object of type type.
Hold a reference to a vtkObjectBase instance.