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>
46 namespace _IOWrapper {
54 virtual void read(std::istream& is) = 0;
61 virtual void write(std::ostream& os)
const = 0;
70 virtual void read(std::istream& is) {is >> m_data;}
82 virtual void write(std::ostream& os)
const {os << m_data;}
88 std::string ToStringImpl(
const BaseWrite& b, std::streamsize precision);
89 void FromStringImpl(
BaseRead& b,
const std::string& s, std::streamsize precision);
97 inline std::string
ToString(
const C& c, std::streamsize precision = 6)
107 inline void FromString(C& c,
const std::string& s, std::streamsize = 6)
110 _IOWrapper::FromStringImpl(i, s, 6);
113 void ReadCoordList(std::istream& is,
CoordType* d,
const int num);
114 void WriteCoordList(std::ostream& os,
const CoordType* d,
const int num);
118 inline std::ostream& operator<<(std::ostream& os,
const Vector<dim>& v)
120 WriteCoordList(os, v.m_elem, dim);
125 inline std::istream& operator>>(std::istream& is, Vector<dim>& v)
127 ReadCoordList(is, v.m_elem, dim);
133 inline std::ostream& operator<<(std::ostream& os,
const RotMatrix<dim>& m)
137 for(
int i = 0; i < dim; ++i) {
138 WriteCoordList(os, m.m_elem[i], dim);
139 os << (i < (dim - 1) ?
',' :
')');
146 inline std::istream& operator>>(std::istream& is, RotMatrix<dim>& m)
155 for(
int i = 0; i < dim; ++i) {
156 ReadCoordList(is, d + i * dim, dim);
158 char want = (i == dim - 1) ?
')' :
',';
170 inline std::ostream& operator<<(std::ostream& os,
const Point<dim>& p)
172 WriteCoordList(os, p.m_elem, dim);
177 inline std::istream& operator>>(std::istream& is, Point<dim>& p)
179 ReadCoordList(is, p.m_elem, dim);
185 inline std::ostream& operator<<(std::ostream& os,
const AxisBox<dim>& a)
187 return os <<
"AxisBox: m_low = " << a.m_low <<
", m_high = " << a.m_high;
191 inline std::istream& operator>>(std::istream& is, AxisBox<dim>& a)
197 }
while(next !=
'=');
203 }
while(next !=
'=');
211 inline std::ostream& operator<<(std::ostream& os,
const Ball<dim>& b)
213 return os <<
"Ball: m_center = " << b.m_center <<
214 +
", m_radius = " << b.m_radius;
218 inline std::istream& operator>>(std::istream& is, Ball<dim>& b)
224 }
while(next !=
'=');
230 }
while(next !=
'=');
238 inline std::ostream& operator<<(std::ostream& os,
const Segment<dim>& s)
240 return os <<
"Segment: m_p1 = " << s.m_p1 <<
", m_p2 = " << s.m_p2;
244 inline std::istream& operator>>(std::istream& is, Segment<dim>& s)
250 }
while(next !=
'=');
256 }
while(next !=
'=');
264 inline std::ostream& operator<<(std::ostream& os,
const RotBox<dim>& r)
266 return os <<
"RotBox: m_corner0 = " << r.m_corner0
267 <<
", m_size = " << r.m_size
268 <<
", m_orient = " << r.m_orient;
272 inline std::istream& operator>>(std::istream& is, RotBox<dim>& r)
278 }
while(next !=
'=');
284 }
while(next !=
'=');
290 }
while(next !=
'=');
297 template<> std::ostream& operator<<(std::ostream& os,
const Polygon<2>& r);
298 template<> std::istream& operator>>(std::istream& is, Polygon<2>& r);
304 inline std::ostream& operator<<(std::ostream& os,
const Line<dim>& r)
306 size_t size = r.numCorners();
315 for(
size_t i = 0; i < size; ++i)
316 os << r.getCorner(i) << (i < (dim - 1) ?
',' :
')');
Generic library namespace.
double CoordType
Basic floating point type.
void FromString(C &c, const std::string &s, std::streamsize=6)
Parse a WFMath type from a string.
std::string ToString(const C &c, std::streamsize precision=6)
Output a WFMath type as a string.
static FloatType epsilon()
This is the attempted precision of the library.