VTK  9.4.20250202
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 "vtkLogger.h" // for vtkLogger::Verbosity enum
14#include "vtkMarshalContext.h" // for vtkMarshalContext
15#include "vtkSmartPointer.h" // for vktSmartPointer
16
17// clang-format off
18#include "vtk_nlohmannjson.h" // for json
19#include VTK_NLOHMANN_JSON(json.hpp) // for json
20// clang-format on
21
22#include <memory> // for unique_ptr
23#include <typeinfo> // for type_info
24
25VTK_ABI_NAMESPACE_BEGIN
26
27class VTKCOMMONCORE_EXPORT vtkSerializer : public vtkObject
28{
29public:
30 static vtkSerializer* New();
31 vtkTypeMacro(vtkSerializer, vtkObject);
32 void PrintSelf(ostream& os, vtkIndent indent) override;
33
34 using HandlerType = std::function<nlohmann::json(vtkObjectBase*, vtkSerializer*)>;
35
39 nlohmann::json SerializeJSON(vtkObjectBase* objectBase);
40
42
49 void RegisterHandler(const std::type_info& type, HandlerType handler);
50 HandlerType GetHandler(const std::type_info& type) const;
51 bool UnRegisterHandler(const std::type_info& type);
53
55
67
69
84
85protected:
87 ~vtkSerializer() override;
88
91
92private:
93 vtkSerializer(const vtkSerializer&) = delete;
94 void operator=(const vtkSerializer&) = delete;
95 class vtkInternals;
96 std::unique_ptr<vtkInternals> Internals;
97};
98VTK_ABI_NAMESPACE_END
99#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.
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
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.