From 6b3fbfb5ef31bd1bcdf4bdebf0449d5b0dcea7f1 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 16 Mar 2015 17:14:56 +0100 Subject: [PATCH] io static methods --- Modular_arithmetic/include/CGAL/primes_impl.h | 4 --- Modular_arithmetic/src/CGAL/primes.cpp | 1 + Stream_support/include/CGAL/IO/io.h | 10 +++++- Stream_support/include/CGAL/IO/io_impl.h | 31 +++++-------------- cppfiles.txt | 2 +- 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Modular_arithmetic/include/CGAL/primes_impl.h b/Modular_arithmetic/include/CGAL/primes_impl.h index df0a3c4f012..340b50bb1e4 100644 --- a/Modular_arithmetic/include/CGAL/primes_impl.h +++ b/Modular_arithmetic/include/CGAL/primes_impl.h @@ -22,10 +22,6 @@ namespace CGAL { namespace internal { -#ifdef CGAL_HEADER_ONLY -const -#endif // CGAL_HEADER_ONLY - const int primes [2000] = { /* * Generated in SAGE with: diff --git a/Modular_arithmetic/src/CGAL/primes.cpp b/Modular_arithmetic/src/CGAL/primes.cpp index b16e1d9dffc..63b8b4d2800 100644 --- a/Modular_arithmetic/src/CGAL/primes.cpp +++ b/Modular_arithmetic/src/CGAL/primes.cpp @@ -18,6 +18,7 @@ // Author(s) : Michael Hemmer #ifndef CGAL_HEADER_ONLY + #include #include diff --git a/Stream_support/include/CGAL/IO/io.h b/Stream_support/include/CGAL/IO/io.h index 7042bc97c10..6b2d45e51fb 100644 --- a/Stream_support/include/CGAL/IO/io.h +++ b/Stream_support/include/CGAL/IO/io.h @@ -41,7 +41,15 @@ namespace CGAL { class IO { public: #ifndef CGAL_HEADER_ONLY - CGAL_EXPORT static int mode; + CGAL_EXPORT static int mode; + static int& get_static_mode() + { return IO::mode; } +#else // CGAL_HEADER_ONLY + inline int& get_static_mode() + { + static int mode = std::ios::xalloc(); + return mode; + } #endif // CGAL_HEADER_ONLY enum Mode {ASCII = 0, PRETTY, BINARY}; }; diff --git a/Stream_support/include/CGAL/IO/io_impl.h b/Stream_support/include/CGAL/IO/io_impl.h index 39f1e1bbd56..ee84373d5a4 100644 --- a/Stream_support/include/CGAL/IO/io_impl.h +++ b/Stream_support/include/CGAL/IO/io_impl.h @@ -36,26 +36,11 @@ namespace CGAL { -#ifdef CGAL_HEADER_ONLY -namespace { -inline int& get_static_mode() -{ - static int mode = std::ios::xalloc(); - return mode; -} -} // namespace -#else // CGAL_HEADER_ONLY -namespace { -inline int& get_static_mode() -{ return IO::mode; } -} // namespace -#endif // CGAL_HEADER_ONLY - CGAL_INLINE_FUNCTION IO::Mode get_mode(std::ios& i) { - return static_cast(i.iword(get_static_mode())); + return static_cast(i.iword(IO::get_static_mode())); } CGAL_INLINE_FUNCTION @@ -63,7 +48,7 @@ IO::Mode set_ascii_mode(std::ios& i) { IO::Mode m = get_mode(i); - i.iword(get_static_mode()) = IO::ASCII; + i.iword(IO::get_static_mode()) = IO::ASCII; return m; } @@ -72,7 +57,7 @@ IO::Mode set_binary_mode(std::ios& i) { IO::Mode m = get_mode(i); - i.iword(get_static_mode()) = IO::BINARY; + i.iword(IO::get_static_mode()) = IO::BINARY; return m; } @@ -82,7 +67,7 @@ IO::Mode set_pretty_mode(std::ios& i) { IO::Mode m = get_mode(i); - i.iword(get_static_mode()) = IO::PRETTY; + i.iword(IO::get_static_mode()) = IO::PRETTY; return m; } @@ -91,7 +76,7 @@ IO::Mode set_mode(std::ios& i, IO::Mode m) { IO::Mode old = get_mode(i); - i.iword(get_static_mode()) = m; + i.iword(IO::get_static_mode()) = m; return old; } @@ -99,21 +84,21 @@ CGAL_INLINE_FUNCTION bool is_pretty(std::ios& i) { - return i.iword(get_static_mode()) == IO::PRETTY; + return i.iword(IO::get_static_mode()) == IO::PRETTY; } CGAL_INLINE_FUNCTION bool is_ascii(std::ios& i) { - return i.iword(get_static_mode()) == IO::ASCII; + return i.iword(IO::get_static_mode()) == IO::ASCII; } CGAL_INLINE_FUNCTION bool is_binary(std::ios& i) { - return i.iword(get_static_mode()) == IO::BINARY; + return i.iword(IO::get_static_mode()) == IO::BINARY; } CGAL_INLINE_FUNCTION diff --git a/cppfiles.txt b/cppfiles.txt index 933432f7871..979f936aad3 100644 --- a/cppfiles.txt +++ b/cppfiles.txt @@ -7,7 +7,7 @@ DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/io.cpp" // va DONE #include "/home/gdamiand/sources/CGAL/Stream_support/src/CGAL/Color.cpp" // constantes globales DONE #include "/home/gdamiand/sources/CGAL/Kernel_23/src/CGAL/kernel.cpp" // constantes globales DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/Interval_arithmetic.cpp" // constante globale -DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_rounding_mode.cpp" // static const (ok car utilisé que pour debug) +DONE #include "/home/gdamiand/sources/CGAL/Number_types/src/CGAL/test_FPU_rounding_mode.cpp" // variable static de classe const DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Timer.cpp" // variable statique de classe DONE #include "/home/gdamiand/sources/CGAL/Profiling_tools/src/CGAL/Real_timer.cpp" // variable statique de classe DONE #include "/home/gdamiand/sources/CGAL/Random_numbers/src/CGAL/Random.cpp" // variable globale; utilisée directement (donc pb pour header only) -> we need to replace the use of CGAL::default_random by CGAL::get_default_random().