iopi newbie
Joined: 09 May 2008 Posts: 7
|
Posted: Wed Oct 29, 2008 11:29 pm Post subject: removeVariable, removeRecursive and reference |
|
|
sometimes it's difficult to delete correctly nodes.
'removeVariable' is cute for remove all subnodes, arrays, and values, but he didn't really destroy the node.
'removeRecursive' destroys a subnode but also he search for all corresponding subnode and sometimes is not what we want.
for example: you only want to delete the subnode 'bar' of the node 'foo'.
foo looks like:
| Code: |
local foo;
insert foo.myList;
pushItem foo.myList = 666;
insert foo.myList#back.bar = "solaris";
insert foo.myHash["giveme"] = "acookie";
insert foo.bar = 42;
insert foo.bar.google = "microsoft";
|
removeRecursive(foo, "bar"); will destroy foo.bar and foo.myList#[0].bar and I don't want.
I found a trick;
| Code: |
localref del_foo_bar = foo.bar;
removeVariable(del_foo_bar);
|
I have also some difficulties with reference. When you want to delete a reference WITHOUT destroy the object referenced I must use this trick.
| Code: |
ref project.myReference = project.a.very.deep.sub.nodes.tree;
/// some treatment of myReference
....
/// now I want to clean myReference so....
insert project.fakeNode;
ref project.myReference = project.fakeNode;
localref del_myReference = project.myReference;
removeVariable(del_myReference);
|
It's boring, isn't it!
Couldbe we need some EXTRA ARGUMENT on removeRecursive to precise what we want.
something like that:
| Code: |
removeRecursive(foo, "bar", $ONCE$);
removeRecursive(project, "myReference", $ONCE | NOT_DEREF$);
|
|
|