gtkmm: Gtk::Bitset Class Reference
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 bitset. 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, that is add all values from other into self that weren't part of it. More... | |
void | intersect (const Glib::RefPtr< const Bitset >& other) |
Sets self to be the intersection of self and other, that is remove all values from self that are not part of other. More... | |
void | subtract (const Glib::RefPtr< const Bitset >& other) |
Sets self to be the subtraction of other from self, that is remove all values from self that are part of other. More... | |
void | difference (const Glib::RefPtr< const Bitset >& other) |
Sets self to be the symmetric difference of self and other, that is set self to contain all values that were either contained in self or in other, but not in both. 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 ListModel handling, by mirroring the Glist::Model::signal_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
Member Typedef Documentation
Constructor & Destructor Documentation
|
delete |
|
delete |
Member Function Documentation
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.
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.
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.
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.
const_iterator Gtk::Bitset::begin | ( | ) | const |
|
inline |
|
inline |
bool Gtk::Bitset::contains | ( | guint | value | ) | const |
Checks if the given value has been added to bitset.
- Parameters
-
value The value to check.
- Returns
true
if self contains value.
Glib::RefPtr<Bitset> Gtk::Bitset::copy | ( | ) | const |
Creates a copy of self.
- Returns
- A new bitset that contains the same values as self.
|
static |
Creates a new empty bitset.
- Returns
- A new empty bitset.
void Gtk::Bitset::difference | ( | const Glib::RefPtr< const Bitset >& | other | ) |
Sets self to be the symmetric difference of self and other, that 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.
const_iterator Gtk::Bitset::end | ( | ) | const |
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.
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.
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.
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.
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 ListModel), be sure to use a 64bit type.
- Returns
- The number of values in the set.
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 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.
GtkBitset* Gtk::Bitset::gobj | ( | ) |
Provides access to the underlying C instance.
const GtkBitset* Gtk::Bitset::gobj | ( | ) | const |
Provides access to the underlying C instance.
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.
void Gtk::Bitset::intersect | ( | const Glib::RefPtr< const Bitset >& | other | ) |
Sets self to be the intersection of self and other, that is 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.
bool Gtk::Bitset::is_empty | ( | ) | const |
Check if no value is contained in bitset.
- Returns
true
if self is empty.
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.
|
protected |
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.
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.
void Gtk::Bitset::remove_all | ( | ) |
Removes all values from the bitset so that it is empty again.
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.
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.
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.
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.
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.
void Gtk::Bitset::splice | ( | guint | position, |
guint | removed, | ||
guint | value | ||
) |
This is a support function for ListModel handling, by mirroring the Glist::Model::signal_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.
void Gtk::Bitset::subtract | ( | const Glib::RefPtr< const Bitset >& | other | ) |
Sets self to be the subtraction of other from self, that is 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.
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
|
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.