From d61faa164334df4e75a666ecedee24c5930fb539 Mon Sep 17 00:00:00 2001 From: POUGET Marc Date: Wed, 29 Jan 2025 17:20:07 +0100 Subject: [PATCH] I/O factoring --- ...Triangulation_on_hyperbolic_surface_2_IO.h | 54 ++++++++++++++++ ...Triangulation_on_hyperbolic_surface_2_IO.h | 61 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 Triangulation_on_hyperbolic_surface_2/doc/Triangulation_on_hyperbolic_surface_2/CGAL/Triangulation_on_hyperbolic_surface_2_IO.h create mode 100644 Triangulation_on_hyperbolic_surface_2/include/CGAL/Triangulation_on_hyperbolic_surface_2_IO.h diff --git a/Triangulation_on_hyperbolic_surface_2/doc/Triangulation_on_hyperbolic_surface_2/CGAL/Triangulation_on_hyperbolic_surface_2_IO.h b/Triangulation_on_hyperbolic_surface_2/doc/Triangulation_on_hyperbolic_surface_2/CGAL/Triangulation_on_hyperbolic_surface_2_IO.h new file mode 100644 index 00000000000..9a6496ce02d --- /dev/null +++ b/Triangulation_on_hyperbolic_surface_2/doc/Triangulation_on_hyperbolic_surface_2/CGAL/Triangulation_on_hyperbolic_surface_2_IO.h @@ -0,0 +1,54 @@ +namespace CGAL{ + + /*! + \ingroup PkgHyperbolicSurfaceTriangulation2InputOutput + inserts the triangulation in a stream. + The format of the output is the following. + Each dart of the triangulation is given an index between \f$ 0 \f$ and \f$ n-1 \f$, where \f$ n \f$ is the number of darts of the triangulation. + The first line contains the number \f$ n \f$ of darts. + The next line contains either 'yes' or 'no' and tells whether the triangulation has an anchor. + If the triangulation has an anchor, then the four next lines print the index of the dart of the anchor, and the three vertices of the anchor. + Then, for every triangle \f$ t \f$, the indices of the three darts of \f$ t \f$ are printed on three distinct lines. + Finally, for every edge \f$ e \f$, the indices of the two darts of \f$ e \f$ are printed on two distinct lines, followed by a third line on which the cross ratio of \f$ e \f$ is printed. + + \pre Triangulation_on_hyperbolic_surface_2::is_valid() + */ + std::ostream& operator<<(std::ostream& s, const Triangulation_on_hyperbolic_surface_2& triangulation); + + /*! + \ingroup PkgHyperbolicSurfaceTriangulation2InputOutput + extracts the triangulation from a stream. + The format of the input should be the same as the format of the output of + the '<<' operator for Triangulation_on_hyperbolic_surface_2. + */ + std::istream& operator>>(std::istream& s, Triangulation_on_hyperbolic_surface_2& triangulation); + + /*! + \ingroup PkgHyperbolicSurfaceTriangulation2InputOutput + inserts the domain in a stream. + + The format of the output is the following. + The first line prints the number \f$n\f$ of vertices of the domain. + For \f$ i=0 \f$ to \f$ n-1 \f$ the index of the side paired to side \f$ i \f$ is printed on a separate line. + For \f$ i=0 \f$ to \f$ n-1 \f$ the i-th vertex is printed on a separate line. + + \pre Hyperbolic_fundamental_domain_2< Traits >::is_valid() + */ + std::ostream& operator<<(std::ostream& s, const Hyperbolic_fundamental_domain_2& domain); + + /*! + \ingroup PkgHyperbolicSurfaceTriangulation2InputOutput + extracts the domain from a stream. + + The format of the input must be the same as the format of the output of + the '<<' operator for Hyperbolic_fundamental_domain_2. + */ + std::istream& operator>>(std::istream& s, Hyperbolic_fundamental_domain_2& domain); + + /*! + \ingroup PkgHyperbolicSurfaceTriangulation2InputOutput + inserts the isometry in a stream. + */ + std::ostream& operator<<(std::ostream& s, const Hyperbolic_isometry_2& isometry); + +}; // namespace CGAL diff --git a/Triangulation_on_hyperbolic_surface_2/include/CGAL/Triangulation_on_hyperbolic_surface_2_IO.h b/Triangulation_on_hyperbolic_surface_2/include/CGAL/Triangulation_on_hyperbolic_surface_2_IO.h new file mode 100644 index 00000000000..4a94a06f1f4 --- /dev/null +++ b/Triangulation_on_hyperbolic_surface_2/include/CGAL/Triangulation_on_hyperbolic_surface_2_IO.h @@ -0,0 +1,61 @@ +// Copyright (c) 2024 +// INRIA Nancy (France), and Université Gustave Eiffel Marne-la-Vallee (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Vincent Despré, Loïc Dubois, Marc Pouget, Monique Teillaud + +// This file contains the declaration and the implementation of the input/output +// functions for the package Triangulation_on_hyperbolic_surface_2 + +#ifndef CGAL_TRIANGULATION_ON_HYPERBOLIC_SURFACE_2_IO_H +#define CGAL_TRIANGULATION_ON_HYPERBOLIC_SURFACE_2_IO_H + +#include +#include +#include +#include + +namespace CGAL { + +//////////////////////////////////////////////////////////////////////////////// +template +std::ostream& operator<<(std::ostream& s, const Hyperbolic_fundamental_domain_2& domain){ + CGAL_precondition(domain.is_valid()); + return domain.to_stream(s); +} + +template +std::istream& operator>>(std::istream& s, Hyperbolic_fundamental_domain_2& domain){ + return domain.from_stream(s); +} + +//////////////////////////////////////////////////////////////////////////////// +template +std::ostream& operator<<(std::ostream& s, const Hyperbolic_isometry_2& isometry){ + for (int k=0; k<4; k++){ + s << isometry.get_coefficient(k); + } + return s; +} + +//////////////////////////////////////////////////////////////////////////////// +template +std::ostream& operator<<(std::ostream& s, const Triangulation_on_hyperbolic_surface_2& triangulation){ + triangulation.to_stream(s); + return s; +} + +template +void operator>>(std::istream& s, Triangulation_on_hyperbolic_surface_2& triangulation){ + triangulation.from_stream(s); +} + +} // namespace CGAL + +#endif // CGAL_TRIANGULATION_ON_HYPERBOLIC_SURFACE_2_IO_H