creativity
v1.3.0
Agent-based model of creativity and piracy
|
Base class for a flat list of simulation members. More...
#include <creativity/gui/MemberStore.hpp>
Public Member Functions | |
virtual void | appendColumnsTo (Gtk::TreeView &v) const =0 |
Takes a Gtk::TreeView and adds this object's columns to it. More... | |
const M & | member (const Path &path) const |
Gets the M Member from a Path. More... | |
const M & | member (const iterator &iter) const |
Gets the M Member from an iterator. More... | |
Path | find (eris::eris_id_t id, size_t hint=0) const |
Returns the Path to the member with the given id. More... | |
Path | find (eris::eris_id_t id, const iterator &iter) const |
Returns the Path to the member with the given id. More... | |
Path | find (eris::eris_id_t id, const Path &hint) const |
Returns the Path to the member with the given id. More... | |
Protected Member Functions | |
MemberStore (std::shared_ptr< const state::State > &&state) | |
Protected constructor; this object should be constructed from a subclass, typically via the subclass's static create() method. More... | |
virtual Gtk::TreeModelFlags | get_flags_vfunc () const override |
Returns Gtk::TreeModel flags (specifically, the LIST_ONLY flag). More... | |
virtual int | get_n_columns_vfunc () const override=0 |
Returns obj.columns.size() , the number of model columns. More... | |
virtual GType | get_column_type_vfunc (int index) const override=0 |
Returns the column type of the given position. More... | |
virtual bool | get_iter_vfunc (const Path &path, iterator &iter) const override |
Converts a path to an iterator. More... | |
virtual bool | iter_next_vfunc (const iterator &iter, iterator &iter_next) const override |
Takes an iterator, returns an iterator to the next item. More... | |
virtual bool | iter_children_vfunc (const iterator &, iterator &) const override |
Returns false always: MemberStore elements cannot have children. | |
virtual bool | iter_parent_vfunc (const iterator &, iterator &) const override |
Returns false always: MemberStore elemenets cannot have children/parents. | |
virtual bool | iter_nth_child_vfunc (const iterator &, int, iterator &) const override |
Returns false always: MemberStore elements cannot have children. | |
virtual bool | iter_has_child_vfunc (const iterator &) const override |
Returns false always: MemberStore elements cannot have children. | |
virtual int | iter_n_children_vfunc (const iterator &) const override |
Returns 0 always: MemberStore elements have no children. | |
virtual bool | iter_nth_root_child_vfunc (int n, iterator &iter) const override |
Obtains an iterator to the n th reader. More... | |
virtual int | iter_n_root_children_vfunc () const override |
Returns the number of readers stored in this model. | |
virtual Path | get_path_vfunc (const iterator &iter) const override |
Converts iterator iter into a Path. | |
virtual void | get_value_vfunc (const iterator &iter, int column, Glib::ValueBase &value) const override=0 |
Accesses a column value. More... | |
virtual bool | get_sort_column_id_vfunc (int *sort_column_id, Gtk::SortType *order) const override |
Accesses the current sort column and order. More... | |
virtual void | set_sort_column_id_vfunc (int sort_column_id, Gtk::SortType order) override=0 |
Sets the model sort column and sort order. More... | |
virtual void | sort_members (std::function< bool(const M &a, const M &b)> &compare, int sort_column_id, Gtk::SortType order) |
Called by subclasses, typically in set_sort_column_id_vfunc, to resort the current list of members using the given function. More... | |
template<typename T , typename = typename std::enable_if<std::is_base_of<Gtk::TreeModelColumnBase, T>::value>> | |
void | appendCol (Gtk::TreeView &v, const std::string &label, T &col, int width, bool sortable=true) const |
Appends a single column to the given view using the given label, width, and sortability. More... | |
Static Protected Member Functions | |
template<typename T > | |
static void | copy_value_ (Glib::ValueBase &valueobj, const T &val) |
Helper method for the crap needed in get_value_vfunc(): creates a Glib::Value of the right type and copies it into the given Glib::ValueBase. More... | |
Protected Attributes | |
const std::shared_ptr< const state::State > | state_ |
The state this MemberStore represents. | |
std::vector< std::reference_wrapper< const M > > | members_ |
The vector of members. Subclasses need to add all member references to this vector. | |
int | stamp_ = 1 |
Tracks model changes by being incremented whenever such a change occurs. | |
Base class for a flat list of simulation members.
Note: the implementing class must inherit from Glib::ObjectBase and call the Glib::ObjectBase(typeid(CLASS)) constructor to register the type with Glib.
M | the state type being represented by this MemberStore such as BookState or ReaderState . |
|
protected |
Protected constructor; this object should be constructed from a subclass, typically via the subclass's static create() method.
Subclasses must inherit from Glib::ObjectBase and call the Glib::ObjectBase(typeid(CLASS)) constructor to register the type with Glib. See gui/ReaderStore.hpp for an example.
state | a reference to a simulation state object. The object's lifespan should exceed the lifespan of the MemberStore-derived object. |
|
inlineprotected |
Appends a single column to the given view using the given label, width, and sortability.
v | the TreeView to add the column to |
label | the string for the column header |
col | the model column object, typically a member of store.columns such as readerstore.columns.id . |
width | the fixed width of the column |
sortable | if omitted (or true) the column will be user-sortable by clicking on the column header; if specified explicitly as false, user sorting will be disabled. |
|
pure virtual |
Takes a Gtk::TreeView and adds this object's columns to it.
Implemented in creativity::gui::BookStore, creativity::gui::ReaderStore, and creativity::gui::LibraryStore.
|
staticprotected |
Helper method for the crap needed in get_value_vfunc(): creates a Glib::Value of the right type and copies it into the given Glib::ValueBase.
Gtk::TreeModel::Path creativity::gui::MemberStore< M >::find | ( | eris::eris_id_t | id, |
size_t | hint = 0 |
||
) | const |
Returns the Path to the member with the given id.
Returns an empty path if the id was not found.
This does a linear search of the current member list. If the optional hint
is given, locations near hint
are checked first; otherwise this does a linear search beginning from 0.
id | the id to compare against members_[i].id to find the element's position. |
hint | if provided as a non-zero, this starts looking at and near the given position, iterating outward in both directions. This is a useful optimization when calling find() on a model that has a reasonable chance of having the elements in the same (or nearby) positions. |
Gtk::TreeModel::Path creativity::gui::MemberStore< M >::find | ( | eris::eris_id_t | id, |
const iterator & | iter | ||
) | const |
Returns the Path to the member with the given id.
The hint
iterator is used to determine the position to check first; if it doesn't match the requested ID, a linear search of all members is performed.
Gtk::TreeModel::Path creativity::gui::MemberStore< M >::find | ( | eris::eris_id_t | id, |
const Path & | hint | ||
) | const |
Returns the Path to the member with the given id.
The hint
path is used to determine the position to check first; if it doesn't match the requested ID, a linear search of all members is performed.
|
overrideprotectedpure virtual |
Returns the column type of the given position.
This is typically invoked via get_column_type, itself given a column member of the .columns
ColRec object.
Implemented in creativity::gui::BookStore, and creativity::gui::ReaderStore.
|
overrideprotectedvirtual |
Returns Gtk::TreeModel flags (specifically, the LIST_ONLY flag).
|
overrideprotectedvirtual |
Converts a path to an iterator.
path | the path (in) |
iter | the iterator to set (out) |
iter
if the path refers to a valid element, returns false otherwise.
|
overrideprotectedpure virtual |
Returns obj.columns.size()
, the number of model columns.
Implemented in creativity::gui::BookStore, and creativity::gui::ReaderStore.
|
overrideprotectedvirtual |
Accesses the current sort column and order.
Returns true if accessed sort_column_id refers to a specific column (instead of the Gtk magic unsorted and default order constants).
sort_column_id | a pointer in which to store the sort column. May be a nullptr to skip accessing the sort column. |
order | a pointer in which to store the sort order. May be a nullptr to skip accessing the sort order. |
|
overrideprotectedpure virtual |
Accesses a column value.
iter | a valid iterator referencing the row to access |
column | the index of the column to access |
value | a Glib::Value<TYPE> object (where TYPE is the appropriate type for the requested column ) in which to store the value. |
Implemented in creativity::gui::BookStore, creativity::gui::ReaderStore, and creativity::gui::LibraryStore.
|
overrideprotectedvirtual |
Takes an iterator, returns an iterator to the next item.
iter | the current element (in) |
iter_next | the next element (out) |
iter_next
if iter
is valid (i.e. the model hasn't changed since the iterator was created) and there is a next element; returns false otherwise.
|
overrideprotectedvirtual |
Obtains an iterator to the n
th reader.
n | the index of the reader to access |
iter | an iterator to set to the requested reader |
n
is valid (i.e. there are at least n+1
readers); false otherwise. const M & creativity::gui::MemberStore< M >::member | ( | const Path & | path | ) | const |
Gets the M Member from a Path.
Throws an exception if the Path is invalid.
const M & creativity::gui::MemberStore< M >::member | ( | const iterator & | iter | ) | const |
Gets the M Member from an iterator.
Throws an exception if the iterator is invalid.
|
overrideprotectedpure virtual |
Sets the model sort column and sort order.
If the sort_column and order differ from the current values, the model data is resorted. If resorting occurs, the sort_column_changed and rows_reordered signals will fire.
Implemented in creativity::gui::BookStore, creativity::gui::ReaderStore, and creativity::gui::LibraryStore.
|
protectedvirtual |
Called by subclasses, typically in set_sort_column_id_vfunc, to resort the current list of members using the given function.
This uses std::stable_sort, which means the current order is maintained for any members that are equal according to the given comparison function.
This fires sort_column_changed if the sort column and/or sort order are changing from their current values, and rows_reordered if the sorting actually changes any row orders.
If compare is not callable, this method does nothing.
compare | a function (or callable object) that returns true if its first arguments should (strictly) come before its second argument, and false otherwise. |
sort_column_id | the new sort column |
order | the new sort order |