smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Private Member Functions | Private Attributes | Friends | List of all members
smgl::Graph Class Reference

A collection of Nodes for managing pipeline state and serialization. More...

#include <smgl/Graph.hpp>

Inheritance diagram for smgl::Graph:
[legend]
Collaboration diagram for smgl::Graph:
[legend]

Public Types

enum class  State { Idle , Updating , Error }
 

Public Member Functions

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.
 
template<typename NodeType , typename... Args>
auto insertNode (Args... args) -> std::shared_ptr< NodeType >
 Construct a Node and add it to the graph.
 
template<typename N , typename... Ns>
void insertNodes (N &n0, Ns &&... nodes)
 Add one or more Nodes to the Graph.
 
void removeNode (const Node::Pointer &n)
 Remove a Node from the Graph.
 
auto size () const -> std::size_t
 Get the number of nodes in the graph.
 
auto state () const -> State
 Get the current graph state.
 
auto cacheFile () const -> filesystem::path
 Get the root cache file for the Graph.
 
void setCacheFile (const filesystem::path &p)
 Set the root cache file for the Graph.
 
auto cacheType () const -> CacheType
 Get the graph's CacheType.
 
void setCacheType (CacheType t)
 Set the graph's CacheType.
 
auto cacheDir () const -> filesystem::path
 Returns the cache directory as configured by cacheFile() and cacheType()
 
auto cacheEnabled () const -> bool
 Whether or not graph caching is enabled.
 
void setEnableCache (bool enable)
 Set whether or not graph caching is enabled.
 
void setProjectMetadata (const Metadata &m)
 Set the project metadata.
 
auto projectMetadata () const -> const Metadata &
 Get the project metadata.
 
auto projectMetadata () -> Metadata &
 Get the project metadata.
 
auto update () -> State
 Update the Graph's nodes.
 
template<typename N , typename... Ns>
auto insertNodes (N &n0, Ns &&... nodes) -> void
 
- Public Member Functions inherited from smgl::UniquelyIdentifiable
auto uuid () const -> Uuid
 
void setUuid (const Uuid &uuid)
 

Static Public Member Functions

static auto Serialize (const Graph &g) -> Metadata
 Serialize a Graph to a Metadata object.
 
static auto Save (const filesystem::path &path, const Graph &g, bool writeCache=false) -> void
 Save a Graph to a JSON file.
 
static auto Load (const filesystem::path &path) -> Graph
 Load a Graph from a JSON file.
 
static auto CheckRegistration (const filesystem::path &path) -> std::vector< std::string >
 Checks that a Graph JSON file can be loaded.
 
static auto CheckRegistration (const Graph &g) -> std::vector< std::string >
 Checks that a Graph can be serialized.
 
static auto Schedule (const Graph &g) -> std::vector< Node::Pointer >
 Generate an update schedule for the provided Graph.
 

Static Public Attributes

static constexpr std::uint32_t Version {1}
 

Static Private Member Functions

static auto Serialize (const Graph &g, bool useCache, const filesystem::path &cacheDir) -> Metadata
 

Private Attributes

filesystem::path cacheFile_
 
CacheType cacheType_ {CacheType::Subdirectory}
 
bool cache_enabled_ {false}
 
std::unordered_map< Uuid, Node::Pointernodes_
 
State state_ {State::Idle}
 
Metadata extraMetadata_
 

Friends

auto WriteDotFile (const filesystem::path &path, const Graph &g, const GraphStyle &style) -> void
 Write Graph to a file in the Graphviz Dot format.
 

Additional Inherited Members

- Protected Member Functions inherited from smgl::UniquelyIdentifiable
 UniquelyIdentifiable ()=default
 
- Protected Attributes inherited from smgl::UniquelyIdentifiable
Uuid uuid_ {Uuid::Uuid4()}
 

Detailed Description

A collection of Nodes for managing pipeline state and serialization.

Definition at line 31 of file Graph.hpp.

Member Enumeration Documentation

◆ State

enum class smgl::Graph::State
strong

Graph state

Definition at line 38 of file Graph.hpp.

Member Function Documentation

◆ cacheEnabled()

auto smgl::Graph::cacheEnabled ( ) const -> bool

Whether or not graph caching is enabled.

If cacheEnabled() is true, Nodes are allowed to write data to a unique subdirectory in cacheDir(). The exact location is relative to cacheFile() and is determined by setCacheType().

◆ cacheFile()

auto smgl::Graph::cacheFile ( ) const -> filesystem::path

Get the root cache file for the Graph.

If cacheEnabled() is true, Nodes are allowed to write data to a unique subdirectory in cacheDir(). The exact location is relative to cacheFile() and is determined by setCacheType().

◆ cacheType()

auto smgl::Graph::cacheType ( ) const -> CacheType

Get the graph's CacheType.

A graph's CacheType determines the location of the cache relative to cacheFile().

◆ CheckRegistration() [1/2]

static auto smgl::Graph::CheckRegistration ( const filesystem::path path) -> std::vector< std::string >
static

Checks that a Graph JSON file can be loaded.

Checks that every Node in the Graph is registered with the serialization system. Returns the list of unregistered types as strings so that missing registrations can be handled appropriately before calling Graph::Load.

Parameters
pathPath to input file in the JSON format
Returns
List of Node types that are not registered for serialization

◆ CheckRegistration() [2/2]

static auto smgl::Graph::CheckRegistration ( const Graph g) -> std::vector< std::string >
static

Checks that a Graph can be serialized.

Checks that every Node in the Graph is registered with the serialization system. Returns the list of unregistered types as strings so that missing registrations can be handled appropriately before calling Graph::Load. Because unregistered types have no source-token key, the returned strings are the raw typeid().name() of each unregistered Node (mangled on GCC/Clang, readable on MSVC).

Parameters
gGraph to be checked
Returns
List of Node types that are not registered for serialization

◆ insertNode()

template<typename NodeType , typename... Args>
auto smgl::Graph::insertNode ( Args...  args) -> std::shared_ptr<NodeType>

Construct a Node and add it to the graph.

Definition at line 5 of file GraphImpl.hpp.

◆ insertNodes()

template<typename N , typename... Ns>
auto smgl::Graph::insertNodes ( N &  n0,
Ns &&...  nodes 
) -> void

Definition at line 13 of file GraphImpl.hpp.

◆ Load()

static auto smgl::Graph::Load ( const filesystem::path path) -> Graph
static

Load a Graph from a JSON file.

Note
Loaded Graph does not share state with any preexisting Graph. See issue #9.
Parameters
pathPath to input file in the JSON format

◆ projectMetadata()

auto smgl::Graph::projectMetadata ( ) -> Metadata &

Get the project metadata.

◆ Save()

static auto smgl::Graph::Save ( const filesystem::path path,
const Graph g,
bool  writeCache = false 
) -> void
static

Save a Graph to a JSON file.

If writeCache is true, cache information will be written adjacent to the provided path honoring the cacheType() configuration.

Parameters
pathPath to output file
gGraph to be saved
writeCacheWhether or not to write cache files

◆ Schedule()

static auto smgl::Graph::Schedule ( const Graph g) -> std::vector< Node::Pointer >
static

Generate an update schedule for the provided Graph.

Traverses the Graph and produces an ordered schedule for updating Nodes. Graph must have at least one Node with no input connections and must be acyclic.

◆ Serialize() [1/2]

static auto smgl::Graph::Serialize ( const Graph g) -> Metadata
static

Serialize a Graph to a Metadata object.

Warning
This function honors the value of cacheEnabled() and will write data to cacheDir().

◆ Serialize() [2/2]

static auto smgl::Graph::Serialize ( const Graph g,
bool  useCache,
const filesystem::path cacheDir 
) -> Metadata
staticprivate

Perform graph serialization

◆ setCacheFile()

void smgl::Graph::setCacheFile ( const filesystem::path p)

Set the root cache file for the Graph.

If cacheEnabled() is true, Nodes are allowed to write data to a unique subdirectory in cacheDir(). The exact location is relative to cacheFile() and is determined by setCacheType().

◆ setCacheType()

void smgl::Graph::setCacheType ( CacheType  t)

Set the graph's CacheType.

A graph's CacheType determines the location of the cache relative to cacheFile().

◆ setEnableCache()

void smgl::Graph::setEnableCache ( bool  enable)

Set whether or not graph caching is enabled.

If cacheEnabled() is true, Nodes are allowed to write data to a unique subdirectory in cacheDir(). The exact location is relative to cacheFile() and is determined by setCacheType().

◆ update()

auto smgl::Graph::update ( ) -> State

Update the Graph's nodes.

Schedules the Nodes of the Graph and update them as needed.

Friends And Related Symbol Documentation

◆ WriteDotFile

auto WriteDotFile ( const filesystem::path path,
const Graph g,
const GraphStyle style 
) -> void
friend

Write Graph to a file in the Graphviz Dot format.

Friend function: Graphviz WriteDotFile

Member Data Documentation

◆ cache_enabled_

bool smgl::Graph::cache_enabled_ {false}
private

Cache enabled state

Definition at line 206 of file Graph.hpp.

◆ cacheFile_

filesystem::path smgl::Graph::cacheFile_
private

Cache file

Definition at line 202 of file Graph.hpp.

◆ cacheType_

CacheType smgl::Graph::cacheType_ {CacheType::Subdirectory}
private

Cache type

Definition at line 204 of file Graph.hpp.

◆ extraMetadata_

Metadata smgl::Graph::extraMetadata_
private

Extra metadata

Definition at line 212 of file Graph.hpp.

◆ nodes_

std::unordered_map<Uuid, Node::Pointer> smgl::Graph::nodes_
private

List of Graph's nodes

Definition at line 208 of file Graph.hpp.

◆ state_

State smgl::Graph::state_ {State::Idle}
private

Graph state

Definition at line 210 of file Graph.hpp.

◆ Version

constexpr std::uint32_t smgl::Graph::Version {1}
staticconstexpr

Graph version

Definition at line 35 of file Graph.hpp.


The documentation for this class was generated from the following files: