26 #ifndef WFMATH_STREAM_H 27 #define WFMATH_STREAM_H 29 #include <wfmath/vector.h> 30 #include <wfmath/rotmatrix.h> 31 #include <wfmath/point.h> 32 #include <wfmath/axisbox.h> 33 #include <wfmath/ball.h> 34 #include <wfmath/segment.h> 35 #include <wfmath/rotbox.h> 36 #include <wfmath/polygon.h> 37 #include <wfmath/line.h> 38 #include <wfmath/error.h> 49 namespace _IOWrapper {
57 virtual void read(std::istream& is) = 0;
64 virtual void write(std::ostream& os)
const = 0;
73 virtual void read(std::istream& is) {is >> m_data;}
85 virtual void write(std::ostream& os)
const {os << m_data;}
91 std::string ToStringImpl(
const BaseWrite& b, std::streamsize precision);
92 void FromStringImpl(
BaseRead& b,
const std::string& s, std::streamsize precision);
100 inline std::string
ToString(
const C& c, std::streamsize precision = 6)
110 inline void FromString(C& c,
const std::string& s, std::streamsize = 6)
113 _IOWrapper::FromStringImpl(i, s, 6);
116 void ReadCoordList(std::istream& is,
CoordType* d,
const int num);
117 void WriteCoordList(std::ostream& os,
const CoordType* d,
const int num);
121 inline std::ostream& operator<<(std::ostream& os, const Vector<dim>& v)
123 WriteCoordList(os, v.m_elem, dim);
128 inline std::istream& operator>>(std::istream& is,
Vector<dim>& v)
130 ReadCoordList(is, v.m_elem, dim);
136 inline std::ostream& operator<<(std::ostream& os, const RotMatrix<dim>& m)
140 for(
int i = 0; i < dim; ++i) {
141 WriteCoordList(os, m.m_elem[i], dim);
142 os << (i < (dim - 1) ?
',' :
')');
149 inline std::istream& operator>>(std::istream& is,
RotMatrix<dim>& m)
158 for(
int i = 0; i < dim; ++i) {
159 ReadCoordList(is, d + i * dim, dim);
161 char want = (i == dim - 1) ?
')' :
',';
173 inline std::ostream& operator<<(std::ostream& os, const Point<dim>& p)
175 WriteCoordList(os, p.m_elem, dim);
180 inline std::istream& operator>>(std::istream& is,
Point<dim>& p)
182 ReadCoordList(is, p.m_elem, dim);
188 inline std::ostream& operator<<(std::ostream& os, const AxisBox<dim>& a)
190 return os <<
"AxisBox: m_low = " << a.m_low <<
", m_high = " << a.m_high;
194 inline std::istream& operator>>(std::istream& is,
AxisBox<dim>& a)
200 }
while(next !=
'=');
206 }
while(next !=
'=');
214 inline std::ostream& operator<<(std::ostream& os, const Ball<dim>& b)
216 return os <<
"Ball: m_center = " << b.m_center <<
217 +
", m_radius = " << b.m_radius;
221 inline std::istream& operator>>(std::istream& is,
Ball<dim>& b)
227 }
while(next !=
'=');
233 }
while(next !=
'=');
241 inline std::ostream& operator<<(std::ostream& os, const Segment<dim>& s)
243 return os <<
"Segment: m_p1 = " << s.m_p1 <<
", m_p2 = " << s.m_p2;
247 inline std::istream& operator>>(std::istream& is,
Segment<dim>& s)
253 }
while(next !=
'=');
259 }
while(next !=
'=');
267 inline std::ostream& operator<<(std::ostream& os, const RotBox<dim>& r)
269 return os <<
"RotBox: m_corner0 = " << r.m_corner0
270 <<
", m_size = " << r.m_size
271 <<
", m_orient = " << r.m_orient;
275 inline std::istream& operator>>(std::istream& is,
RotBox<dim>& r)
281 }
while(next !=
'=');
287 }
while(next !=
'=');
293 }
while(next !=
'=');
300 template<> std::ostream& operator<<(std::ostream& os, const Polygon<2>& r);
301 template<> std::istream& operator>>(std::istream& is,
Polygon<2>& r);
307 inline std::ostream& operator<<(std::ostream& os, const Line<dim>& r)
309 size_t size = r.numCorners();
318 for(
size_t i = 0; i < size; ++i)
319 os << r.getCorner(i) << (i < (dim - 1) ?
',' :
')');
326 #endif // WFMATH_STREAM_H Generic library namespace.
A dim dimensional axis-aligned box.
A dim dimensional rotation matrix. Technically, a member of the group O(dim).
double CoordType
Basic floating point type.
A dim dimensional box, lying at an arbitrary angle.
A dim dimensional vector.
The 2D specialization of the Polygon<> template.
void FromString(C &c, const std::string &s, std::streamsize=6)
Parse a WFMath type from a string.
A line segment embedded in dim dimensions.
An error thrown by operator>>() when it fails to parse wfmath types.
std::string ToString(const C &c, std::streamsize precision=6)
Output a WFMath type as a string.