creativity  v1.3.0
Agent-based model of creativity and piracy
BookStore.hpp
1 #pragma once
2 #include "creativity/gui/MemberStore.hpp"
3 #include "creativity/state/BookState.hpp"
4 #include <eris/types.hpp>
5 #include <glibmm/object.h>
6 #include <glibmm/refptr.h>
7 #include <gtkmm/enums.h>
8 #include <gtkmm/treemodel.h>
9 #include <gtkmm/treemodelcolumn.h>
10 #include <gtkmm/treepath.h>
11 #include <memory>
12 #include <string>
13 
14 namespace Glib { class ValueBase; }
15 namespace Gtk { class TreeView; }
16 namespace creativity { namespace state { class State; } }
17 
18 
19 namespace creativity { namespace gui {
20 
24 class BookStore : public MemberStore<state::BookState>, public virtual Glib::Object {
25  public:
26  BookStore() = delete;
27 
59  static Glib::RefPtr<BookStore> create(std::shared_ptr<const state::State> state, eris::eris_id_t author = 0);
60 
65  class ColRec : public Gtk::TreeModel::ColumnRecord {
66  public:
67  Gtk::TreeModelColumn<eris::eris_id_t>
68  id,
69  author;
70 
71  Gtk::TreeModelColumn<double>
72  pos_x,
73  pos_y,
74  quality,
75  price,
76  revenue,
78 
79  Gtk::TreeModelColumn<std::string>
81  market_str;
82 
83  Gtk::TreeModelColumn<bool>
84  market_private,
86  market_any;
87 
88  Gtk::TreeModelColumn<unsigned int>
89  age,
90  created,
91  sales,
92  sales_lifetime_private,
94  sales_lifetime,
95  pirated,
96  pirated_lifetime,
97  copies,
98  copies_lifetime,
99  lifetime_private;
100 
101  protected:
102  ColRec() {
103  add(id); add(author);
104  add(pos_x); add(pos_y); add(quality); add(price); add(revenue); add(revenue_lifetime);
105  add(pos_str);
106  add(market_private); add(market_public); add(market_any); add(market_str);
107  add(age); add(created); add(sales); add(sales_lifetime_private); add(sales_lifetime_public);
108  add(sales_lifetime); add(pirated); add(pirated_lifetime);
109  add(copies); add(copies_lifetime); add(lifetime_private);
110  }
111  friend class BookStore;
112  };
113 
117  std::unique_ptr<ColRec> columns{new ColRec};
118 
120  virtual void appendColumnsTo(Gtk::TreeView &v) const override;
121 
122  protected:
124  BookStore(std::shared_ptr<const state::State> &&state, eris::eris_id_t author);
125 
127  BookStore(std::shared_ptr<const state::State> &&state, eris::eris_id_t author, std::unique_ptr<ColRec> &&cols);
128 
133  BookStore(std::shared_ptr<const state::State> &&state, std::unique_ptr<ColRec> &&cols);
134 
140  void initializeBooks();
141 
143  virtual int get_n_columns_vfunc() const override;
144 
150  virtual GType get_column_type_vfunc(int index) const override;
151 
159  virtual void get_value_vfunc(const iterator &iter, int column, Glib::ValueBase &value) const override;
160 
161  // TreeSortable overrides:
162 
174  virtual void set_sort_column_id_vfunc(int sort_column_id, Gtk::SortType order) override;
175 
176 
177  private:
178  // Filter by author, if non-zero; otherwise, this is a global book list (or a subclass
179  // handles the list)
180  const eris::eris_id_t author_ = 0;
181 
182  // The various comparison functions; one of these gets passed to std::stable_sort.
183 #define LESS_GREATER_METHODS(col) \
184  static bool less_##col(const state::BookState &a, const state::BookState &b); \
185  static bool greater_##col(const state::BookState &a, const state::BookState &b);
186  LESS_GREATER_METHODS(id)
187  LESS_GREATER_METHODS(author)
188  LESS_GREATER_METHODS(pos_x)
189  LESS_GREATER_METHODS(pos_y)
190  LESS_GREATER_METHODS(quality)
191  LESS_GREATER_METHODS(price)
192  LESS_GREATER_METHODS(revenue)
193  LESS_GREATER_METHODS(revenue_lifetime)
194  LESS_GREATER_METHODS(pos_str)
195  LESS_GREATER_METHODS(market_str)
196  LESS_GREATER_METHODS(market_private)
197  LESS_GREATER_METHODS(market_public)
198  LESS_GREATER_METHODS(market_any)
199  LESS_GREATER_METHODS(age)
200  LESS_GREATER_METHODS(created)
201  LESS_GREATER_METHODS(sales)
202  LESS_GREATER_METHODS(sales_lifetime_private)
203  LESS_GREATER_METHODS(sales_lifetime_public)
204  LESS_GREATER_METHODS(sales_lifetime)
205  LESS_GREATER_METHODS(pirated)
206  LESS_GREATER_METHODS(pirated_lifetime)
207  LESS_GREATER_METHODS(copies)
208  LESS_GREATER_METHODS(copies_lifetime)
209  LESS_GREATER_METHODS(lifetime_private)
210 #undef LESS_GREATER_METHODS
211 };
212 
213 }}
Gtk::TreeModel::ColumnRecord subclass for handling Book information in the list of books in the main ...
Definition: BookStore.hpp:24
Definition: BookStore.hpp:14
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< bool > market_public
True if on the market and that market is public.
Definition: BookStore.hpp:84
Gtk::TreeModelColumn< std::string > pos_str
position of the book as a string such as (-7.16,0.440)
Definition: BookStore.hpp:80
Gtk::TreeModelColumn< unsigned int > sales_lifetime_public
Lifetime copies sold on the public market.
Definition: BookStore.hpp:89
ColumnRecord object for a BookStore.
Definition: BookStore.hpp:65
Gtk::TreeModelColumn< double > revenue_lifetime
Cumulative revenue of the book since its creation.
Definition: BookStore.hpp:72
Gtk::TreeModelColumn< eris::eris_id_t > id
Book ID.
Definition: BookStore.hpp:68