ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
Circuit.hpp
Go to the documentation of this file.
1/**
2 * @file Circuit.hpp
3 * @brief Out-of-line template method implementations for @c Circuit<gateType>.
4 *
5 * This file provides the definitions of the template methods declared in
6 * @c Circuit.h that cannot be placed in a @c .cpp file (since they must
7 * be instantiated by the compiler in each translation unit that uses them).
8 *
9 * Implemented methods:
10 * - @c hasGate(): UUID membership test.
11 * - @c getGate(): UUID → gate_t lookup, allocating a new gate on miss.
12 * - @c getUUID(): gate_t → UUID string lookup.
13 * - @c addGate(): default gate allocation (extends @c gates and @c wires vectors).
14 * - @c setGate(gateType): allocate a new gate and set its type.
15 * - @c setGate(const uuid&, gateType): create/update a UUID-named gate.
16 * - @c addWire(): append a directed edge.
17 *
18 * Included by subclass headers that need these implementations (e.g.
19 * @c BooleanCircuit.h, @c DotCircuit.h).
20 */
21#ifndef CIRCUIT_HPP
22#define CIRCUIT_HPP
23
24#include "Circuit.h"
25
26template<class gateType>
27bool Circuit<gateType>::hasGate(const uuid &u) const
28{
29 return uuid2id.find(u)!=uuid2id.end();
30}
31
32template<class gateType>
34{
35 auto it=uuid2id.find(u);
36 if(it==uuid2id.end()) {
37 gate_t id=addGate();
38 uuid2id[u]=id;
39 id2uuid[id]=u;
40 return id;
41 } else
42 return it->second;
43}
44
45template<class gateType>
47{
48 auto it = id2uuid.find(g);
49 if(it==id2uuid.end())
50 return "";
51 else
52 return it->second;
53}
54
55template<class gateType>
57{
58 gate_t id{gates.size()};
59 gates.push_back(gateType());
60 wires.push_back({});
61 return id;
62}
63
64template<class gateType>
66{
67 gate_t id = addGate();
68 gates[static_cast<std::underlying_type<gate_t>::type>(id)] = type;
69 return id;
70}
71
72template<class gateType>
73gate_t Circuit<gateType>::setGate(const uuid &u, gateType type)
74{
75 gate_t id = getGate(u);
76 gates[static_cast<std::underlying_type<gate_t>::type>(id)] = type;
77 return id;
78}
79
80template<class gateType>
82{
83 getWires(f).push_back(t);
84}
85
86#endif /* CIRCUIT_HPP */
Generic directed-acyclic-graph circuit template and gate identifier.
gate_t
Strongly-typed gate identifier.
Definition Circuit.h:48
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
void addWire(gate_t f, gate_t t)
Add a directed wire from gate f (parent) to gate t (child).
Definition Circuit.hpp:81
uuid getUUID(gate_t g) const
Return the UUID string associated with gate g.
Definition Circuit.hpp:46
gate_t getGate(const uuid &u)
Return (or create) the gate associated with UUID u.
Definition Circuit.hpp:33
bool hasGate(const uuid &u) const
Test whether a gate with UUID u exists.
Definition Circuit.hpp:27
virtual gate_t addGate()
Allocate a new gate with a default-initialised type.
Definition Circuit.hpp:56