VTK  9.4.20250421
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
10#ifndef vtkSerializer_h
11#define vtkSerializer_h
12
13#include "vtkObject.h"
14
15#include "vtkCommonCoreModule.h" // for export macro
16#include "vtkLogger.h" // for vtkLogger::Verbosity enum
17#include "vtkMarshalContext.h" // for vtkMarshalContext
18#include "vtkSmartPointer.h" // for vktSmartPointer
19
20// clang-format off
21#include "vtk_nlohmannjson.h" // for json
22#include VTK_NLOHMANN_JSON(json.hpp) // for json
23// clang-format on
24
25#include <memory> // for unique_ptr
26#include <typeinfo> // for type_info
27
28VTK_ABI_NAMESPACE_BEGIN
29
30class VTKCOMMONCORE_EXPORT vtkSerializer : public vtkObject
31{
32public:
33 static vtkSerializer* New();
34 vtkTypeMacro(vtkSerializer, vtkObject);
35 void PrintSelf(ostream& os, vtkIndent indent) override;
36
37 using HandlerType = std::function<nlohmann::json(vtkObjectBase*, vtkSerializer*)>;
38
42 nlohmann::json SerializeJSON(vtkObjectBase* objectBase);
43
45
52 void RegisterHandler(const std::type_info& type, HandlerType handler);
53 HandlerType GetHandler(const std::type_info& type) const;
54 bool UnRegisterHandler(const std::type_info& type);
56
58
67 vtkSetSmartPointerMacro(Context, vtkMarshalContext);
68 vtkGetSmartPointerMacro(Context, vtkMarshalContext);
70
72
87
88protected:
90 ~vtkSerializer() override;
91
94
95private:
96 vtkSerializer(const vtkSerializer&) = delete;
97 void operator=(const vtkSerializer&) = delete;
98 class vtkInternals;
99 std::unique_ptr<vtkInternals> Internals;
100};
101VTK_ABI_NAMESPACE_END
102#endif
a simple class to control print indentation
Definition vtkIndent.h:108
@ VERBOSITY_INVALID
Definition vtkLogger.h:214
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.
void SetSerializerLogVerbosity(vtkLogger::Verbosity verbosity)
Set/Get the log verbosity of messages that are emitted when data is uploaded to GPU memory.
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
std::function< nlohmann::json(vtkObjectBase *, vtkSerializer *)> HandlerType
~vtkSerializer() override
vtkLogger::Verbosity GetSerializerLogVerbosity()
Set/Get the log verbosity of messages that are emitted when data is uploaded to GPU memory.
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.