Class: LemonGraph::Digraph::Arc

Inherits:
GraphItem show all
Defined in:
ext/lemongraph/lemongraph.cc,
ext/lemongraph/lemongraph.cc

Overview

Arc of a LemonGraph::Digraph, from a source Node to a target Node.

Instance Attribute Summary

Attributes inherited from GraphItem

#graph, #id

Instance Method Summary collapse

Methods inherited from GraphItem

#!=, #<=>, #==

Instance Method Details

#eraseself

Erases the arc from the graph it belongs to.

Returns:

  • (self)


56
57
58
59
60
# File 'ext/lemongraph/digraph_arc.cc', line 56

VALUE lemongraph_diarc_erase(VALUE self)
{
	lemongraph_digraph_rb2ref(rb_iv_get(self, "@graph")).erase(lemongraph_rbdiarc2diarc(self));
	return self;
}

#reverse!self

Reverses the direction of the given arc.

Returns:

  • (self)


133
134
135
136
137
# File 'ext/lemongraph/digraph_arc.cc', line 133

VALUE lemongraph_diarc_reverse(VALUE self)
{
	lemongraph_digraph_rb2ref(rb_iv_get(self, "@graph")).reverseArc(lemongraph_rbdiarc2diarc(self));
	return self;
}

#sourceNode

Returns the source node of the arc.

Returns:



111
112
113
114
115
116
# File 'ext/lemongraph/digraph_arc.cc', line 111

VALUE lemongraph_diarc_source(VALUE self)
{
	VALUE g = rb_iv_get(self, "@graph");
	lemon::ListDigraph::Node n = lemongraph_digraph_rb2ref(g).source(lemongraph_rbdiarc2diarc(self));
	return lemongraph_make_dinode(n, g);
}

#source=(node) ⇒ self

Changes the source node of the arc a to node.

Parameters:

  • node (Node)

    the arc's new source node

Returns:

  • (self)


94
95
96
97
98
99
100
101
102
103
104
105
# File 'ext/lemongraph/digraph_arc.cc', line 94

VALUE lemongraph_diarc_change_source(VALUE self, VALUE node)
{
	if (rb_class_of(node) != c_DiNode) {
		rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
				rb_class_name(c_DiNode), rb_obj_classname(node));
	}
	VALUE graph = rb_iv_get(self, "@graph");
	if (rb_iv_get(node, "@graph") != graph)
		rb_raise(rb_eRuntimeError, "arc and node not from the sams graph");
	lemongraph_digraph_rb2ref(graph).changeSource(lemongraph_rbdiarc2diarc(self), lemongraph_rbdinode2dinode(node));
	return self;
}

#splitNode

Splits the arc. First, a new node v is added to the graph, then the target node of the original arc is set to v. Finally, an arc from v to the original target is added.

Returns:

  • (Node)

    the newly created node



146
147
148
149
150
151
# File 'ext/lemongraph/digraph_arc.cc', line 146

VALUE lemongraph_diarc_split(VALUE self)
{
	VALUE g = rb_iv_get(self, "@graph");
	lemon::ListDigraph::Node n = lemongraph_digraph_rb2ref(g).split(lemongraph_rbdiarc2diarc(self));
	return lemongraph_make_dinode(n, g);
}

#targetNode

Returns the target node of the arc.

Returns:



122
123
124
125
126
127
# File 'ext/lemongraph/digraph_arc.cc', line 122

VALUE lemongraph_diarc_target(VALUE self)
{
	VALUE g = rb_iv_get(self, "@graph");
	lemon::ListDigraph::Node n = lemongraph_digraph_rb2ref(g).target(lemongraph_rbdiarc2diarc(self));
	return lemongraph_make_dinode(n, g);
}

#target=(node) ⇒ self

Changes the target node of the arc a to node.

Parameters:

  • node (Node)

    the arc's new target node

Returns:

  • (self)


76
77
78
79
80
81
82
83
84
85
86
87
# File 'ext/lemongraph/digraph_arc.cc', line 76

VALUE lemongraph_diarc_change_target(VALUE self, VALUE node)
{
	if (rb_class_of(node) != c_DiNode) {
		rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
				rb_class_name(c_DiNode), rb_obj_classname(node));
	}
	VALUE graph = rb_iv_get(self, "@graph");
	if (rb_iv_get(node, "@graph") != graph)
		rb_raise(rb_eRuntimeError, "arc and node not from the sams graph");
	lemongraph_digraph_rb2ref(graph).changeTarget(lemongraph_rbdiarc2diarc(self), lemongraph_rbdinode2dinode(node));
	return self;
}

#valid?Boolean

Test if the arc is valid, i.e. it is a real arc of the graph it belons to.

Returns:

  • (Boolean)


66
67
68
69
# File 'ext/lemongraph/digraph_arc.cc', line 66

VALUE lemongraph_diarc_is_valid(VALUE self)
{
	return lemongraph_digraph_rb2ref(rb_iv_get(self, "@graph")).valid(lemongraph_rbdiarc2diarc(self)) ? Qtrue : Qfalse;
}