New Pointer-System in gtkmm 3.0



Hello,

while reading the "gtkmm 3.0"-Thread i thought of adding an universal-pointer to gtkmm. This Pointer could be a mix of those *** C-Pointers to managed widgets, C-Pointers for top-levels, the RefPtr. The basic idea is to let the Pointer decide whether a widget needs to be destroyed after leaving scope (RefPtr) or whether it's managed by a top-level-widget (WeakPtr).

A simple example would be:


Gtk::Ptr<Gtk::Window> wnd = Gtk::Window::create();
//this is a top-level widget, so it needs to be a reference-counting-pointer

Gtk::Ptr<Gtk::Button> button = Gtk::Button::create();
//this button is not assigned, so it needs to be freed when leaving scope too.

wnd->add(button);
//the button now belongs to the window, so it's destroyed when the window leaves scope //the easiest (and probably best) way to provide this, is to increment the reference-counter


Invalid Pointer would throw, if operator-> is called, so "if(ptr) ptr->()" is not nessasary any more.
This idea fits best with Gtk::Builder.

Here is some example code:

class MyWindow
: public Gtk::Window
{
public:
 MyWindow();
 ~MyWindow();

private:
 Gtk::Ptr<Gtk::Button> quit_button;
}

int main()
{
 Gtk::Ptr<MyWindow> wnd(new MyWindow);
 Gtk::Main::run(wnd);

 return 0;
}

MyWindow::MyWindow()
{
 Gtk::Ptr<Gtk::ButtonBox> box(new Gtk::Buttonbox);
 quit_button = new Gtk::Button("Quit!");

 box->append(quit_button);
 add(box);
}



The main benefits would be:
1.) A throwing operator->()
2.) Reference counting widgets (e.g. build a widget "slowly" within different scopes and add it later, like Cairo::RefPtr)
3.) A general Pointer-Syntax
4.) Support for Multithreading (???)


With regards,

michi7x7


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]