creativity  v1.3.0
Agent-based model of creativity and piracy
ReaderStore.hpp
1 #pragma once
2 #include <eris/types.hpp>
3 #include "creativity/gui/MemberStore.hpp"
4 #include "creativity/state/State.hpp"
5 #include <memory>
6 #include <cstddef>
7 #include <string>
8 #include <glibmm/object.h>
9 #include <glibmm/refptr.h>
10 #include <gtkmm/enums.h>
11 #include <gtkmm/treemodel.h>
12 #include <gtkmm/treemodelcolumn.h>
13 #include <gtkmm/treepath.h>
14 namespace Glib { class ValueBase; }
15 namespace Gtk { class TreeView; }
16 
17 namespace creativity { namespace gui {
18 
22 class ReaderStore : public MemberStore<state::ReaderState>, private virtual Glib::Object {
23  public:
28  static Glib::RefPtr<ReaderStore> create(std::shared_ptr<const state::State> state);
29 
34  class ColRec : public Gtk::TreeModel::ColumnRecord {
35  public:
36  Gtk::TreeModelColumn<eris::eris_id_t> id;
37  Gtk::TreeModelColumn<double> pos_x,
38  pos_y,
39  u,
40  u_lifetime,
41  creation_shape,
42  creation_scale;
43  Gtk::TreeModelColumn<std::string> pos_str;
44  Gtk::TreeModelColumn<size_t> books_owned,
45  books_purchased,
47  books_new,
48  books_new_purchased,
49  books_new_pirated,
50  books_written,
51  last_book_age,
52  num_friends;
53 
54  private:
55  ColRec() {
56  add(id); add(pos_x); add(pos_y); add(pos_str); add(u); add(u_lifetime);
57  add(creation_shape); add(creation_scale); add(num_friends);
58  add(books_owned); add(books_purchased); add(books_pirated);
59  add(books_new); add(books_new_purchased); add(books_new_pirated);
60  add(books_written); add(last_book_age);
61  }
62  friend class ReaderStore;
63  };
64 
69 
71  void appendColumnsTo(Gtk::TreeView &v) const override;
72 
73  protected:
75  ReaderStore(std::shared_ptr<const state::State> &&state);
76 
82  virtual GType get_column_type_vfunc(int index) const override;
83 
85  virtual int get_n_columns_vfunc() const override;
86 
94  virtual void get_value_vfunc(const iterator &iter, int column, Glib::ValueBase &value) const override;
95 
96  // TreeSortable overrides:
97 
109  virtual void set_sort_column_id_vfunc(int sort_column_id, Gtk::SortType order) override;
110 
111 
112  private:
113  // The various comparison functions; one of these gets passed to std::stable_sort.
114 #define LESS_GREATER_METHODS(col) \
115  static bool less_##col(const state::ReaderState &a, const state::ReaderState &b); \
116  static bool greater_##col(const state::ReaderState &a, const state::ReaderState &b);
117  LESS_GREATER_METHODS(id)
118  LESS_GREATER_METHODS(pos_x)
119  LESS_GREATER_METHODS(pos_y)
120  LESS_GREATER_METHODS(pos_str)
121  LESS_GREATER_METHODS(u)
122  LESS_GREATER_METHODS(u_lifetime)
123  LESS_GREATER_METHODS(creation_shape)
124  LESS_GREATER_METHODS(creation_scale)
125  LESS_GREATER_METHODS(books_owned)
126  LESS_GREATER_METHODS(books_purchased)
127  LESS_GREATER_METHODS(books_pirated)
128  LESS_GREATER_METHODS(books_new)
129  LESS_GREATER_METHODS(books_new_purchased)
130  LESS_GREATER_METHODS(books_new_pirated)
131  LESS_GREATER_METHODS(books_written)
132  LESS_GREATER_METHODS(num_friends)
133 #undef LESS_GREATER_METHODS
134  bool less_last_book_age(const state::ReaderState &a, const state::ReaderState &b) const;
135  bool greater_last_book_age(const state::ReaderState &a, const state::ReaderState &b) const;
136 
137 };
138 
139 }}
Definition: BookStore.hpp:14
Records the various variables associated with a reader.
Definition: ReaderState.hpp:18
Primary namespace for all Creativity library code.
Definition: config.hpp:4
Definition: BookInfoWindow.hpp:6
Base class for a flat list of simulation members.
Definition: MemberStore.hpp:21
Gtk::TreeModelColumn< size_t > num_friends
Number of friends of this reader.
Definition: ReaderStore.hpp:44
Gtk::TreeModelColumn< double > u_lifetime
Cumulative lifetime utility of the reader.
Definition: ReaderStore.hpp:37
Gtk::TreeModelColumn< eris::eris_id_t > id
ID of the reader.
Definition: ReaderStore.hpp:36
Gtk::TreeModelColumn< std::string > pos_str
position of the book as a string such as (-7.16,0.440)
Definition: ReaderStore.hpp:43
double books_pirated(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average number of books pirated per reader per period.
Gtk::TreeModel::ColumnRecord subclass for handling Reader information in the list of readers in the m...
Definition: ReaderStore.hpp:22
ColumnRecord object for a ReaderStore.
Definition: ReaderStore.hpp:34
ColRec columns
The columns of this ReaderStore.
Definition: ReaderStore.hpp:68