VTK  9.7.1
vtkInvoker.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 vtkInvoker_h
11 #define vtkInvoker_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_fwd.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 vtkInvoker : public vtkObject
31 {
32 public:
33  static vtkInvoker* New();
34  vtkTypeMacro(vtkInvoker, vtkObject);
35  void PrintSelf(ostream& os, vtkIndent indent) override;
36 
37  using HandlerType =
38  std::function<nlohmann::json(vtkInvoker*, vtkObjectBase*, const char*, const nlohmann::json&)>;
39 
40  nlohmann::json Invoke(
41  const vtkTypeUInt32& identifier, const std::string& methodName, const nlohmann::json& args);
42 
44 
51  void RegisterHandler(const std::type_info& type, HandlerType Invoker);
52  HandlerType GetHandler(const std::type_info& type) const;
53  bool UnRegisterHandler(const std::type_info& type);
55 
57 
62  vtkSetSmartPointerMacro(Context, vtkMarshalContext);
63  vtkGetSmartPointerMacro(Context, vtkMarshalContext);
65 
67 
79  void SetInvokerLogVerbosity(vtkLogger::Verbosity verbosity);
80  vtkLogger::Verbosity GetInvokerLogVerbosity();
82 
83 protected:
84  vtkInvoker();
85  ~vtkInvoker() override;
86 
89 
90 private:
91  vtkInvoker(const vtkInvoker&) = delete;
92  void operator=(const vtkInvoker&) = delete;
93  class vtkInternals;
94  std::unique_ptr<vtkInternals> Internals;
95 };
96 
97 VTK_ABI_NAMESPACE_END
98 #endif
Deserialize VTK objects from JSON.
Definition: vtkInvoker.h:30
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.
a simple class to control print indentation
Definition: vtkIndent.h:28
Shared context used by vtkSerializer and vtkDeserializer
vtkSmartPointer< vtkMarshalContext > Context
Definition: vtkInvoker.h:87
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
std::function< nlohmann::json(vtkInvoker *, vtkObjectBase *, const char *, const nlohmann::json &)> HandlerType
Definition: vtkInvoker.h:38