mettli / guichan

Automatically exported from code.google.com/p/guichan
Other
0 stars 0 forks source link

gcn::Exception thrown if widget isn't in container. #131

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If gcn::BasicContainer::remove(Widget*) is called, but the widget was not 
added to the container, a gcn::Exception is thrown.  Should this be 
expected?

In comparison, if std::remove() (or the object specific remove(), such as 
std::list::remove()) is called, then it will not error, but rather return 
a value indicating that the requested item was not found.

I'd like to suggest changing gcn::BasicContainer::remove() to return 
either a pointer to the removed widget (or null, if not found) or a 
boolean value to indicate whether the widget was removed or not (thus 
saving the exception throw).

On the same token, it might also be helpful to include a bool 
gcn::BasicContainer::hasWidget(Widget*) to determine if the container is 
holding the requested widget or not.

Original issue reported on code.google.com by holy.smo...@gmail.com on 13 Feb 2010 at 4:20

GoogleCodeExporter commented 9 years ago
Well I think it's a matter of taste. Why do you want to remove something that 
is not 
present? It seems like an error to me. Of course, adding a method for checking 
if a 
widget is in a container or not is a good idea. I guess std::remove has 
combined the 
two methods in one operatotion.

Original comment by olof.nae...@gmail.com on 13 Feb 2010 at 5:10

GoogleCodeExporter commented 9 years ago
I've found that, in several instances, I'm not sure if the widget is present or 
not 
(it may or may not be, depending on a number of other variables).  I agree, 
though, 
that this is a matter of taste and the manner in which I've been programming.  
I 
feel that a hasWidget() method could allow for such flexibility in both cases.  
I've 
attached a patch.

Original comment by holy.smo...@gmail.com on 13 Feb 2010 at 5:30

Attachments:

GoogleCodeExporter commented 9 years ago
Crud, the hpp patch should have been 'virtual bool', not 'virtual void'.  Sorry 
:-/

Original comment by holy.smo...@gmail.com on 13 Feb 2010 at 5:52