145 const bool hasNames = (
_names_ !=
nullptr);
149 if (!first) s +=
",";
152 if (hasNames &&
_names_->existsFirst(
id)) s += std::format(
"{}<{}>",
id,
_names_->second(
id));
153 else s += std::format(
"{}",
id);
163 return std::to_string(
id);
174 auto owner =
_names_->tryFirst(name);
175 if (owner.has_value()) {
182 _names_ = std::make_unique< Bijection< NodeId, std::string > >();
191 return "(" + std::to_string(
id) +
") " +
_names_->second(
id);
204 for (
const auto node:
nodes())
Exception : a similar element already exists.
Exception : node does not exist.
void whenNodeDeleted(const void *src, NodeId id)
called when a node is deleted in the iterated NodeGraphPart
const NodeGraphPart * nodes_
the nodegraphpart on which points the iterator
NodeId pos_
the nodeid on which the iterator points currently
Class for node sets in graph.
NodeGraphPartIteratorSafe _endIteratorSafe_
the end iterator (used to speed-up parsings of the NodeGraphPart)
void populateNodes(const NodeGraphPart &s)
populateNodes clears *this and fills it with the same nodes as "s"
Signaler< NodeId > onNodeDeleted
void _clearNodes_()
code for clearing nodes (called twice)
virtual void clear()
alias for clearNodes
std::unique_ptr< Bijection< NodeId, std::string > > _names_
optional node names — null when no name has been set
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
bool hasName(NodeId id) const
returns true iff node id has an explicit name
void _eraseHole_(NodeId id)
to delete hole.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
std::string nameFromId(NodeId id) const
returns the name of node id, or "<id>" if no name is set
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
void setName(NodeId id, const std::string &name)
sets the name of node id
Size _holes_size_
value for holes configuration
void writeDotNodes(dot::DotWriter &writer, const dot::DotStyle &style, const dot::DotOptions &options) const
writes the nodes in the dot language, see writeDotNode()
virtual std::string toString() const
a function to display the set of nodes
std::string dotNodeText(NodeId id) const
the label of a node in a graph drawn with graphviz : "(id) name", or "" if the node has no name
bool _holes_resize_policy_
value for holes configuration
virtual ~NodeGraphPart()
destructor
std::unique_ptr< Bijection< NodeId, std::string > > _cloneNames_() const
clone the names bijection (returns nullptr when no name has been set)
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
Signaler< NodeId > onNodeAdded
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
std::optional< NodeId > idFromName(const std::string &name) const
returns the id of the node with the given name, or std::nullopt
void writeDotNode(dot::DotWriter &writer, const dot::DotStyle &style, const dot::DotOptions &options, NodeId id) const
writes a node in the dot language, with the label "(id) name" if it is named and the colors given by ...
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
void _addHole_(NodeId id)
to add a hole.
bool _inHoles_(NodeId id) const
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
bool empty() const noexcept
Indicates whether the set is the empty set.
void insert(const Key &k)
Inserts a new element into the set.
void erase(const Key &k)
Erases an element from the set.
bool hasListener() override
The options given to a toDot(const DotOptions&).
const DotNodeOptions * node(Size node) const
the options of a node, or nullptr if none was given for it
Writes a graph in the dot language, statement after statement, in the order of the calls.
void node(std::string_view id, const DotAttributes &attributes={})
a node, whose identifier is id (quoted).
The statements common to the graphs drawn with graphviz : preamble, attributes of nodes and arcs.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
DotAttributes nodeAttributes(const DotStyle &style, const DotNodeOptions *options, std::string_view defaultLabel, std::string_view defaultTooltip)
The attributes of a node : its label and tooltip, and its colors if the options give some.
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Base node set class for graphs.
Inline implementation of the base node set class for graphs.
#define GUM_EMIT1(signal, arg1)
The look shared by all the graphs: size, direction, layout, colors of the arcs and of the nodes.