mirror of https://github.com/CGAL/cgal
Move Vector_2 I/O to user class level
This commit is contained in:
parent
48390a019a
commit
0e7340c184
|
|
@ -138,50 +138,6 @@ operator!=(const Null_vector &n, const VectorC2<R> &v)
|
||||||
return !(v == n);
|
return !(v == n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CGAL_NO_OSTREAM_INSERT_VECTORC2
|
|
||||||
template < class R >
|
|
||||||
std::ostream &
|
|
||||||
operator<<(std::ostream &os, const VectorC2<R> &v)
|
|
||||||
{
|
|
||||||
switch(os.iword(IO::mode)) {
|
|
||||||
case IO::ASCII :
|
|
||||||
return os << v.x() << ' ' << v.y();
|
|
||||||
case IO::BINARY :
|
|
||||||
write(os, v.x());
|
|
||||||
write(os, v.y());
|
|
||||||
return os;
|
|
||||||
default:
|
|
||||||
return os << "VectorC2(" << v.x() << ", " << v.y() << ')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // CGAL_NO_OSTREAM_INSERT_VECTORC2
|
|
||||||
|
|
||||||
#ifndef CGAL_NO_ISTREAM_EXTRACT_VECTORC2
|
|
||||||
template < class R >
|
|
||||||
std::istream &
|
|
||||||
operator>>(std::istream &is, VectorC2<R> &p)
|
|
||||||
{
|
|
||||||
typename R::FT x, y;
|
|
||||||
switch(is.iword(IO::mode)) {
|
|
||||||
case IO::ASCII :
|
|
||||||
is >> x >> y;
|
|
||||||
break;
|
|
||||||
case IO::BINARY :
|
|
||||||
read(is, x);
|
|
||||||
read(is, y);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
std::cerr << "" << std::endl;
|
|
||||||
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (is)
|
|
||||||
p = VectorC2<R>(x, y);
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
#endif // CGAL_NO_ISTREAM_EXTRACT_VECTORC2
|
|
||||||
|
|
||||||
CGAL_END_NAMESPACE
|
CGAL_END_NAMESPACE
|
||||||
|
|
||||||
#endif // CGAL_CARTESIAN_VECTOR_2_H
|
#endif // CGAL_CARTESIAN_VECTOR_2_H
|
||||||
|
|
|
||||||
|
|
@ -222,24 +222,105 @@ operator!=(const Null_vector &n, const Vector_2<R> &v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class R >
|
||||||
|
std::ostream&
|
||||||
|
insert(std::ostream& os, const Vector_2<R>& v, const Cartesian_tag&)
|
||||||
|
{
|
||||||
|
switch(os.iword(IO::mode)) {
|
||||||
|
case IO::ASCII :
|
||||||
|
return os << v.x() << ' ' << v.y();
|
||||||
|
case IO::BINARY :
|
||||||
|
write(os, v.x());
|
||||||
|
write(os, v.y());
|
||||||
|
return os;
|
||||||
|
default:
|
||||||
|
return os << "VectorC2(" << v.x() << ", " << v.y() << ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class R >
|
||||||
|
std::ostream&
|
||||||
|
insert(std::ostream& os, const Vector_2<R>& v, const Homogeneous_tag&)
|
||||||
|
{
|
||||||
|
switch(os.iword(IO::mode))
|
||||||
|
{
|
||||||
|
case IO::ASCII :
|
||||||
|
return os << v.hx() << ' ' << v.hy() << ' ' << v.hw();
|
||||||
|
case IO::BINARY :
|
||||||
|
write(os, v.hx());
|
||||||
|
write(os, v.hy());
|
||||||
|
write(os, v.hw());
|
||||||
|
return os;
|
||||||
|
default:
|
||||||
|
return os << "VectorH2(" << v.hx() << ", "
|
||||||
|
<< v.hy() << ", "
|
||||||
|
<< v.hw() << ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef CGAL_NO_OSTREAM_INSERT_VECTOR_2
|
|
||||||
template < class R >
|
template < class R >
|
||||||
std::ostream&
|
std::ostream&
|
||||||
operator<<(std::ostream& os, const Vector_2<R>& v)
|
operator<<(std::ostream& os, const Vector_2<R>& v)
|
||||||
{
|
{
|
||||||
return os << v.rep();
|
return insert(os, v, typename R::Kernel_tag() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <class R >
|
||||||
|
std::istream&
|
||||||
|
extract(std::istream& is, Vector_2<R>& v, const Cartesian_tag&)
|
||||||
|
{
|
||||||
|
typename R::FT x, y;
|
||||||
|
switch(is.iword(IO::mode)) {
|
||||||
|
case IO::ASCII :
|
||||||
|
is >> x >> y;
|
||||||
|
break;
|
||||||
|
case IO::BINARY :
|
||||||
|
read(is, x);
|
||||||
|
read(is, y);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cerr << "" << std::endl;
|
||||||
|
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (is)
|
||||||
|
v = Vector_2<R>(x, y);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class R >
|
||||||
|
std::istream&
|
||||||
|
extract(std::istream& is, Vector_2<R>& v, const Homogeneous_tag&)
|
||||||
|
{
|
||||||
|
typename R::RT hx, hy, hw;
|
||||||
|
switch(is.iword(IO::mode))
|
||||||
|
{
|
||||||
|
case IO::ASCII :
|
||||||
|
is >> hx >> hy >> hw;
|
||||||
|
break;
|
||||||
|
case IO::BINARY :
|
||||||
|
read(is, hx);
|
||||||
|
read(is, hy);
|
||||||
|
read(is, hw);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cerr << "" << std::endl;
|
||||||
|
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
v = Vector_2<R>(hx, hy, hw);
|
||||||
|
return is;
|
||||||
}
|
}
|
||||||
#endif // CGAL_NO_OSTREAM_INSERT_VECTOR_2
|
|
||||||
|
|
||||||
#ifndef CGAL_NO_ISTREAM_EXTRACT_VECTOR_2
|
|
||||||
template < class R >
|
template < class R >
|
||||||
std::istream&
|
std::istream&
|
||||||
operator>>(std::istream& is, Vector_2<R>& v)
|
operator>>(std::istream& is, Vector_2<R>& v)
|
||||||
{
|
{
|
||||||
return is >> v.rep();
|
return extract(is, v, typename R::Kernel_tag() );
|
||||||
}
|
}
|
||||||
#endif // CGAL_NO_ISTREAM_EXTRACT_VECTOR_2
|
|
||||||
|
|
||||||
CGAL_END_NAMESPACE
|
CGAL_END_NAMESPACE
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue