29template<
class gateType>
38template<
class gateType>
41 auto [it, fresh] =
uuid2id.try_emplace(u);
46 return {it->second, fresh};
49template<
class gateType>
64template<
class gateType>
69 return id2uuid[
static_cast<std::underlying_type<gate_t>::type
>(g)].str();
77template<
class gateType>
80 const auto i =
static_cast<std::underlying_type<gate_t>::type
>(g);
92template<
class gateType>
100 const auto i =
static_cast<std::underlying_type<gate_t>::type
>(g);
110template<
class gateType>
113 const auto i =
static_cast<std::underlying_type<gate_t>::type
>(g);
126template<
class gateType>
129 const auto i =
static_cast<std::underlying_type<gate_t>::type
>(g);
144template<
class gateType>
147 const auto i =
static_cast<std::underlying_type<gate_t>::type
>(from);
156 const std::string u =
id2name[from];
167template<
class gateType>
171 gates.push_back(gateType());
178template<
class gateType>
182 gates[
static_cast<std::underlying_type<gate_t>::type
>(id)] = type;
186template<
class gateType>
190 gates[
static_cast<std::underlying_type<gate_t>::type
>(id)] = type;
194template<
class gateType>
Generic directed-acyclic-graph circuit template and gate identifier.
gate_t
Strongly-typed gate identifier.
unsigned char nameKind(gate_t g) const
What gate g is named by.
std::vector< unsigned char > name_kind
What each gate is named by.
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.
@ UUID_NAME
A UUID, in id2uuid.
@ OTHER_NAME
Another string, in id2name.
void dropName(gate_t g)
Remove the name of gate g, if any.
virtual gate_t setGate(const uuid &u, gateType type)
Create or update the gate associated with UUID u.
void addWire(gate_t f, gate_t t)
Add a directed wire from gate f (parent) to gate t (child).
std::unordered_map< gate_uuid, gate_t, gate_uuid_hash > uuid2id
UUID → gate index.
std::unordered_map< gate_t, std::string > id2name
Gate index → other name.
void pointName(gate_t g, gate_t target)
Make the name of gate g, if any, name gate target.
std::vector< gateType > gates
Gate type for each gate.
std::vector< gate_uuid > id2uuid
UUID of each gate (if UUID_NAME).
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.
std::pair< gate_t, bool > findOrAddGate(const gate_uuid &u)
Return (or create) the gate associated with UUID u, and whether it was created.
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.
void bindName(gate_t g, const gate_uuid &u)
Name gate g by the UUID u.
std::unordered_map< std::string, gate_t > name2id
Other name → gate index.
void moveName(gate_t from, gate_t to)
Give the name of gate from, if any, to gate to.
virtual gate_t addGate()
Allocate a new gate with a default-initialised type.
A UUID as its 16 bytes, read as two big-endian words.
static bool parse(const std::string &s, gate_uuid &u)
Read s as a UUID in the text form PostgreSQL prints (lowercase, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)...