Fix issues in Inventor/VRML writers

This commit is contained in:
Mael Rouxel-Labbé 2020-10-14 11:03:26 +02:00
parent f99016972e
commit 8e6f695e76
7 changed files with 25 additions and 23 deletions

View File

@ -14,6 +14,7 @@
#include <CGAL/IO/OFF/Scanner_OFF.h> #include <CGAL/IO/OFF/Scanner_OFF.h>
#include <CGAL/IO/OFF/File_scanner_OFF.h> #include <CGAL/IO/OFF/File_scanner_OFF.h>
#include <CGAL/IO/OFF/File_writer_OFF.h> #include <CGAL/IO/OFF/File_writer_OFF.h>
#include <CGAL/IO/OFF/generic_copy_OFF.h>
#include <CGAL/IO/helpers.h> #include <CGAL/IO/helpers.h>
#include <CGAL/IO/Generic_writer.h> #include <CGAL/IO/Generic_writer.h>

View File

@ -59,7 +59,7 @@ public:
typedef File_scanner_OFF Scanner; typedef File_scanner_OFF Scanner;
typedef I_Scanner_OFF_vertex_iterator<Pt> Self; typedef I_Scanner_OFF_vertex_iterator<Pt> Self;
I_Scanner_OFF_vertex_iterator(std::size_t cnt) : m_scan(0), m_cnt(cnt+1) {} I_Scanner_OFF_vertex_iterator(std::size_t cnt) : m_scan(nullptr), m_cnt(cnt+1) {}
I_Scanner_OFF_vertex_iterator( Scanner& s, int cnt) I_Scanner_OFF_vertex_iterator( Scanner& s, int cnt)
: m_scan(&s), m_cnt(cnt) : m_scan(&s), m_cnt(cnt)
{ {
@ -118,7 +118,7 @@ private:
public: public:
I_Scanner_OFF_vertex_and_normals_iterator( int cnt) I_Scanner_OFF_vertex_and_normals_iterator( int cnt)
: m_scan(0), m_cnt(cnt+1) {} : m_scan(nullptr), m_cnt(cnt+1) {}
I_Scanner_OFF_vertex_and_normals_iterator( Scanner& s, int cnt) I_Scanner_OFF_vertex_and_normals_iterator( Scanner& s, int cnt)
: m_scan(&s), m_cnt(cnt) : m_scan(&s), m_cnt(cnt)
{ {
@ -184,7 +184,7 @@ public:
typedef I_Scanner_OFF_facet_iterator Self; typedef I_Scanner_OFF_facet_iterator Self;
typedef value_type::iterator iterator; typedef value_type::iterator iterator;
I_Scanner_OFF_facet_iterator( std::size_t cnt) : m_scan(0), m_cnt(cnt+1) {} I_Scanner_OFF_facet_iterator( std::size_t cnt) : m_scan(nullptr), m_cnt(cnt+1) {}
I_Scanner_OFF_facet_iterator( Scanner& s, std::size_t cnt) I_Scanner_OFF_facet_iterator( Scanner& s, std::size_t cnt)
: m_scan(&s), m_cnt(cnt) : m_scan(&s), m_cnt(cnt)
{ {

View File

@ -52,7 +52,7 @@ generic_copy_OFF(File_scanner_OFF& scanner,
writer.write_header(out, writer.write_header(out,
scanner.size_of_vertices(), scanner.size_of_vertices(),
scanner.polyhedral_surface() ? scanner.size_of_halfedges() : 0, scanner.polyhedral_surface() ? scanner.size_of_halfedges() : 0,
scanner.size_of_facets()); scanner.size_of_facets());
// read in all vertices // read in all vertices
double x, y, z; // Point coordinates. double x, y, z; // Point coordinates.

View File

@ -25,19 +25,19 @@ namespace CGAL {
class File_writer_inventor class File_writer_inventor
{ {
Inventor_ostream_base* m_os; Inventor_ostream_base m_os;
std::size_t m_facets; std::size_t m_facets;
public: public:
File_writer_inventor() {} File_writer_inventor() {}
std::ostream& out() const { return m_os->os(); } std::ostream& out() const { return m_os.os(); }
void write_header(Inventor_ostream_base& o, void write_header(std::ostream& o,
std::size_t vertices, std::size_t vertices,
std::size_t halfedges, std::size_t halfedges,
std::size_t facets) std::size_t facets)
{ {
m_os = &o; m_os.open(o);
m_facets = facets; m_facets = facets;
out() << "# " << vertices << " vertices\n"; out() << "# " << vertices << " vertices\n";

View File

@ -31,10 +31,10 @@ namespace CGAL {
class Inventor_ostream_base class Inventor_ostream_base
{ {
private: private:
std::ostream* m_os; std::ostream* m_os = nullptr;
public: public:
Inventor_ostream_base() : m_os(0) {} Inventor_ostream_base() : m_os(nullptr) {}
Inventor_ostream_base(std::ostream& o) : m_os(&o) {} Inventor_ostream_base(std::ostream& o) : m_os(&o) {}
~Inventor_ostream_base() { close(); } ~Inventor_ostream_base() { close(); }
void open(std::ostream& o) { m_os = &o; } void open(std::ostream& o) { m_os = &o; }
@ -53,13 +53,13 @@ public:
return m_os && !m_os->fail(); return m_os && !m_os->fail();
} }
std::ostream& os() std::ostream& os() const
{ {
// The behaviour if m_os == 0 could be changed to return // The behaviour if m_os == nullptr could be changed to return
// cerr or a file handle to /dev/null. The latter one would // cerr or a file handle to /dev/null. The latter one would
// mimick the behaviour that one can still use a stream with // mimick the behaviour that one can still use a stream with
// an invalid stream, but without producing any output. // an invalid stream, but without producing any output.
CGAL_assertion( m_os != 0 ); CGAL_assertion( m_os != nullptr );
return *m_os; return *m_os;
} }
}; };

View File

@ -21,26 +21,27 @@
#include <CGAL/IO/VRML/VRML_2_ostream.h> #include <CGAL/IO/VRML/VRML_2_ostream.h>
#include <iostream>
#include <cstddef> #include <cstddef>
#include <iostream>
namespace CGAL { namespace CGAL {
class File_writer_VRML_2 class File_writer_VRML_2
{ {
VRML_2_ostream* m_os; VRML_2_ostream m_os;
std::size_t m_facets; std::size_t m_facets;
public: public:
File_writer_VRML_2() {} File_writer_VRML_2() {}
std::ostream& out() const { return m_os->os(); }
void write_header(VRML_2_ostream& o, std::ostream& out() const { return m_os.os(); }
void write_header(std::ostream& o,
std::size_t vertices, std::size_t vertices,
std::size_t halfedges, std::size_t halfedges,
std::size_t facets) std::size_t facets)
{ {
m_os = &o; m_os.open(o);
m_facets = facets; m_facets = facets;
out() << " #-- Begin of Polygon Mesh\n"; out() << " #-- Begin of Polygon Mesh\n";
@ -80,7 +81,7 @@ public:
" coordIndex [" << std::endl; " coordIndex [" << std::endl;
} }
void write_facet_begin( std::size_t) { out() << " "; } void write_facet_begin(std::size_t) { out() << " "; }
void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';} void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';}
void write_facet_end() { out() << "-1,\n"; } void write_facet_end() { out() << "-1,\n"; }
}; };

View File

@ -27,7 +27,7 @@ namespace CGAL {
class VRML_2_ostream class VRML_2_ostream
{ {
public: public:
VRML_2_ostream() : m_os(0) {} VRML_2_ostream() : m_os(nullptr) {}
VRML_2_ostream(std::ostream& o) : m_os(&o) { header(); } VRML_2_ostream(std::ostream& o) : m_os(&o) { header(); }
~VRML_2_ostream() { close(); } ~VRML_2_ostream() { close(); }
@ -44,13 +44,13 @@ public:
explicit operator bool () { return m_os && !m_os->fail(); } explicit operator bool () { return m_os && !m_os->fail(); }
std::ostream& os() std::ostream& os() const
{ {
// The behaviour if m_os == 0 could be changed to return // The behaviour if m_os == nullptr could be changed to return
// cerr or a file handle to /dev/null. The latter one would // cerr or a file handle to /dev/null. The latter one would
// mimick the behaviour that one can still use a stream with // mimick the behaviour that one can still use a stream with
// an invalid stream, but without producing any output. // an invalid stream, but without producing any output.
CGAL_assertion( m_os != 0 ); CGAL_assertion( m_os != nullptr );
return *m_os; return *m_os;
} }