Game Development Community

C++ Help: What's mean if(empty())?

by elvince · in Torque 3D Professional · 08/05/2010 (8:05 pm) · 5 replies

Maybe a odd question but what does mean:
void GuiStackControl::stackFromBottom()
{
   if( empty() )
      return;

I feel something has not been clean up, but as I'm not an expert in C++, this may be something useful.

Thanks

#1
08/05/2010 (8:34 pm)
I'm guessing based on the name, that the stackFromBottom method traverses a stack from the bottom to the top. The if check is seeing if the stack is empty. If it is, then there is nothing to traverse, or whatever work the method is doing, so it returns.
#2
08/05/2010 (8:46 pm)
I would have say that also. But look in the code there no empty function in the stackcontrol.
More it's used only on stackFromBottom and not stackFromTop by example.
#3
08/05/2010 (8:52 pm)
It's possible that empty() is a method on a parent object - I'm guessing the GUI Container. I'm not at a computer that I have the T3D source on, and I'm not sure exactly what class it is, but that's certainly my best guess.
#4
08/05/2010 (9:02 pm)
SimSet->SimGroup->guiControl->guiStackControl

The empty() function is defined on SimSet which the downlevel classes inherit. It is actually calling the empty() method on a SimObjectList owned by the SimSet.

#5
08/06/2010 (6:38 am)
thanks I get it : bool empty() const { return objectList.empty(); }

so it might be useful to set this on all stackFromXXX function :D