34#include <unordered_map>
35#include <unordered_set>
60template<
class gateType>
71std::vector<std::vector<gate_t> >
wires;
80 gates[
static_cast<std::underlying_type<gate_t>::type
>(g)]=t;
131 return gates[
static_cast<std::underlying_type<gate_t>::type
>(g)];
141 return wires[
static_cast<std::underlying_type<gate_t>::type
>(g)];
151 return wires[
static_cast<std::underlying_type<gate_t>::type
>(g)];
219virtual char const *
what() const noexcept {
230 return g=
gate_t{
static_cast<std::underlying_type<gate_t>::type
>(g)+1};
241 return static_cast<std::underlying_type<gate_t>::type
>(t)<u;
250 return std::to_string(
static_cast<std::underlying_type<gate_t>::type
>(g));
261 std::underlying_type<gate_t>::type u;
275 return o << static_cast<std::underlying_type<gate_t>::type>(g);
std::istream & operator>>(std::istream &i, gate_t &g)
Read a gate_t from an input stream.
gate_t & operator++(gate_t &g)
Pre-increment operator for gate_t.
std::ostream & operator<<(std::ostream &o, gate_t g)
Write a gate_t to an output stream as its decimal value.
bool operator<(gate_t t, std::vector< gate_t >::size_type u)
Compare a gate_t against a std::vector size type.
gate_t
Strongly-typed gate identifier.
std::string to_string(gate_t g)
Convert a gate_t to its decimal string representation.
Exception type thrown by circuit operations on invalid input.
std::string message
Human-readable description of the error.
virtual char const * what() const noexcept
Return the error message as a C-string.
CircuitException(const std::string &m)
Construct with a descriptive error message.
Generic template base class for provenance circuits.
std::string uuid
UUID type used in this circuit (always std::string).
std::vector< gate_t > & getWires(gate_t g)
Return a mutable reference to the child-wire list of gate g.
gateType getGateType(gate_t g) const
Return the type of gate g.
std::unordered_map< gate_t, uuid > id2uuid
Gate index → UUID string.
const std::vector< gate_t > & getWires(gate_t g) const
Return a const reference to the child-wire list of gate g.
virtual gate_t setGate(const uuid &u, gateType type)
Create or update the gate associated with UUID u.
virtual std::string toString(gate_t g) const =0
Return a textual description of gate g for debugging.
void addWire(gate_t f, gate_t t)
Add a directed wire from gate f (parent) to gate t (child).
std::unordered_map< uuid, gate_t > uuid2id
UUID string → gate index.
void setGateType(gate_t g, gateType t)
Update the type of an existing gate.
std::vector< gateType > gates
Gate type for each gate.
uuid getUUID(gate_t g) const
Return the UUID string associated with gate g.
std::vector< std::vector< gate_t > > wires
Child wire lists for each gate.
gate_t getGate(const uuid &u)
Return (or create) the gate associated with UUID u.
bool hasGate(const uuid &u) const
Test whether a gate with UUID u exists.
std::vector< gate_t >::size_type getNbGates() const
Return the total number of gates in the circuit.
virtual gate_t addGate()
Allocate a new gate with a default-initialised type.