Virtual Testbed
Ship dynamics simulator for extreme conditions
vsl/compartments.hh
1 #ifndef VTESTBED_VSL_COMPARTMENTS_HH
2 #define VTESTBED_VSL_COMPARTMENTS_HH
3 
4 #include <array>
5 #include <istream>
6 #include <ostream>
7 #include <string>
8 #include <vector>
9 
10 #include <vtestbed/base/blitz.hh>
11 #include <vtestbed/geometry/basis.hh>
12 #include <vtestbed/vsl/description.hh>
13 #include <vtestbed/vsl/name.hh>
14 
15 namespace vtb {
16 
17  namespace vsl {
18 
19  template <class T>
20  class Room {
21 
22  public:
23  using vec3 = blitz::TinyVector<T,3>;
26 
27  private:
28  vec3 _origin{T{}};
29  basis_type _ibasis{T{}};
30  std::string _name;
31 
32  public:
33 
34  void read(std::istream& in);
35  void write(std::ostream& out) const;
36  void clear();
37 
38  inline const std::string& name() const { return this->_name; }
39  inline const vec3& origin() const { return this->_origin; }
40  inline const basis_type& inverse_basis() const { return this->_ibasis; }
41 
43  coordinate_system() const {
44  return coordinate_system_type(inverse(inverse_basis()), origin());
45  }
46 
47  };
48 
49  template <class T>
50  inline std::istream&
51  operator>>(std::istream& in, Room<T>& rhs) {
52  rhs.read(in);
53  return in;
54  }
55 
56  template <class T>
57  inline std::ostream&
58  operator<<(std::ostream& out, const Room<T>& rhs) {
59  rhs.write(out);
60  return out;
61  }
62 
63  template <class T>
64  class Compartments {
65 
66  private:
67  using room_type = Room<T>;
69 
70  private:
71  enum class Reading {Name, Room};
72 
73  private:
74  std::string _filename;
75  Name _name;
76  Description _description;
77  room_array _rooms;
78 
79  public:
80 
81  void read(std::istream& in);
82  void write(std::ostream& out) const;
83  void clear();
84 
85  inline const room_array& rooms() const { return this->_rooms; }
86  inline void filename(const std::string& filename) { this->_filename = filename; }
87  inline const std::string& filename() const noexcept { return this->_filename; }
88  inline const Name& name() const { return this->_name; }
89  inline const Description& description() const { return this->_description; }
90 
91  private:
92 
93  void read_line(std::istream& in, Reading& state);
94  void read_room(std::istream& in);
95 
96  };
97 
98  template <class T>
99  inline std::istream&
100  operator>>(std::istream& in, Compartments<T>& rhs) {
101  rhs.read(in);
102  return in;
103  }
104 
105  template <class T>
106  inline std::ostream&
107  operator<<(std::ostream& out, const Compartments<T>& rhs) {
108  rhs.write(out);
109  return out;
110  }
111 
112  }
113 
114 }
115 
116 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9