codeworker Forum Index codeworker
A universal parsing tool & a source code generator
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

removeVariable, removeRecursive and reference

 
Post new topic   Reply to topic    codeworker Forum Index -> CodeWorker's Improvements and Extensions
View previous topic :: View next topic  
Author Message
iopi
newbie


Joined: 09 May 2008
Posts: 7

PostPosted: Wed Oct 29, 2008 11:29 pm    Post subject: removeVariable, removeRecursive and reference Reply with quote

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$);
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    codeworker Forum Index -> CodeWorker's Improvements and Extensions All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group