Virtual Testbed
Ship dynamics simulator for extreme conditions
db/compartments.hh
1 #ifndef VTESTBED_DB_COMPARTMENTS_HH
2 #define VTESTBED_DB_COMPARTMENTS_HH
3 
4 #include <string>
5 #include <vector>
6 
7 #include <sqlitex/forward.hh>
8 
9 #include <vtestbed/core/types.hh>
10 #include <vtestbed/db/entity.hh>
11 #include <vtestbed/db/types.hh>
12 #include <vtestbed/geometry/types.hh>
13 
14 namespace vtb {
15 
16  namespace db {
17 
18  template <class T>
19  class Room {
20 
21  public:
23  using id_type = int64_t;
24 
25  private:
26  id_type _id = 0;
27  std::string _name;
28  polyhedron_type _geometry;
29 
30  public:
31 
32  void clear();
33  void read(sqlite::statement& in);
34 
35  inline id_type id() const { return this->_id; }
36  inline void id(id_type rhs) { this->_id = rhs; }
37  inline bool has_id() { return this->_id != 0; }
38  inline const std::string& name() const { return this->_name; }
39  inline void name(const std::string& rhs) { this->_name = rhs; }
40  inline const polyhedron_type& polyhedron() const { return this->_geometry; }
41  inline void polyhedron(const polyhedron_type& rhs) { this->_geometry = rhs; }
42  inline void polyhedron(polyhedron_type&& rhs) { this->_geometry = std::move(rhs); }
43 
44  };
45 
46  template <class T>
47  sqlite::statement&
48  operator>>(sqlite::statement& in, Room<T>& rhs);
49 
50  template <class T>
51  class Compartments: public Entity {
52 
53  public:
54  using room_type = Room<T>;
56  using polyhedron_type = typename room_type::polyhedron_type;
58  using vec3 = vtb::geometry::Vertex<T,3>;
59  using int3 = vtb::geometry::Vertex<int,3>;
61 
62  private:
63  room_array _rooms;
64 
65  public:
66  using Entity::filename;
67 
68  void clear();
69  void import(std::string filename);
70  void import_original();
71  void filename(const std::string& filename);
72  bool has_valid_id(sqlite::connection* db) const;
73  bool original(sqlite::connection* db) const;
74  void insert(sqlite::connection* db);
75  void copy(sqlite::connection* db);
76  void select(sqlite::connection* db);
77  void select_blobs(sqlite::connection* db);
78  void update(sqlite::connection* db);
79  void remove(sqlite::connection* db);
80  void save(sqlite::connection* db);
81  void read(sqlite::statement& in);
82 
83  void install(polyhedron_type hull, T wall_thickness, T eps);
84 
85  inline const room_array& rooms() const { return this->_rooms; }
86  inline void rooms(room_array&& rhs) { this->_rooms = std::move(rhs); }
87  void set_compartments(const core_room_array& rhs);
88  core_room_array make_compartments(bool transform) const;
89 
91  all(sqlite::connection* db);
92 
93  private:
94 
95  inline room_array& rooms() { return this->_rooms; }
96  void insert_rooms(sqlite::connection* db);
97 
98  };
99 
100  template <class T>
101  sqlite::statement&
102  operator>>(sqlite::statement& in, Compartments<T>& rhs);
103 
104  }
105 
106 }
107 
108 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9