So one of the design goals I had for this was to use the built in unique_ptr and shared_ptr classes as much as possible:
* Developers are familiar with their semantics.
* unique_ptr "moves" to shared_ptr implicitly.
I agree it'd be nicer to try and make this a template, so I'll see if I can get that to work.
I plan to (if I can get it to work) make the technique also apply to glib style property getters (mainly for char arrays).
e.g. instead of:
gchar* a = nullptr;
gchar* b = nullptr;
g_get_properties(o, "a", &a, "b", &b, nullptr);
g_free(a);
g_free(b);
doing:
GCharUPtr a, b;
g_get_properties(o, "a", Assigner<gchar>(a), "b", Assigner<gchar>(b), nullptr);
I would also like it to apply generally to any glib or gobject type that is allocated this way.
So one of the design goals I had for this was to use the built in unique_ptr and shared_ptr classes as much as possible:
* Developers are familiar with their semantics.
* unique_ptr "moves" to shared_ptr implicitly.
I agree it'd be nicer to try and make this a template, so I'll see if I can get that to work.
I plan to (if I can get it to work) make the technique also apply to glib style property getters (mainly for char arrays).
e.g. instead of:
gchar* a = nullptr;
gchar* b = nullptr;
g_get_properties(o, "a", &a, "b", &b, nullptr);
g_free(a);
g_free(b);
doing:
GCharUPtr a, b;
g_get_properties(o, "a", Assigner<gchar>(a), "b", Assigner<gchar>(b), nullptr);
I would also like it to apply generally to any glib or gobject type that is allocated this way.
e.g. a factory method:
unique_ptr<GApple> cpp_get_apple() { ptr<GApple> a; apple(_ gFactory. get(), Assigner(a))) {
unique_
if (!g_get_
throw some_error();
}
return a;
}
which I can then assign to a shared_ptr:
shared_ptr<GApple> a(cpp_get_apple()); call_that_ wants_a_ shared_ ptr(a);
other_method_