Move Vector_2 I/O to user class level

This commit is contained in:
Sylvain Pion 2006-08-05 22:34:47 +00:00
parent 48390a019a
commit 0e7340c184
2 changed files with 95 additions and 58 deletions

View File

@ -138,50 +138,6 @@ operator!=(const Null_vector &n, const VectorC2<R> &v)
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
#endif // CGAL_CARTESIAN_VECTOR_2_H

View File

@ -222,24 +222,105 @@ operator!=(const Null_vector &n, const Vector_2<R> &v)
}
#ifndef CGAL_NO_OSTREAM_INSERT_VECTOR_2
template < class R >
std::ostream &
operator<<(std::ostream &os, const Vector_2<R> &v)
template <class R >
std::ostream&
insert(std::ostream& os, const Vector_2<R>& v, const Cartesian_tag&)
{
return os << v.rep();
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_VECTOR_2
#ifndef CGAL_NO_ISTREAM_EXTRACT_VECTOR_2
template < class R >
std::istream &
operator>>(std::istream &is, Vector_2<R>& v)
template <class R >
std::ostream&
insert(std::ostream& os, const Vector_2<R>& v, const Homogeneous_tag&)
{
return is >> v.rep();
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() << ')';
}
}
template < class R >
std::ostream&
operator<<(std::ostream& os, const Vector_2<R>& v)
{
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;
}
template < class R >
std::istream&
operator>>(std::istream& is, Vector_2<R>& v)
{
return extract(is, v, typename R::Kernel_tag() );
}
#endif // CGAL_NO_ISTREAM_EXTRACT_VECTOR_2
CGAL_END_NAMESPACE