NAME

Gtk2::Ex::TreeModel::ImplBits - miscellaneous helpers for TreeModel implementations

SYNOPSIS

use Gtk2::Ex::TreeModel::ImplBits;

FUNCTIONS

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.

This is designed to pick a stamp in the INIT_INSTANCE of a TreeModel object,

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.

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.

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.

EXPORTS

Nothing is exported by default, but random_stamp can be requested in usual Exporter style,

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!

SEE ALSO

Gtk2::TreeModel, Gtk2::Ex::WidgetBits, Exporter

HOME PAGE

http://user42.tuxfamily.org/gtk2-ex-widgetbits/index.html

LICENSE

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/.