Skip to content

Commit 8a3d760

Browse files
committed
Update Node.jl
Implement methods for updating thz node MTG encoding of a NodeMTG (immutable version) + fix some doc
1 parent 6dce7d0 commit 8a3d760

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

src/types/Node.jl

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,43 @@ link(node::Node) = getfield(node_mtg(node), :link)
285285
Set the symbol of the MTG encoding node.
286286
"""
287287
symbol!(node::Node{T,A}, symbol) where {T<:MutableNodeMTG,A} = setfield!(node_mtg(node), :symbol, symbol)
288+
function symbol!(node::Node{T,A}, new_symbol) where {T<:NodeMTG,A}
289+
current_node_mtg = node_mtg(node)
290+
node_mtg!(node, NodeMTG(current_node_mtg.link, new_symbol, current_node_mtg.index, current_node_mtg.scale))
291+
end
288292

289293
"""
290-
scale(node::Node)
294+
scale!(node::Node, new_scale)
291295
292-
Get the scale from the MTG encoding of the node.
296+
Set the scale of the MTG encoding of the node. The scale should be some kind of integer.
293297
"""
294-
scale!(node::Node{T,A}, symbol) where {T<:MutableNodeMTG,A} = setfield!(node_mtg(node), :scale, symbol)
298+
scale!(node::Node{T,A}, new_scale) where {T<:MutableNodeMTG,A} = setfield!(node_mtg(node), :scale, new_scale)
299+
function scale!(node::Node{T,A}, new_scale) where {T<:NodeMTG,A}
300+
current_node_mtg = node_mtg(node)
301+
node_mtg!(node, NodeMTG(current_node_mtg.link, current_node_mtg.symbol, current_node_mtg.index, new_scale))
302+
end
295303

296304
"""
297-
index(node::Node)
305+
index!(node::Node, new_index)
298306
299-
Get the index from the MTG encoding of the node.
307+
Set the index of the MTG encoding of the node. The index should be some kind of integer.
300308
"""
301-
index!(node::Node{T,A}, symbol) where {T<:MutableNodeMTG,A} = setfield!(node_mtg(node), :index, symbol)
309+
index!(node::Node{T,A}, new_index) where {T<:MutableNodeMTG,A} = setfield!(node_mtg(node), :index, new_index)
310+
function index!(node::Node{T,A}, new_index) where {T<:NodeMTG,A}
311+
current_node_mtg = node_mtg(node)
312+
node_mtg!(node, NodeMTG(current_node_mtg.link, current_node_mtg.symbol, new_index, current_node_mtg.scale))
313+
end
302314

303315
"""
304-
link(node::Node)
316+
link!(node::Node, new_link)
305317
306-
Get the link from the MTG encoding of the node.
318+
Set the link of the MTG encoding of the node. It can be one of "/", "<", or "+".
307319
"""
308-
link!(node::Node{T,A}, symbol) where {T<:MutableNodeMTG,A} = setfield!(node_mtg(node), :link, symbol)
320+
link!(node::Node{T,A}, new_link) where {T<:MutableNodeMTG,A} = setfield!(node_mtg(node), :link, new_link)
321+
function link!(node::Node{T,A}, new_link) where {T<:NodeMTG,A}
322+
current_node_mtg = node_mtg(node)
323+
node_mtg!(node, NodeMTG(new_link, current_node_mtg.symbol, current_node_mtg.index, current_node_mtg.scale))
324+
end
309325

310326
"""
311327
node_attributes(node::Node)

0 commit comments

Comments
 (0)