VTK  9.7.1
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 
28 VTK_ABI_NAMESPACE_BEGIN
29 
30 class VTKCOMMONCORE_EXPORT vtkSerializer : public vtkObject
31 {
32 public:
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 
84  void SetSerializerLogVerbosity(vtkLogger::Verbosity verbosity);
85  vtkLogger::Verbosity GetSerializerLogVerbosity();
87 
88 protected:
89  vtkSerializer();
90  ~vtkSerializer() override;
91 
94 
95 private:
96  vtkSerializer(const vtkSerializer&) = delete;
97  void operator=(const vtkSerializer&) = delete;
98  class vtkInternals;
99  std::unique_ptr<vtkInternals> Internals;
100 };
101 VTK_ABI_NAMESPACE_END
102 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::function< nlohmann::json(vtkObjectBase *, vtkSerializer *)> HandlerType
Definition: vtkSerializer.h:37
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract base class for most VTK objects
Definition: vtkObjectBase.h:68
Shared context used by vtkSerializer and vtkDeserializer
vtkSmartPointer< vtkMarshalContext > Context
Definition: vtkSerializer.h:92
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
Serialize VTK objects to JSON.
Definition: vtkSerializer.h:30