[OpendTect_Developers] Creating detailed error messages in OpendTect

Bert Bril bert at opendtect.org
Tue Dec 15 17:04:43 CET 2009


All,


> The benefit of the BufferString compared to sprintf is that in only
> allocates the amount of memory needed, while you have to know on
> forehand how much memory you might need with sprintf.

Yes, that's right, but also the 'standard' OO advantages apply, like:

* No worries or possible errors with float vs double, signed vs 
unsigned, short vs long and so forth

further:

* Automatic selection of a good float-type format (selects f or g 
depending on the value)

* Automatic removal of trailing and leading zeros - and other garbage.


You can also use this functionality outside the scope of BufferString. 
There are loose functions toString() that convert all basic types to 
strings. They return a pointer to a static buffer - which may make them 
less useful in MT applications. But the above advantages can also make 
reports nicer (if don't need precise formatting).

One thing that hit me early on is the following:

Coord c( 3, 4 );
std::cout << toString(c.x) << ' ' << toString(c.y) << std::endl;

This will print (on single-CPU machines too):

3 3


Isn't C++ fun?


/Bert

-- 
-- Bert Bril / OpendTect developer at dGB
-- mailto:Bert.Bril at opendtect.org , http://opendtect.org





More information about the Developers mailing list