smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
Graph.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstdint>
6#include <memory>
7#include <unordered_map>
8#include <vector>
9
10#include "smgl/Node.hpp"
11#include "smgl/Uuid.hpp"
12#include "smgl/filesystem.hpp"
13
14namespace smgl
15{
16
17// Pre-declare for Graphviz
18class GraphStyle;
19
21enum class CacheType {
23 Adjacent = 0,
26};
27
32{
33public:
35 constexpr static std::uint32_t Version{1};
36
38 enum class State { Idle, Updating, Error };
39
41 auto operator[](const Uuid& uuid) const -> Node::Pointer;
42
44 void insertNode(const Node::Pointer& n);
45
47 template <typename NodeType, typename... Args>
48 auto insertNode(Args... args) -> std::shared_ptr<NodeType>;
49
51 template <typename N, typename... Ns>
52 void insertNodes(N& n0, Ns&&... nodes);
53
55 void removeNode(const Node::Pointer& n);
56
58 auto size() const -> std::size_t;
59
61 auto state() const -> State;
62
70 auto cacheFile() const -> filesystem::path;
71
77 void setCacheFile(const filesystem::path& p);
78
85 auto cacheType() const -> CacheType;
86
93
98 auto cacheDir() const -> filesystem::path;
99
105 auto cacheEnabled() const -> bool;
106
112 void setEnableCache(bool enable);
113
116
118 auto projectMetadata() const -> const Metadata&;
119
122
128 auto update() -> State;
129
136 static auto Serialize(const Graph& g) -> Metadata;
137
148 static auto Save(
149 const filesystem::path& path, const Graph& g, bool writeCache = false)
150 -> void;
151
161 static auto Load(const filesystem::path& path) -> Graph;
162
173 static auto CheckRegistration(const filesystem::path& path)
174 -> std::vector<std::string>;
175
189 static auto CheckRegistration(const Graph& g) -> std::vector<std::string>;
190
198 static auto Schedule(const Graph& g) -> std::vector<Node::Pointer>;
199
200private:
206 bool cache_enabled_{false};
210 State state_{State::Idle};
213
215 static auto Serialize(
216 const Graph& g, bool useCache, const filesystem::path& cacheDir)
217 -> Metadata;
218
220 friend auto WriteDotFile(
221 const filesystem::path& path, const Graph& g, const GraphStyle& style)
222 -> void;
223};
224
225} // namespace smgl
226
227#include "smgl/GraphImpl.hpp"
Class defining a Graph's style when writing to a Dot file.
Definition Graphviz.hpp:101
A collection of Nodes for managing pipeline state and serialization.
Definition Graph.hpp:32
static auto Schedule(const Graph &g) -> std::vector< Node::Pointer >
Generate an update schedule for the provided Graph.
auto cacheFile() const -> filesystem::path
Get the root cache file for the Graph.
CacheType cacheType_
Definition Graph.hpp:204
auto cacheEnabled() const -> bool
Whether or not graph caching is enabled.
auto size() const -> std::size_t
Get the number of nodes in the graph.
State state_
Definition Graph.hpp:210
void insertNodes(N &n0, Ns &&... nodes)
Add one or more Nodes to the Graph.
static auto Save(const filesystem::path &path, const Graph &g, bool writeCache=false) -> void
Save a Graph to a JSON file.
auto cacheDir() const -> filesystem::path
Returns the cache directory as configured by cacheFile() and cacheType()
void setCacheFile(const filesystem::path &p)
Set the root cache file for the Graph.
static auto Load(const filesystem::path &path) -> Graph
Load a Graph from a JSON file.
void setCacheType(CacheType t)
Set the graph's CacheType.
static constexpr std::uint32_t Version
Definition Graph.hpp:35
filesystem::path cacheFile_
Definition Graph.hpp:202
std::unordered_map< Uuid, Node::Pointer > nodes_
Definition Graph.hpp:208
void setProjectMetadata(const Metadata &m)
Set the project metadata.
static auto CheckRegistration(const filesystem::path &path) -> std::vector< std::string >
Checks that a Graph JSON file can be loaded.
static auto Serialize(const Graph &g, bool useCache, const filesystem::path &cacheDir) -> Metadata
void setEnableCache(bool enable)
Set whether or not graph caching is enabled.
auto update() -> State
Update the Graph's nodes.
friend auto WriteDotFile(const filesystem::path &path, const Graph &g, const GraphStyle &style) -> void
Write Graph to a file in the Graphviz Dot format.
static auto Serialize(const Graph &g) -> Metadata
Serialize a Graph to a Metadata object.
Metadata extraMetadata_
Definition Graph.hpp:212
auto operator[](const Uuid &uuid) const -> Node::Pointer
Get a Node by Uuid.
void insertNode(const Node::Pointer &n)
Add a Node to the Graph.
bool cache_enabled_
Definition Graph.hpp:206
auto cacheType() const -> CacheType
Get the graph's CacheType.
void removeNode(const Node::Pointer &n)
Remove a Node from the Graph.
auto state() const -> State
Get the current graph state.
auto projectMetadata() const -> const Metadata &
Get the project metadata.
Generic Node class.
Definition Node.hpp:70
std::shared_ptr< Node > Pointer
Definition Node.hpp:87
Base class for objects which are uniquely identifiable.
Definition Uuid.hpp:77
auto uuid() const -> Uuid
Universally unique identifier class.
Definition Uuid.hpp:18
Project top-level namespace.
CacheType
Cache Location Type.
Definition Graph.hpp:21
nlohmann::ordered_json Metadata
Metadata storage class.
Definition Metadata.hpp:12
@ Error
Error messages and above.
Definition Logging.hpp:23
ISO C++ top-level namespace.