ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
DotCircuit.h
Go to the documentation of this file.
1/**
2 * @file DotCircuit.h
3 * @brief Provenance circuit variant that renders to GraphViz DOT format.
4 *
5 * @c DotCircuit is a lightweight circuit specialisation used exclusively
6 * for visualisation. It stores a textual description (@c desc) alongside
7 * each gate so that the rendered DOT graph can label nodes with meaningful
8 * provenance formula symbols (⊗, ⊕, ⊖, δ, etc.).
9 *
10 * The @c render() method traverses the circuit and produces a complete
11 * GraphViz @c digraph string that can be piped to @c dot or displayed
12 * with @c graph-easy.
13 */
14#ifndef DOT_CIRCUIT_H
15#define DOT_CIRCUIT_H
16
17#include <unordered_map>
18#include <unordered_set>
19#include <set>
20#include <vector>
21
22#include "Circuit.hpp"
23
24/**
25 * @brief Gate types for a DOT visualisation circuit.
26 *
27 * Each value corresponds to a semiring operator or special gate kind,
28 * and is rendered as the appropriate mathematical symbol in the output.
29 *
30 * - @c UNDETERMINED Placeholder, should not appear in a finished circuit.
31 * - @c OTIMES Semiring times (⊗).
32 * - @c OPLUS Semiring plus (⊕).
33 * - @c OMINUS Semiring monus (⊖), full.
34 * - @c OMINUSR Monus, right child only.
35 * - @c OMINUSL Monus, left child only.
36 * - @c PROJECT Projection gate.
37 * - @c EQ Equijoin gate.
38 * - @c IN Input (variable) gate.
39 * - @c DELTA δ-semiring operator.
40 */
41enum class DotGate
42{
43 UNDETERMINED, ///< Placeholder gate not yet assigned a type
44 OTIMES, ///< Semiring times (⊗)
45 OPLUS, ///< Semiring plus (⊕)
46 OMINUS, ///< Semiring monus (⊖), full
47 OMINUSR, ///< Monus, right child only
48 OMINUSL, ///< Monus, left child only
49 PROJECT, ///< Projection gate
50 EQ, ///< Equijoin gate
51 IN, ///< Input (variable) gate
52 DELTA ///< δ-semiring operator
53};
54
55/**
56 * @brief Circuit specialisation for GraphViz DOT rendering.
57 *
58 * Extends @c Circuit<DotGate> with per-gate description strings and a
59 * @c render() method that produces a complete DOT @c digraph.
60 */
61class DotCircuit : public Circuit<DotGate> {
62private:
63std::set<gate_t> inputs; ///< Input gate IDs (rendered as leaf nodes)
64std::vector<std::string> desc; ///< Per-gate label strings (indexed by gate ID)
65
66public:
67/** @copydoc Circuit::addGate() */
68gate_t addGate() override;
70
71/** @copydoc Circuit::setGate(const uuid&, gateType) */
72gate_t setGate(const uuid &u, DotGate type) override;
73
74/**
75 * @brief Create (or update) a gate with a UUID, type, and description.
76 *
77 * The @p d string is used as the node label in the DOT output.
78 *
79 * @param u UUID of the gate.
80 * @param t Gate type.
81 * @param d Description / label string for this gate.
82 * @return Gate identifier.
83 */
84gate_t setGate(const uuid &u, DotGate t, std::string d);
85
86/**
87 * @brief Render the entire circuit as a GraphViz DOT @c digraph string.
88 *
89 * The returned string can be written to a file and processed with
90 * @c dot, @c neato, or @c graph-easy.
91 *
92 * @return DOT representation of the circuit.
93 */
94std::string render() const;
95
96/** @copydoc Circuit::toString() */
97virtual std::string toString(gate_t g) const override;
98};
99
100#endif /* DOT_CIRCUIT_H */
gate_t
Strongly-typed gate identifier.
Definition Circuit.h:48
Out-of-line template method implementations for Circuit<gateType>.
DotGate
Gate types for a DOT visualisation circuit.
Definition DotCircuit.h:42
@ PROJECT
Projection gate.
@ OPLUS
Semiring plus (⊕)
@ EQ
Equijoin gate.
@ OMINUS
Semiring monus (⊖), full.
@ OMINUSL
Monus, left child only.
@ OMINUSR
Monus, right child only.
@ DELTA
δ-semiring operator
@ IN
Input (variable) gate.
@ UNDETERMINED
Placeholder gate not yet assigned a type.
@ OTIMES
Semiring times (⊗)
Generic template base class for provenance circuits.
Definition Circuit.h:61
std::string uuid
UUID type used in this circuit (always std::string).
Definition Circuit.h:64
virtual gate_t setGate(const uuid &u, gateType type)
Create or update the gate associated with UUID u.
Definition Circuit.hpp:73
Circuit specialisation for GraphViz DOT rendering.
Definition DotCircuit.h:61
virtual std::string toString(gate_t g) const override
Return a textual description of gate g for debugging.
gate_t addGate() override
Allocate a new gate with a default-initialised type.
std::set< gate_t > inputs
Input gate IDs (rendered as leaf nodes)
Definition DotCircuit.h:63
gate_t setGate(const uuid &u, DotGate type) override
Create or update the gate associated with UUID u.
std::string render() const
Render the entire circuit as a GraphViz DOT digraph string.
std::vector< std::string > desc
Per-gate label strings (indexed by gate ID)
Definition DotCircuit.h:64