bug with wxVariant

Sebastien Senechal seb at cyberdine.ca
Sun Oct 22 15:27:29 PDT 2006


Hi  Willem,


Le mardi octobre 17 2006 18:33, Willem Kokke a écrit :
> wxVariant::GetLong ends up calling Convert
>
> bool wxVariant::Convert(long* value) const
> {
>     wxString type(GetType());
>     if (type == wxT("double"))
>         *value = (long) (((wxVariantDoubleData*)GetData())->GetValue());
>     else if (type == wxT("long"))
>         *value = ((wxVariantDataLong*)GetData())->GetValue();
> #ifdef HAVE_BOOL
>     else if (type == wxT("bool"))
>         *value = (long) (((wxVariantDataBool*)GetData())->GetValue());
> #endif
>     else if (type == wxT("string"))
>         *value = wxAtol((const wxChar*)
> ((wxVariantDataString*)GetData())->GetValue());
>     else
>         return false;
>
>     return true;
> }
>
>
> so it creates 4 temporary string object, loads of string compares and in
> the end it just calls wxAtol, which calls atol

>
> so you are creating a extra temporary wxVariant for no good reason, wasting
> memory and processor time, just to save a line of code?
- yes ! several lines of code multiplied by number of times i used that...
- alternative is to create wxString temporary variable anyway....
- i already use atoi for simple and fast conversions :) 
- and I didn't create wxVariant for that purpose, most of my variables are 
Already variant... 

generic code, less lines of code, more streamlined and readable code, less 
prone to errors, less debugging, less maintenance, less cost.
and yes there is a cost to using generic variable, must have some check on 
type at some point... 

also if i followed your suggestions, why use functionnalities like wxHashList,  
etc... instead of goo old STL functions hasmap ? waste of memory and 
processor time too ? to save a line of code or 2? :) 

but i am concerned with number of operations ttaken by this convert indeed... 
shall i avoid wxWdigets facilities and prefer stl whenever possible?


By the way,  for the exact opposite operation why is wxString(int) still 
private ? 

	this is not possible :
	wxLogVerbose( "there is " + nb + " items containing " + nb2 + "other items")

	and again... we need to put brackets and write xxx more lines of code..
	don't u find this inconvenient ? or please tell me how u do... 
	as i use lots of  debug messages ... (cost of performance but hell debugging 
is extremelly fast)

> then you might as well use atol(str.c_str()); and get it over with...
yup
>
> Some people do need to test whether the string contains a valid number. I
> prefer having a concise library instead of a library with hundreds of
> utility functions that just discard one single parameter.
I agree with you. i am not asking to change the library :)
i am still discovering wxWidgets, and i just try to understand the logic 
behind such or such functionnality. i have the impression wxWdigets is 
heavily inspired by MFC and windows programming ... 


and i still consider 
  char tot = wxVariant("255").GetChar();          => =0x00
as being a bug, since any developper stubbling upon that code cannot 'guess' 
this is not 'allowed' in that case, and will spend some debugging time 
finding out how...
  also wxVariant not being a conversion utlity is different from other 
languages (i.e. QVariant in QT)

> if you really 
> can't stand the extra line of code, write a utility functions yourself.
done

regards

seb




More information about the wx-users mailing list