[gtkmm-documentation] Update the RefPtr appendix
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Update the RefPtr appendix
- Date: Mon, 19 Feb 2018 12:45:52 +0000 (UTC)
commit 9424b0f219e18d7187bb590b916b3d8216d3a66e
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Mon Feb 19 13:43:00 2018 +0100
Update the RefPtr appendix
Glib::RefPtr is now an alias for std::shared_ptr.
docs/tutorial/C/index-in.docbook | 29 +++++++++++++++--------------
1 files changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/docs/tutorial/C/index-in.docbook b/docs/tutorial/C/index-in.docbook
index dc2548f..9c9e5d8 100644
--- a/docs/tutorial/C/index-in.docbook
+++ b/docs/tutorial/C/index-in.docbook
@@ -8070,8 +8070,9 @@ your examples in their programs, and copies of this document
reference-counting smartpointer. You might be familiar with
<classname>std::unique_ptr<></classname>
and <classname>std::shared_ptr<></classname>, which are also smartpointers.
-<classname>Glib::RefPtr<></classname> is similar to <classname>std::shared_ptr<></classname>,
-which is also reference-counting. <classname>Glib::RefPtr<></classname> was introduced
+In >kmm;-4.0 <classname>Glib::RefPtr<></classname> is an alias for
+<classname>std::shared_ptr<></classname>,
+which is reference-counting. <classname>Glib::RefPtr<></classname> was introduced
long before there was a reference-counting smartpointer in the C++ Standard Library.
</para>
@@ -8115,13 +8116,15 @@ Glib::RefPtr<Gdk::Pixbuf> refPixbuf = Gdk::Pixbuf::create_from_file(filena
int width = refPixbuf->get_width();
</programlisting>
</para>
-<para>But unlike most smartpointers, you can't use the * operator to
-access the underlying instance.
+<para>You can also use the * operator and the <methodname>get()</methodname> method
+to access the underlying instance, but it's usually a bad idea to do so. Unless
+you are careful, you can end up with a pointer or a reference which is not included
+in the reference count.
</para>
<para>
<programlisting>
Glib::RefPtr<Gdk::Pixbuf> refPixbuf = Gdk::Pixbuf::create_from_file(filename);
-Gdk::Pixbuf& underlying = *refPixbuf; //Syntax error - will not compile.
+Gdk::Pixbuf& underlying = *refPixbuf; // Possible, but not recommended
</programlisting>
</para>
</sect1>
@@ -8138,8 +8141,8 @@ Glib::RefPtr<Gtk::TreeModel> refModel = refStore;
</programlisting>
</para>
<para>This means that any method which takes a <type>const
-Glib::RefPtr<BaseType></type> argument can also take a
-<type>const Glib::RefPtr<DerivedType></type>. The cast is
+Glib::RefPtr<BaseType>&</type> argument can also take a
+<type>const Glib::RefPtr<DerivedType>&</type>. The cast is
implicit, just as it would be for a normal pointer.</para>
<para>You can also cast to a derived type, but the syntax is
a little different than with a normal pointer.
@@ -8147,15 +8150,14 @@ a little different than with a normal pointer.
<para>
<programlisting>
Glib::RefPtr<Gtk::TreeStore> refStore =
-Glib::RefPtr<Gtk::TreeStore>::cast_dynamic(refModel);
+ std::dynamic_pointer_cast<Gtk::TreeStore>(refModel);
Glib::RefPtr<Gtk::TreeStore> refStore2 =
-Glib::RefPtr<Gtk::TreeStore>::cast_static(refModel);
+ std::static_pointer_cast<Gtk::TreeStore>(refModel);
</programlisting>
</para>
</sect1>
-
-<sect1 id="sec-refptr-checking-for-null"><title>Checking for null</title>
+<sect1 id="sec-refptr-checking-for-null"><title>Checking for nullptr</title>
<para>
Just like normal pointers, you can check whether a
<classname>RefPtr</classname> points to anything.
@@ -8163,7 +8165,7 @@ Just like normal pointers, you can check whether a
<para>
<programlisting>
Glib::RefPtr<Gtk::TreeModel> refModel = m_TreeView.get_model();
-if(refModel)
+if (refModel)
{
int cols_count = refModel->get_n_columns();
...
@@ -8172,11 +8174,10 @@ if(refModel)
</para>
<para>
But unlike normal pointers, <classname>RefPtr</classname>s are automatically
-initialized to null so you don't need to remember to do that yourself.
+initialized to <literal>nullptr</literal> so you don't need to remember to do that yourself.
</para>
</sect1>
-
<sect1 id="sec-refptr-constness"><title>Constness</title>
<para>
The use of the <literal>const</literal> keyword in C++ is not always clear. You
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]