PDA

View Full Version : ClanLib 3.1 pulling and pushing



rombust
10-08-2013, 08:10 AM
A thought for the future.

Currently we have on clan::Canvas

push_cliprect, pull_cliprect, push_modelview, pull_modelview

These cause problems, if you want to handle exceptions that are thrown.

For example, here an exception is thrown and modelview will not be popped


func()
{
canvas.push_modelview();
if (error)
throw clan::Exception("Oh dear");
canvas.pop_modelview();
}

I am not entire sure what the best solution is.

But something to think about one day.

Judas
10-09-2013, 08:01 PM
The only nice way to deal with things like that is to create scope classes which restore/pop in their destructor.

In classical device contexts you have a "SaveDC" function and a restore function. In C++, the easiest way to implement something like that would be to do:



CanvasCheckpoint cp(canvas);
canvas.push();
yadayada();
canvas.pop();
cp.end();


If the destructor for cp is called without a call to end() then it means an exception occured. This strategy is equivalent to MutexSection, DBTransaction, PixelBufferLock, and so on.