Virtual Testbed
Ship dynamics simulator for extreme conditions
db/ship.hh
1 #ifndef VTESTBED_DB_SHIP_HH
2 #define VTESTBED_DB_SHIP_HH
3 
4 #include <vector>
5 
6 #include <vtestbed/core/types.hh>
7 #include <vtestbed/db/compartments.hh>
8 #include <vtestbed/db/hull.hh>
9 
10 namespace vtb {
11 
12  namespace db {
13 
14  template <class T>
15  class Ship {
16 
17  private:
18  using hull_type = Hull<T>;
20  using id_type = int64_t;
21  using int3 = typename compartments_type::int3;
23 
24  private:
25  id_type _id = 0;
26  hull_type _hull;
27  compartments_type _compartments;
28 
29  public:
30 
31  void clear();
32  bool has_valid_id(sqlite::connection* db) const;
33  void select(sqlite::connection* db);
34  void select_initial_blobs(sqlite::connection* db);
35  void select_final_blobs(sqlite::connection* db);
36  void save(sqlite::connection* db);
37  void remove(sqlite::connection* db);
38  void read(sqlite::statement& in);
39 
40  void generate(const int3& nrooms);
41  void install_compartments(T wall_thickness, T eps);
42 
43  inline id_type id() const { return this->_id; }
44  inline void id(id_type rhs) { this->_id = rhs; }
45  inline bool has_id() const { return this->_id != 0; }
46  T mass() const;
47  inline hull_type& hull() { return this->_hull; }
48  inline const hull_type& hull() const { return this->_hull; }
49  inline compartments_type& compartments() { return this->_compartments; }
50 
51  inline const compartments_type&
52  compartments() const {
53  return this->_compartments;
54  }
55 
56  ship_type make_ship(bool transform);
57 
58  static std::vector<Ship<T>> all(sqlite::connection* db);
59 
60  private:
61 
62  void insert_ship(sqlite::connection* db);
63  void update_ship(sqlite::connection* db);
64 
65  };
66 
67  template <class T>
68  sqlite::statement&
69  operator>>(sqlite::statement& in, Ship<T>& rhs);
70 
71  }
72 
73 }
74 
75 #endif // vim:filetype=cpp
Rigid ship with a mass and translational and angular velocity.
Definition: core/ship.hh:186
Main namespace.
Definition: convert.hh:9