Gtk2::Ex::TreeModel::ImplBits - miscellaneous helpers for TreeModel implementations
use Gtk2::Ex::TreeModel::ImplBits;
Gtk2::Ex::TreeModel::ImplBits::random_stamp ($model)
Set $model->{'stamp'} to a randomly chosen stamp (an integer) between 1 and 2**31-1 inclusive. If $model->{'stamp'} is an existing stamp value then that's excluded, ensuring a new value.
$model->{'stamp'}
This is designed to pick a stamp in the INIT_INSTANCE of a TreeModel object,
INIT_INSTANCE
use Gtk2::Ex::TreeModel::ImplBits; sub INIT_INSTANCE { my ($self) = @_; Gtk2::Ex::TreeModel::ImplBits::random_stamp ($self); # ... }
and also later to change stamp to deliberately invalidate iters an application might still have. This can be when the last row is deleted, so no iter can possibly be valid, or when the model is not iters-persist and a delete, insert or reorder has moved memory etc rendering existing iter pointers or references invalid.
iters-persist
Zero is not used for a stamp because it's what ListStore and TreeStore remove set to invalidate an iter when no next row. Negatives are not used because Perl-Gtk 1.220 on a system with 64-bit IV and 32-bit gint will sometimes zero extend (instead of sign extend), giving back a positive value. In the future though it might be possible to use negatives, or a full 64-bit gint on a 64-bit system.
remove
Gtk2::TreeStore uses a similar randomly chosen stamp. With a random stamp there's a small chance an iter misuse will be undetected because stamps happen to match. But this will be extremely rare, and randomness has the considerable advantage that it won't be systematically tricked by something semi-deterministic like uninitialized or re-used memory.
Gtk2::TreeStore
Nothing is exported by default, but random_stamp can be requested in usual Exporter style,
random_stamp
Exporter
use Gtk2::Ex::TreeModel::ImplBits 'random_stamp'; sub remove { my ($self, $iter) = @_; # ... if (have_become_empty) { # no iter can be valid, new stamp to enforce that random_stamp ($self); } }
There's no :all tag since this module is meant as a grab-bag of functions and to import yet unknown names would be asking for trouble!
:all
Gtk2::TreeModel, Gtk2::Ex::WidgetBits, Exporter
http://user42.tuxfamily.org/gtk2-ex-widgetbits/index.html
Copyright 2009, 2010, 2011, 2012 Kevin Ryde
Gtk2-Ex-WidgetBits is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Gtk2-Ex-WidgetBits is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Gtk2-Ex-WidgetBits. If not, see http://www.gnu.org/licenses/.
To install Gtk2::Ex::WidgetBits, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gtk2::Ex::WidgetBits
CPAN shell
perl -MCPAN -e shell install Gtk2::Ex::WidgetBits
For more information on module installation, please visit the detailed CPAN module installation guide.