gtkmm 4.7.1

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::Bitset Class Referencefinal

Sets of integers. More...

`#include <gtkmm/bitset.h>`

## Public Types
using | const_iterator = BitsetConstIter

## Public Member Functions
void | reference () const
| Increment the reference count for this object. More...
void | unreference () const
| Decrement the reference count for this object. More...
GtkBitset * | gobj ()
| Provides access to the underlying C instance. More...
const GtkBitset * | gobj () const
| Provides access to the underlying C instance. More...
GtkBitset * | gobj_copy () const
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
| Bitset ()=delete
| Bitset (const Bitset &)=delete
Bitset & | operator= (const Bitset &)=delete
const_iterator | begin () const
const_iterator | end () const
const_iterator | cbegin () const
const_iterator | cend () const
bool | contains (guint value) const
| Checks if the given value has been added to self. More...
bool | is_empty () const
| Check if no value is contained in bitset. More...
guint64 | get_size () const
| Gets the number of values that were added to the set. More...
guint64 | get_size (guint first, guint last) const
| Gets the number of values that are part of the set from first to last (inclusive). More...
guint | get_nth (guint nth) const
| Returns the value of the nth item in self. More...
bool | equals (const Glib::RefPtr< const Bitset > & other) const
| Returns `true` if self and other contain the same values. More...
guint | get_minimum () const
| Returns the smallest value in self. More...
guint | get_maximum () const
| Returns the largest value in self. More...
Glib::RefPtr< Bitset > | copy () const
| Creates a copy of self. More...
void | remove_all ()
| Removes all values from the bitset so that it is empty again. More...
bool | add (guint value)
| Adds value to self if it wasn't part of it before. More...
bool | remove (guint value)
| Removes value from self if it was part of it before. More...
void | add_range (guint start, guint n_items)
| Adds all values from start (inclusive) to start + n_items (exclusive) in self. More...
void | remove_range (guint start, guint n_items)
| Removes all values from start (inclusive) to start + n_items (exclusive) in self. More...
void | add_range_closed (guint first, guint last)
| Adds the closed range [ first, last], so first, last and all values in between. More...
void | remove_range_closed (guint first, guint last)
| Removes the closed range [ first, last], so first, last and all values in between. More...
void | add_rectangle (guint start, guint width, guint height, guint stride)
| Interprets the values as a 2-dimensional boolean grid with the given stride and inside that grid, adds a rectangle with the given width and height. More...
void | remove_rectangle (guint start, guint width, guint height, guint stride)
| Interprets the values as a 2-dimensional boolean grid with the given stride and inside that grid, removes a rectangle with the given width and height. More...
void | join (const Glib::RefPtr< const Bitset > & other)
| Sets self to be the union of self and other. More...
void | intersect (const Glib::RefPtr< const Bitset > & other)
| Sets self to be the intersection of self and other. More...
void | subtract (const Glib::RefPtr< const Bitset > & other)
| Sets self to be the subtraction of other from self. More...
void | difference (const Glib::RefPtr< const Bitset > & other)
| Sets self to be the symmetric difference of self and other. More...
void | shift_left (guint amount)
| Shifts all values in self to the left by amount. More...
void | shift_right (guint amount)
| Shifts all values in self to the right by amount. More...
void | splice (guint position, guint removed, guint value)
| This is a support function for `Gio::ListModel` handling, by mirroring the `GlistModel::items-changed` signal. More...

## Static Public Member Functions
static Glib::RefPtr< Bitset > | create ()
| Creates a new empty bitset. More...

## Protected Member Functions
void | operator delete (void *, std::size_t)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gtk::Bitset > | wrap (GtkBitset * object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Detailed Description

Sets of integers.

Gtk::Bitset is a data structure for representing a set of unsigned integers. Another name for this data structure is "bitmap".

This version is based on roaring bitmaps.

A bitset allows adding a set of integers and provides support for set operations like unions, intersections and checks for equality or if a value is contained in the set. Gtk::Bitset also contains various functions to query metadata about the bitset, such as the minimum or maximum values or its size.

The fastest way to iterate values in a bitset is Gtk::BitsetConstIter which allows quick iteration of all the values in a bitset.

The main use case for Gtk::Bitset is implementing complex selections for Gtk::SelectionModel.

See also
  SelectionModel, BitsetConstIter

Since gtkmm 3.98:

## Member Typedef Documentation

## ◆ const_iterator

using Gtk::Bitset::const_iterator = BitsetConstIter

## Constructor & Destructor Documentation

## ◆ Bitset() [1/2]

Gtk::Bitset::Bitset | ( |  | ) |
| delete

## ◆ Bitset() [2/2]

Gtk::Bitset::Bitset | ( | const Bitset & |  | ) |
| delete

## Member Function Documentation

## ◆ add()

bool Gtk::Bitset::add | ( | guint | value | ) |

Adds value to self if it wasn't part of it before.

Parameters

  value | Value to add.

Returns
  `true` if value was not part of self and self was changed.

## ◆ add_range()

void Gtk::Bitset::add_range | ( | guint | start,
|  | guint | n_items
| ) |  |

Adds all values from start (inclusive) to start + n_items (exclusive) in self.

Parameters

  start | First value to add.
  n_items | Number of consecutive values to add.

## ◆ add_range_closed()

void Gtk::Bitset::add_range_closed | ( | guint | first,
|  | guint | last
| ) |  |

Adds the closed range [ first, last], so first, last and all values in between.

first must be smaller than last.

Parameters

  first | First value to add.
  last | Last value to add.

## ◆ add_rectangle()

void Gtk::Bitset::add_rectangle | ( | guint | start,
|  | guint | width,
|  | guint | height,
|  | guint | stride
| ) |  |

Interprets the values as a 2-dimensional boolean grid with the given stride and inside that grid, adds a rectangle with the given width and height.

Parameters

  start | First value to add.
  width | Width of the rectangle.
  height | Height of the rectangle.
  stride | Row stride of the grid.

## ◆ begin()

const_iterator Gtk::Bitset::begin | ( |  | ) | const

## ◆ cbegin()

const_iterator Gtk::Bitset::cbegin | ( |  | ) | const
| inline

## ◆ cend()

const_iterator Gtk::Bitset::cend | ( |  | ) | const
| inline

## ◆ contains()

bool Gtk::Bitset::contains | ( | guint | value | ) | const

Checks if the given value has been added to self.

Parameters

  value | The value to check.

Returns
  `true` if self contains value.

## ◆ copy()

Glib::RefPtr<Bitset> Gtk::Bitset::copy | ( |  | ) | const

Creates a copy of self.

Returns
  A new bitset that contains the same values as self.

## ◆ create()

static Glib::RefPtr<Bitset> Gtk::Bitset::create | ( |  | ) |
| static

Creates a new empty bitset.

Returns
  A new empty bitset.

## ◆ difference()

void Gtk::Bitset::difference | ( | const Glib::RefPtr< const Bitset > & | other | ) |

Sets self to be the symmetric difference of self and other.

The symmetric difference is set self to contain all values that were either contained in self or in other, but not in both. This operation is also called an XOR.

It is allowed for self and other to be the same bitset. The bitset will be emptied in that case.

Parameters

  other | The `Gtk::Bitset` to compute the difference from.

## ◆ end()

const_iterator Gtk::Bitset::end | ( |  | ) | const

## ◆ equals()

bool Gtk::Bitset::equals | ( | const Glib::RefPtr< const Bitset > & | other | ) | const

Returns `true` if self and other contain the same values.

Parameters

  other | Another `Gtk::Bitset`.

Returns
  `true` if self and other contain the same values.

## ◆ get_maximum()

guint Gtk::Bitset::get_maximum | ( |  | ) | const

Returns the largest value in self.

If self is empty, 0 is returned.

Returns
  The largest value in self.

## ◆ get_minimum()

guint Gtk::Bitset::get_minimum | ( |  | ) | const

Returns the smallest value in self.

If self is empty, `G_MAXUINT` is returned.

Returns
  The smallest value in self.

## ◆ get_nth()

guint Gtk::Bitset::get_nth | ( | guint | nth | ) | const

Returns the value of the nth item in self.

If nth is >= the size of self, 0 is returned.

Parameters

  nth | Index of the item to get.

Returns
  The value of the nth item in self.

## ◆ get_size() [1/2]

guint64 Gtk::Bitset::get_size | ( |  | ) | const

Gets the number of values that were added to the set.

For example, if the set is empty, 0 is returned.

Note that this function returns a `guint64`, because when all values are set, the return value is `G_MAXUINT + 1`. Unless you are sure this cannot happen (it can't with `Gio::ListModel`), be sure to use a 64bit type.

Returns
  The number of values in the set.

## ◆ get_size() [2/2]

guint64 Gtk::Bitset::get_size | ( | guint | first,
|  | guint | last
| ) |  | const

Gets the number of values that are part of the set from first to last (inclusive).

Note that this function returns a `guint64`, because when all values are set, the return value is `G_MAXUINT + 1`. Unless you are sure this cannot happen (it can't with `Gio::ListModel`), be sure to use a 64bit type.

Parameters

  first | The first element to include.
  last | The last element to include.

Returns
  The number of values in the set from first to last.

## ◆ gobj() [1/2]

GtkBitset* Gtk::Bitset::gobj | ( |  | ) |

Provides access to the underlying C instance.

## ◆ gobj() [2/2]

const GtkBitset* Gtk::Bitset::gobj | ( |  | ) | const

Provides access to the underlying C instance.

## ◆ gobj_copy()

GtkBitset* Gtk::Bitset::gobj_copy | ( |  | ) | const

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ intersect()

void Gtk::Bitset::intersect | ( | const Glib::RefPtr< const Bitset > & | other | ) |

Sets self to be the intersection of self and other.

In other words, remove all values from self that are not part of other.

It is allowed for self and other to be the same bitset. Nothing will happen in that case.

Parameters

  other | The `Gtk::Bitset` to intersect with.

## ◆ is_empty()

bool Gtk::Bitset::is_empty | ( |  | ) | const

Check if no value is contained in bitset.

Returns
  `true` if self is empty.

## ◆ join()

void Gtk::Bitset::join | ( | const Glib::RefPtr< const Bitset > & | other | ) |

Sets self to be the union of self and other.

That is, add all values from other into self that weren't part of it.

It is allowed for self and other to be the same bitset. Nothing will happen in that case.

Parameters

  other | The `Gtk::Bitset` to union with.

## ◆ operator delete()

void Gtk::Bitset::operator delete | ( | void * | ,
|  | std::size_t |
| ) |  |
| protected

## ◆ operator=()

Bitset& Gtk::Bitset::operator= | ( | const Bitset & |  | ) |
| delete

## ◆ reference()

void Gtk::Bitset::reference | ( |  | ) | const

Increment the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

## ◆ remove()

bool Gtk::Bitset::remove | ( | guint | value | ) |

Removes value from self if it was part of it before.

Parameters

  value | Value to add.

Returns
  `true` if value was part of self and self was changed.

## ◆ remove_all()

void Gtk::Bitset::remove_all | ( |  | ) |

Removes all values from the bitset so that it is empty again.

## ◆ remove_range()

void Gtk::Bitset::remove_range | ( | guint | start,
|  | guint | n_items
| ) |  |

Removes all values from start (inclusive) to start + n_items (exclusive) in self.

Parameters

  start | First value to remove.
  n_items | Number of consecutive values to remove.

## ◆ remove_range_closed()

void Gtk::Bitset::remove_range_closed | ( | guint | first,
|  | guint | last
| ) |  |

Removes the closed range [ first, last], so first, last and all values in between.

first must be smaller than last.

Parameters

  first | First value to remove.
  last | Last value to remove.

## ◆ remove_rectangle()

void Gtk::Bitset::remove_rectangle | ( | guint | start,
|  | guint | width,
|  | guint | height,
|  | guint | stride
| ) |  |

Interprets the values as a 2-dimensional boolean grid with the given stride and inside that grid, removes a rectangle with the given width and height.

Parameters

  start | First value to remove.
  width | Width of the rectangle.
  height | Height of the rectangle.
  stride | Row stride of the grid.

## ◆ shift_left()

void Gtk::Bitset::shift_left | ( | guint | amount | ) |

Shifts all values in self to the left by amount.

Values smaller than amount are discarded.

Parameters

  amount | Amount to shift all values to the left.

## ◆ shift_right()

void Gtk::Bitset::shift_right | ( | guint | amount | ) |

Shifts all values in self to the right by amount.

Values that end up too large to be held in a `unsigned int` are discarded.

Parameters

  amount | Amount to shift all values to the right.

## ◆ splice()

void Gtk::Bitset::splice | ( | guint | position,
|  | guint | removed,
|  | guint | value
| ) |  |

This is a support function for `Gio::ListModel` handling, by mirroring the `GlistModel::items-changed` signal.

First, it "cuts" the values from position to removed from the bitset. That is, it removes all those values and shifts all larger values to the left by removed places.

Then, it "pastes" new room into the bitset by shifting all values larger than position by value spaces to the right. This frees up space that can then be filled.

Parameters

  position | Position at which to slice.
  removed | Number of values to remove.
  value | Number of values to add.

## ◆ subtract()

void Gtk::Bitset::subtract | ( | const Glib::RefPtr< const Bitset > & | other | ) |

Sets self to be the subtraction of other from self.

In other words, remove all values from self that are part of other.

It is allowed for self and other to be the same bitset. The bitset will be emptied in that case.

Parameters

  other | The `Gtk::Bitset` to subtract.

## ◆ unreference()

void Gtk::Bitset::unreference | ( |  | ) | const

Decrement the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

## Friends And Related Function Documentation

## ◆ wrap()

Glib::RefPtr< Gtk::Bitset > wrap | ( | GtkBitset * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.