← Back to team overview

yade-users team mailing list archive

Re: Looping interactions and bodies

 

Thanks Vaclav for not only telling me the differences, but also for showing me how to do it for other things!

 

 

Cheers,

 

CWBoon
 
> From: eudoxos@xxxxxxxx
> To: yade-users@xxxxxxxxxxxxxxxxxxx
> Date: Fri, 11 Dec 2009 19:04:20 +0100
> Subject: Re: [Yade-users] Looping interactions and bodies
> 
> > I see generally 2 methods of iterating bodies and interactions. 
> > 
> > 1st method:
> > Interaction::Container::iterator ii =
> > ncb->transientInteractions->begin();
> > Interaction::Container::iterator iiEnd = ncb -> transientInteraction
> > -> end();
> > for( ; ii!=iiEnd; ++i){ }
> > 
> > 2nd method:
> > FOREACH(const shared_ptr<Interaction>& I, *ncb->interaction){ }
> > 
> > 
> > What are the differences between the two methods [i.e. (*ii) from the
> > first method or (I) in the second method] ?? In what circumstances
> > do I choose one over the other? 
> 
> Use always the second one, it is functionally the same and more
> readable. (transientInteractions is deprecated and is now reference to
> interactions)
> 
> The same for bodies. FOREACH also works for STL containers such as
> vector<string> abc; FOREACH(string& s, abc){ ... }.
> 
> Make sure you avoid NULL (erased) bodies and non-real interactions:
> 
> FOREACH(const shared_ptr<Body>& b, *scene->bodies){
> if(!b) continue;
> /* ... */
> }
> 
> and
> 
> FOREACH(const shared_ptr<Interaction>& i, *scene->interactions){
> if(!i->isReal()) continue;
> /* ... */
> }
> 
> I was thinking about modification of the iterators so that such
> bodies/interactions would be skipped silently (if desired), but that has
> not happened (yet?).
> 
> Cheers, Vaclav
> 
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : yade-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
 		 	   		  
_________________________________________________________________
New Windows 7: Simplify what you do everyday. Find the right PC for you.
http://windows.microsoft.com/shop

References