SENSEI
A frame work for generic in situ analytics
ProgrammableDataAdaptor.h
1 #ifndef sensei_ProgrammableDataAdaptor_h
2 #define sensei_ProgrammableDataAdaptor_h
3 
4 #include "senseiConfig.h"
5 #include "DataAdaptor.h"
6 
7 #include <string>
8 #include <functional>
9 
10 namespace sensei
11 {
12 
13 /** Implements the sensei::DataAdaptor interface with user provided callables
14  * ProgrammableDataAdaptor allows one to provide callbacks implementing
15  * the data interface. This is an alternative to using polymorphism.
16  * Callbacks can be any callable including functors and C function pointers
17  */
18 class SENSEI_EXPORT ProgrammableDataAdaptor : public DataAdaptor
19 {
20 public:
21  static ProgrammableDataAdaptor *New();
22  senseiTypeMacro(ProgrammableDataAdaptor, DataAdaptor);
23 
24  using GetNumberOfMeshesFunction = std::function<int(unsigned int&)>;
25 
26  using GetMeshMetadataFunction =
27  std::function<int(unsigned int, MeshMetadataPtr &)>;
28 
29  using GetMeshFunction =
30  std::function<int(const std::string &, bool, svtkDataObject *&)>;
31 
32  using AddArrayFunction = std::function<int(svtkDataObject*,
33  const std::string &, int, const std::string &)>;
34 
35  using ReleaseDataFunction = std::function<int()>;
36 
37  /** Set the callable that will be invoked when GetNumberOfMeshes is called
38  * See GetNumberOfMeshes for details of what the callback must do.
39  */
40  void SetGetNumberOfMeshesCallback(const GetNumberOfMeshesFunction &callback);
41 
42  /** Set the callable that will be invoked when GetMeshMetadata is called
43  * See GetMeshMetadata for details of what the callback must do.
44  */
45  void SetGetMeshMetadataCallback(const GetMeshMetadataFunction &callback);
46 
47  /** Set the callable that will be invoked when GetMesh is called
48  * See GetMesh for details of what the callback must do.
49  */
50  void SetGetMeshCallback(const GetMeshFunction &callback);
51 
52  /** Set the callable that will be invoked when AddArray is called
53  * See AddArray for details of what the callback must do.
54  */
55  void SetAddArrayCallback(const AddArrayFunction &callback);
56 
57  /** Set the callable that will be invoked when ReleaseData is called.
58  * See ReleaseData for details about wwhat the callback should do.
59  */
60  void SetReleaseDataCallback(const ReleaseDataFunction &callback);
61 
62  int GetNumberOfMeshes(unsigned int &numMeshes) override;
63 
64  int GetMeshMetadata(unsigned int id, MeshMetadataPtr &metadata) override;
65 
66  int GetMesh(const std::string &meshName, bool structureOnly,
67  svtkDataObject *&mesh) override;
68 
69  int AddArray(svtkDataObject* mesh, const std::string &meshName,
70  int association, const std::string &arrayName) override;
71  int ReleaseData() override;
72 
73 protected:
76 
77  // callbacks
78  GetNumberOfMeshesFunction GetNumberOfMeshesCallback;
79  GetMeshMetadataFunction GetMeshMetadataCallback;
80  GetMeshFunction GetMeshCallback;
81  AddArrayFunction AddArrayCallback;
82  ReleaseDataFunction ReleaseDataCallback;
83 
84 private:
86  void operator=(const ProgrammableDataAdaptor&) = delete;
87 };
88 
89 }
90 #endif
SENSEI.
Definition: ADIOS2AnalysisAdaptor.h:27
Implements the sensei::DataAdaptor interface with user provided callables ProgrammableDataAdaptor all...
Definition: ProgrammableDataAdaptor.h:18
Base class that defines the interface for fetching data from a simulation.
Definition: DataAdaptor.h:25