Virtual Testbed
Ship dynamics simulator for extreme conditions
DatabaseWindow.hh
1 #ifndef VTESTBED_GUI_DATABASEWINDOW_HH
2 #define VTESTBED_GUI_DATABASEWINDOW_HH
3 
4 #include <type_traits>
5 
6 #include <sqlitex/forward.hh>
7 
8 #include <vtestbed/gui/EntityDialog.hh>
9 #include <vtestbed/gui/TablePanel.hh>
10 #include <vtestbed/gui/Window.hh>
11 
12 namespace vtb {
13 
14  namespace gui {
15 
16  enum class Entity: int {Hull, Compartments, Ship};
17 
18  template <class T>
20  integer(T value) {
21  using type = typename std::underlying_type<T>::type;
22  return static_cast<type>(value);
23  }
24 
25  template <class T>
26  class DatabaseWindow: public Window {
27 
28  public:
29  enum class Action {None, Open, Import, Delete};
30 
31  private:
32  using database_type = sqlite::connection;
34  using id_type = int64_t;
35  static constexpr const size_t num_entities = 3;
36 
37  private:
38  TablePanel _table[num_entities];
39  EntityDialog _dialog[num_entities];
40  Entity _entity = Entity::Hull;
41 
42  public:
43 
45  void load(database_type* db);
46  Action draw(database_type* db);
47  inline Entity entity() const { return this->_entity; }
48  id_type selected_entity_id() const;
49 
50  private:
51 
52  inline int entity_idx() const { return static_cast<int>(this->_entity); }
53  inline int* entity_ptr() { return reinterpret_cast<int*>(&this->_entity); }
54 
55  };
56 
57  template <class T> TablePanel::table_type hull_table(sqlite::connection* db);
58  template <class T> TablePanel::table_type compartments_table(sqlite::connection* db);
59  template <class T> TablePanel::table_type ship_table(sqlite::connection* db);
60 
61  }
62 
63 }
64 
65 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9