18 nodes_.append(graph_input_node_);
19 nodes_.append(graph_output_node_);
26 std::destroy_at(socket);
29 std::destroy_at(socket);
31 std::destroy_at(node);
33 for (
const InterfaceNode *node : {graph_input_node_, graph_output_node_}) {
35 std::destroy_at(socket);
38 std::destroy_at(socket);
40 std::destroy_at(node);
54 for (
const int i : inputs.index_range()) {
59 socket.
type_ = inputs[i].type;
61 for (
const int i : outputs.index_range()) {
66 socket.
type_ = outputs[i].type;
77 socket.
node_ = graph_input_node_;
79 socket.
index_in_node_ = graph_inputs_.append_and_get_index(&socket);
80 graph_input_node_->
outputs_ = graph_inputs_;
82 graph_input_node_->socket_names_.
append(std::move(name));
90 socket.
node_ = graph_output_node_;
92 socket.
index_in_node_ = graph_outputs_.append_and_get_index(&socket);
93 graph_output_node_->
inputs_ = graph_outputs_;
95 graph_output_node_->socket_names_.
append(std::move(name));
104 from.targets_.append(&to);
109 if (socket.origin_ !=
nullptr) {
110 socket.origin_->targets_.remove_first_occurrence_and_reorder(&socket);
111 socket.origin_ =
nullptr;
117 for (
const int i : nodes_.index_range()) {
118 nodes_[i]->index_in_graph_ = i;
124 int socket_counter = 0;
125 for (
const int i : nodes_.index_range()) {
127 socket->index_in_graph_ = socket_counter++;
130 socket->index_in_graph_ = socket_counter++;
133 socket_num_ = socket_counter;
138 for (
const int i : nodes_.index_range()) {
139 if (nodes_[i]->index_in_graph_ != i) {
162 std::stringstream ss;
178 return socket.
name();
195 digraph.
set_rankdir(dot::Attr_rankdir::LeftToRight);
199 for (
const Node *node : nodes_) {
201 if (node->is_interface()) {
209 dot_node_with_sockets.
node_name = node->name();
224 for (
const Node *node : nodes_) {
233 options.add_edge_attributes(*origin, *socket, dot_edge);
235 else if (
const void *default_value = socket->default_value()) {
236 const CPPType &type = socket->type();
237 std::string value_string;
238 if (type.is_printable()) {
239 value_string = type.
to_string(default_value);
242 value_string = type.name();
245 default_value_dot_node.
set_shape(dot::Attr_shape::Ellipse);
247 digraph.
new_edge(default_value_dot_node, to_dot_port);
std::string to_string(const void *value) const
destruct_ptr< T > construct(Args &&...args)
StringRefNull copy_string(StringRef str)
Span< T * > construct_elements_and_pointer_array(int64_t n, Args &&...args)
const Value & lookup(const Key &key) const
void add_new(const Key &key, const Value &value)
void append(const T &value)
void set(StringRef key, StringRef value)
DirectedEdge & new_edge(NodePort from, NodePort to)
std::string to_dot_string() const
Node & new_node(StringRef label)
void set_rankdir(Attr_rankdir rankdir)
NodePort output(int index) const
NodePort input(int index) const
void set_shape(Attr_shape shape)
void set_background_color(StringRef name)
const LazyFunction & function() const
virtual std::string socket_name(const Socket &socket) const
virtual void add_edge_attributes(const OutputSocket &from, const InputSocket &to, dot::DirectedEdge &dot_edge) const
virtual std::optional< std::string > socket_font_color(const Socket &socket) const
void update_node_indices()
Graph(StringRef name="unkown")
bool node_indices_are_valid() const
Span< const FunctionNode * > function_nodes() const
FunctionNode & add_function(const LazyFunction &fn)
void add_link(OutputSocket &from, InputSocket &to)
void update_socket_indices()
GraphOutputSocket & add_output(const CPPType &type, std::string name="")
void clear_origin(InputSocket &socket)
std::string to_dot(const ToDotOptions &options={}) const
GraphInputSocket & add_input(const CPPType &type, std::string name="")
Span< Input > inputs() const
Span< Output > outputs() const
virtual std::string output_name(int index) const
virtual std::string input_name(int index) const
virtual std::string name() const
Span< OutputSocket * > outputs_
Span< InputSocket * > inputs_
std::string detailed_name() const
CCL_NAMESPACE_BEGIN struct Options options
std::optional< std::string > fontcolor
Input & add_input(std::string name)
Output & add_output(std::string name)