libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches

Defined in dot.hpp.

This class facilitates the creation and rendering of graph descriptions in the DOT language of the Graphviz graph drawing software. This class is fairly rudimentary, and is not intended to implement every feature of the DOT language.

You can create a Dot object, assemble the graph by adding nodes and edges, attributes, labels, colours, subgraphs, and clusters, and retrieve its DOT source code string (Dot::to_string). Write the source code to a file and render it with the Graphviz installation on your system.

Warning
No checks of any kind for the correctness of the output (Dot::to_string) std::string are performed.

Classes

struct  Edge
 This nested struct represents an edge in the represented graph. More...
 
struct  Node
 This nested struct represents a node in the represented graph. More...
 

Public Types

enum class  Kind { digraph , graph , subgraph }
 The kind of object represented. More...
 

Public Member Functions

 Dot ()
 Default constructor.
 
 Dot (Dot &&)
 Default move constructor.
 
 Dot (Dot const &)
 Default copy constructor.
 
template<typename Thing>
Dotadd_attr (Thing &&key)
 Add an attribute to the graph.
 
template<typename Thing1, typename Thing2>
Dotadd_attr (Thing1 &&key, Thing2 &&val)
 Add an attribute to the graph.
 
template<typename Thing1, typename Thing2>
Edgeadd_edge (Thing1 &&head, Thing2 &&tail)
 Add an edge with given head and tail.
 
template<typename Thing>
Nodeadd_node (Thing &&thing)
 Add a node to the represented graph.
 
Dotadd_subgraph (Dot &&subgraph)
 Add a Dot object as a subgraph.
 
Dotadd_subgraph (Dot const &subgraph)
 Add a Dot object as a subgraph.
 
std::map< std::string, std::string > const & attrs () const noexcept
 Returns a const reference to the map of attributes.
 
template<typename Thing1, typename Thing2>
Edgeedge (Thing1 &&head, Thing2 &&tail)
 Returns the first edge with given head and tail.
 
std::vector< Edge > const & edges () const noexcept
 Returns a const reference to the vector of edges.
 
std::vector< Edge > & edges () noexcept
 Returns a reference to the vector of edges.
 
bool is_node (std::string const &name) const
 Check if there is a node with a given name.
 
template<typename Thing, typename std::enable_if_t< !std::is_same_v< std::decay_t< Thing >, std::string > >>
bool is_node (Thing &&thing) const
 Check if there is a node with name obtained from an object.
 
Kind kind () const noexcept
 Get the kind of the represented graph.
 
Dotkind (Kind val) noexcept
 Set the kind of the represented graph.
 
std::string const & name () const noexcept
 Get the current name of the represented graph.
 
Dotname (std::string const &val)
 Set the name of the represented graph.
 
template<typename Thing>
Nodenode (Thing &&thing)
 Return a node from the represented graph.
 
auto nodes () const noexcept
 Returns a range object of const references to the current nodes.
 
auto nodes () noexcept
 Returns a range object of references to the current nodes.
 
Dotoperator= (Dot &&)
 Default move assignment operator.
 
Dotoperator= (Dot const &)
 Default copy assignment operator.
 
std::vector< Dot > const & subgraphs () const noexcept
 Returns a const reference to the vector of subgraphs.
 
std::vector< Dot > & subgraphs () noexcept
 Returns a reference to the vector of subgraphs.
 
std::string to_string () const
 Convert a Dot object to a string.
 

Related Symbols

(Note that these are not member symbols.)

std::string to_human_readable_repr (Dot::Edge const &e)
 Return a human readable representation of a Dot::Edge object.
 
std::string to_human_readable_repr (Dot::Node const &n)
 Return a human readable representation of a Dot::Node object.
 
std::string to_human_readable_repr (Dot const &d)
 Return a human readable representation of a Dot object.
 
std::string to_human_readable_repr (Dot::Kind const &k, std::string const &sep="::")
 Return a human readable representation of a Dot::Kind object.
 

Member Enumeration Documentation

◆ Kind

enum class Kind
strong
Enumerator
digraph 

Value indicating that the represented graph has directed edges ->.

graph 

Value indicating that the represented graph has undirected edges --.

subgraph 

Value indicating that the represented graph is a subgraph of another Dot object.

Member Function Documentation

◆ add_attr() [1/2]

template<typename Thing>
Dot & add_attr ( Thing && key)
inline

This function adds a new attribute, or replaces the value of an existing attribute, of a Dot object. The argument key is converted to std::string (unless they are std::string, std::string_view, or char const* already).

Template Parameters
Thingthe type of the argument.
Parameters
keythe name of the attribute.
Returns
A reference to this.
Warning
No checks of any kind are performed that the string representations of key or val are valid in DOT; see the Graphviz documentation for more details.

◆ add_attr() [2/2]

template<typename Thing1, typename Thing2>
Dot & add_attr ( Thing1 && key,
Thing2 && val )
inline

This function adds a new attribute, or replaces the value of an existing attribute, of a Dot object. The arguments key and val are converted to std::string (unless they are std::string, std::string_view, or char const* already).

Template Parameters
Thing1the type of the first argument.
Thing2the type of the second argument.
Parameters
keythe name of the attribute.
valthe value of the attribute.
Returns
A reference to this.
Warning
No checks of any kind are performed that the string representations of key or val are valid in DOT; see the Graphviz documentation for more details.

◆ add_edge()

template<typename Thing1, typename Thing2>
Edge & add_edge ( Thing1 && head,
Thing2 && tail )
inline

This function adds an edge with head and tail obtained from head and tail by converting head and tail to std::string objects (unless they are std::string, std::string_view, or char const* already) using std::to_string.

Template Parameters
Thing1the type of the 1st argument.
Thing2the type of the 2nd argument.
Parameters
headthe head of the edge.
tailthe tail of the edge.
Returns
A reference to the Edge object from head to tail.
Exceptions
LibsemigroupsExceptionif head or tail does not represent a node in the graph.

◆ add_node()

template<typename Thing>
Node & add_node ( Thing && thing)
inline

This function adds a node with name obtained from thing by converting it to a std::string (unless they are std::string, std::string_view, or char const* already) using std::to_string.

Template Parameters
Thingthe type of the argument.
Parameters
thingthe object to use as the name of a node.
Returns
A reference to the Node object with name obtained from thing.
Exceptions
LibsemigroupsExceptionif there is already a node with name std::to_string(thing).

◆ add_subgraph() [1/2]

Dot & add_subgraph ( Dot && subgraph)

This function adds the Dot object subgraph as a subgraph of this. The following transformations are performed:

  • the label attribute of the added subgraph is the name of subgraph;
  • the name of the added subgraph has the prefix "cluster_" prepended;
  • every node in the added subgraph has the prefix "name_" prepended (where "name" is the return value of name);
  • the label attribute of every node in the added subgraph is its original name in subgraph;
  • every edge is modified so that its head and tail use the new node names;
  • every edge has the attribute constraint set to false.
Parameters
subgraphthe Dot object to use as a subgraph.
Returns
A reference to this.

◆ add_subgraph() [2/2]

Dot & add_subgraph ( Dot const & subgraph)

This function adds the Dot object subgraph as a subgraph of this. The following transformations are performed:

  • the label attribute of the added subgraph is the name of subgraph;
  • the name of the added subgraph has the prefix "cluster_" prepended;
  • every node in the added subgraph has the prefix "name_" prepended (where "name" is the return value of name);
  • the label attribute of every node in the added subgraph is its original name in subgraph;
  • every edge is modified so that its head and tail use the new node names;
  • every edge has the attribute constraint set to false.
Parameters
subgraphthe Dot object to use as a subgraph.
Returns
A reference to this.

◆ attrs()

std::map< std::string, std::string > const & attrs ( ) const
inlinenoexcept

Returns a const reference to a std::map of the current attributes of the represented graph.

Returns
A const reference to the std::vector of current subgraph objects.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ edge()

template<typename Thing1, typename Thing2>
Edge & edge ( Thing1 && head,
Thing2 && tail )
inline

This function returns the first edge with head and tail obtained from head and tail by converting head and tail to std::string objects (unless they are std::string, std::string_view, or char const* already) using std::to_string.

Template Parameters
Thing1the type of the 1st argument.
Thing2the type of the 2nd argument.
Parameters
headthe head of the edge.
tailthe tail of the edge.
Returns
A reference to the Edge object from head to tail.
Exceptions
LibsemigroupsExceptionif head or tail does not represent a node in the graph.
LibsemigroupsExceptionif there's no edge from head to tail.

◆ edges() [1/2]

std::vector< Edge > const & edges ( ) const
inlinenoexcept

Returns a const reference to a std::vector of the current edges (Edge objects) in the represented graph.

Returns
A const reference to the std::vector of current Edge objects.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ edges() [2/2]

std::vector< Edge > & edges ( )
inlinenoexcept

Returns a reference to a std::vector of the current edges (Edge objects) in the represented graph.

Returns
A reference to the std::vector of current Edge objects.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ is_node() [1/2]

bool is_node ( std::string const & name) const
inlinenodiscard

This function returns true if name is currently the name of a node in the represented graph and false otherwise.

Parameters
namethe name.
Returns
A bool.

◆ is_node() [2/2]

template<typename Thing, typename std::enable_if_t< !std::is_same_v< std::decay_t< Thing >, std::string > >>
bool is_node ( Thing && thing) const
inlinenodiscard

This function returns true if the value returned by std::to_string applied to name is currently the name of a node in the represented graph and false otherwise.

Template Parameters
Thingthe type of the argument.
Parameters
thingthe object that whose string representation might be a node.
Returns
A bool.

◆ kind() [1/2]

Kind kind ( ) const
inlinenoexcept
Returns
A value of type Dot::kind.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ kind() [2/2]

Dot & kind ( Kind val)
inlinenoexcept
Parameters
valthe kind.
Returns
A reference to this.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ name() [1/2]

std::string const & name ( ) const
inlinenoexcept

Get the current name of the represented graph.

Returns
The current name of the represented graph.

◆ name() [2/2]

Dot & name ( std::string const & val)
inline
Parameters
valthe name.
Returns
A reference to this.

◆ node()

template<typename Thing>
Node & node ( Thing && thing)
inline

This function returns a reference to a node with name obtained from thing by converting it to a std::string (unless they are std::string, std::string_view, or char const* already) using std::to_string.

Template Parameters
Thingthe type of the argument.
Parameters
thingthe object to use as the name of a node.
Returns
A reference to the Node object with name obtained from thing.
Exceptions
LibsemigroupsExceptionif there is no node with name std::to_string(thing).

◆ nodes() [1/2]

auto nodes ( ) const
inlinenoexcept

Returns a range object of const references for the current nodes in the represented graph; see Ranges for more details.

Returns
A range object.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ nodes() [2/2]

auto nodes ( )
inlinenoexcept

Returns a range object of references for the current nodes in the represented graph; see Ranges for more details.

Returns
A range object.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ subgraphs() [1/2]

std::vector< Dot > const & subgraphs ( ) const
inlinenoexcept

Returns a const reference to a std::vector of the current subgraphs (Dot objects) in the represented graph.

Returns
A const reference to the std::vector of current subgraph objects.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ subgraphs() [2/2]

std::vector< Dot > & subgraphs ( )
inlinenoexcept

Returns a reference to a std::vector of the current subgraphs (Dot objects) in the represented graph.

Returns
A reference to the std::vector of current subgraph objects.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ to_string()

std::string to_string ( ) const

This function returns the string representation of the Dot object. This string contains a representation of the graph in the DOT language for Graphviz.

Returns
A std::string by value.

Friends And Related Symbol Documentation

◆ to_human_readable_repr() [1/4]

std::string to_human_readable_repr ( Dot const & d)
related

Return a human readable representation of a Dot object.

Parameters
dthe Dot object.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ to_human_readable_repr() [2/4]

std::string to_human_readable_repr ( Dot::Kind const & k,
std::string const & sep = "::" )
related

Return a human readable representation of a Dot::Kind object.

Parameters
kthe Dot::Kind object.
sepseparator to use between "Dot" and "Kind" (defaults to "::").
Exceptions
This function guarantees not to throw a LibsemigroupsException.

Member Data Documentation

◆ colors

std::array<std::string_view, 24> colors
staticconstexpr
Initial value:
= {"#00ff00", "#ff00ff", "#007fff", "#ff7f00", "#7fbf7f", "#4604ac",
"#de0328", "#19801d", "#d881f5", "#00ffff", "#ffff00", "#00ff7f",
"#ad5867", "#85f610", "#84e9f5", "#f5c778", "#207090", "#764ef3",
"#7b4c00", "#0000ff", "#b80c9a", "#601045", "#29b7c0", "#839f12"}

An array of default HTML/hex colours.


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