MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Graph.hpp
1 #pragma once
2 
3 #include "Export.hpp"
4 
5 #include "GraphTypes.hpp"
6 #include "Events.hpp"
7 
8 #include "ShowcaseTypes.hpp"
9 
10 #include "GraphGenerators.hpp"
11 
12 #include "ValueStream.hpp"
13 #include "GeneratorValueStream.hpp"
14 #include "ValueStreamChannels.hpp"
15 
16 #include <folly/futures/Future.h>
17 #include <folly/Executor.h>
18 
19 namespace Showcase
20 {
21  typedef ValueStreamPtr<NodeEvent> NodeEventStreamPtr;
22  typedef ValueStreamPtr<PropertyEvent> PropertyEventStreamPtr;
23 
24  typedef ShowcaseFactoryPtr<GraphGenerator> GraphGenFactoryPtr;
25  typedef ShowcaseFactoryPtr<PropertyGenerator> PropGenFactoryPtr;
26 
27 
29  class SHOWCASE_API Graph : public std::enable_shared_from_this<Graph>
30  {
31  public:
32  Graph(std::shared_ptr<folly::Executor> executor);
33 
34  ~Graph();
35 
38  NodeEventStreamPtr children(const GraphNode& node, std::shared_ptr<folly::Executor> executor = nullptr) const;
39  PropertyEventStreamPtr properties(const GraphNode& node, std::shared_ptr<folly::Executor> executor = nullptr) const;
40  PropertyEventStreamPtr properties(const GraphEdge& edge, std::shared_ptr<folly::Executor> executor = nullptr) const;
41 
42  // ------------ Initializing the graph for queries ---------------
43 
44  FactoryKey<GraphGenerator>
45  registerFactory(const QString& name, GraphGenFactoryPtr factory);
46 
47  FactoryKey<PropertyGenerator>
48  registerFactory(const QString& name, PropGenFactoryPtr factory);
49 
50  bool unregisterFactory(FactoryKey<GraphGenerator> key);
51  bool unregisterFactory(FactoryKey<PropertyGenerator> key);
52 
53  std::shared_ptr<folly::Executor> executor();
54 
55  private:
60  std::shared_ptr<GeneratorValueStream<PropertyGenerator>>
61  properties(const PropertyEvent& event) const;
62 
63  void initializeEventStream(std::shared_ptr<GeneratorValueStream<GraphGenerator>> stream) const;
64  void initializeEventStream(std::shared_ptr<GeneratorValueStream<PropertyGenerator>> stream) const;
65 
66  std::shared_ptr<folly::Executor> m_executor;
67 
69  FactoryMap<GraphGenerator> m_graphFactories;
70  FactoryMap<PropertyGenerator> m_propertyFactories;
71  };
72  typedef std::shared_ptr<Graph> GraphPtr;
73 
74 }