CGAL 6.3-dev - IO Streams
Loading...
Searching...
No Matches
Reference Manual

Andreas Fabri, Geert-Jan Giezeman, and Lutz Kettner
All classes in the CGAL kernel provide input and output operators for I/O streams. The basic task of such an operator is to produce a representation of an object that can be written as a sequence of characters on devices as a console, a file, or a pipe. In CGAL we distinguish between a raw ASCII, a raw binary and a pretty printing format.
Introduced in: CGAL 1.0
BibTeX: cgal:fgk-ios-12-26b
License: LGPL

All classes in the CGAL kernel provide input and output operators for I/O streams. CGAL provides three different printing mode, defined in the enum IO::Mode , as well as different functions to set and get the printing mode.

Classified Reference Pages

Enum

Classes

Functions

I/O Functions

Topics

 Stream Operators
 I/O Functions
 I/O Enums

Classes

class  CGAL::IO::Color
 An object of the class Color is a color available for drawing operations in many CGAL output streams. More...
class  CGAL::IO::Basic_color_streambuf< CharT, Traits >
 The class template Basic_color_streambuf wraps another basic_streambuf and automatically adds ANSI color codes to the output. More...
class  CGAL::IO::Basic_color_stream_guard< StreamT >
 RAII helper class for temporarily installing a color streambuf on a stream. More...
class  CGAL::IO::Basic_indenting_streambuf< CharT, Traits >
 The class template Basic_indenting_streambuf wraps another basic_streambuf and automatically adds indentation at the beginning of each line. More...
class  CGAL::IO::Basic_indenting_stream_guard< StreamT >
 RAII helper class for temporarily installing an indenting streambuf on a stream. More...
class  CGAL::Output_rep< T, F >
 The purpose of Output_rep is to provide a way to control output formatting that works independently of the object's stream output operator. More...
class  CGAL::Input_rep< T >
 The definition of Input_rep is completely symmetric to Output_rep. More...
class  CGAL::Istream_iterator< T, Stream >
 The class Istream_iterator is an input iterator adaptor for the input stream class Stream and value type T. More...
class  CGAL::Ostream_iterator< T, Stream >
 The class Ostream_iterator is an output iterator adaptor for the output stream class Stream and value type T. More...
class  CGAL::Verbose_ostream
 The class Verbose_ostream can be used as an output stream. More...

Typedefs

using CGAL::IO::Color_streambuf = Basic_color_streambuf<char>
 Type alias for Basic_color_streambuf<char>.
using CGAL::IO::Color_wstreambuf = Basic_color_streambuf<wchar_t>
 Type alias for Basic_color_streambuf<wchar_t>.
using CGAL::IO::Color_stream_guard = Basic_color_stream_guard<std::ostream>
 Type alias for Basic_color_stream_guard<std::ostream>.
using CGAL::IO::Color_wstream_guard = Basic_color_stream_guard<std::wostream>
 Type alias for Basic_color_stream_guard<std::wostream>.
using CGAL::IO::Indenting_streambuf = Basic_indenting_streambuf<char>
 Type alias for Basic_indenting_streambuf<char>.
using CGAL::IO::Indenting_wstreambuf = Basic_indenting_streambuf<wchar_t>
 Type alias for Basic_indenting_streambuf<wchar_t>.
using CGAL::IO::Indenting_stream_guard = Basic_indenting_stream_guard<std::ostream>
 Type alias for basic_indenting_stream_guard<std::ostream>.
using CGAL::IO::Indenting_wstream_guard = Basic_indenting_stream_guard<std::wostream>
 Type alias for basic_indenting_stream_guard<std::wostream>.

Functions

std::filesystem::path CGAL::data_file_path (const std::filesystem::path &filename)
 returns the full path of a data file from CGAL.
template<Ansi_color... colors, typename... Streams>
auto CGAL::IO::make_color_guards (Streams &... streams)
 creates color guards for multiple streams simultaneously.
template<typename CharT, typename Traits>
bool CGAL::IO::stream_supports_color (const std::basic_ostream< CharT, Traits > &stream)
 checks if a stream is attached to a terminal that supports colors.
template<typename... Streams>
auto CGAL::IO::make_indenting_guards (int spaces_per_level, Streams &... streams)
 creates indenting guards for multiple streams simultaneously.
template<typename... Streams>
auto CGAL::IO::make_indenting_guards (const std::string &indent_string, Streams &... streams)
 creates indenting guards for multiple streams with a custom indent string.
template<class T>
Output_rep< T > CGAL::IO::oformat (const T &t)
 Convenience function to construct an output representation (Output_rep) for type T.
template<class T, class F>
Output_rep< T, F > CGAL::IO::oformat (const T &t, F format)
 Convenience function to construct an output representation (Output_rep) for type T.
template<class T>
Input_rep< T > CGAL::IO::iformat (T &t)
 The definition of this function is completely symmetric to oformat().
Mode CGAL::IO::get_mode (std::ios &s)
 returns the printing mode of the IO stream s.
Mode CGAL::IO::set_ascii_mode (std::ios &s)
 sets the mode of the IO stream s to be the ASCII mode.
Mode CGAL::IO::set_binary_mode (std::ios &s)
 sets the mode of the IO stream s to be the BINARY mode.
Mode CGAL::IO::set_pretty_mode (std::ios &s)
 sets the mode of the IO stream s to be the PRETTY mode.
Mode CGAL::IO::set_mode (std::ios &s, Mode m)
 sets the printing mode of the IO stream s.
bool CGAL::IO::is_pretty (std::ios &s)
 checks if the IO stream s is in PRETTY mode.
bool CGAL::IO::is_ascii (std::ios &s)
 checks if the IO stream s is in ASCII mode.
bool CGAL::IO::is_binary (std::ios &s)
 checks if the IO stream s is in BINARY mode.

Function Documentation

◆ data_file_path()

std::filesystem::path CGAL::data_file_path ( const std::filesystem::path & filename)

#include <CGAL/config.h>

returns the full path of a data file from CGAL.

The data files are located in the data directory of a CGAL release or in the directory Data/data from a git branch checkout. That function uses as prefix the environment variable CGAL_DATA_DIR if set, and the value of the macro CGAL_DATA_DIR otherwise. When using cmake and a standard CGAL setup, linking the target using that function with the target CGAL::Data will automatically set the macro CGAL_DATA_DIR pointing to the data directory of the CGAL version used. The function will attempt to open the file at the returned location and will print a warning message via std::cerr if the file could not be opened.

Examples
Stream_support/read_UTF-8.cpp.

◆ get_mode()

Mode CGAL::IO::get_mode ( std::ios & s)

◆ is_ascii()

bool CGAL::IO::is_ascii ( std::ios & s)

◆ is_binary()

bool CGAL::IO::is_binary ( std::ios & s)

◆ is_pretty()

bool CGAL::IO::is_pretty ( std::ios & s)

◆ make_color_guards()

template<Ansi_color... colors, typename... Streams>
auto CGAL::IO::make_color_guards ( Streams &... streams)

#include <CGAL/IO/Color_ostream.h>

creates color guards for multiple streams simultaneously.

This helper function creates Basic_color_stream_guard objects for multiple streams at once. All streams will use the same color settings, and their original streambufs will be automatically restored when the guards go out of scope. The guards are returned in a tuple.

Template Parameters
colorsNon-type template parameters specifying the colors to combine
StreamsThe stream types (deduced from arguments)
Parameters
streamsThe streams to apply colors to
Returns
A tuple of Basic_color_stream_guard objects
See also
Basic_color_stream_guard

Example usage:

Examples
Stream_support/color_ostream.cpp.

◆ make_indenting_guards() [1/2]

template<typename... Streams>
auto CGAL::IO::make_indenting_guards ( const std::string & indent_string,
Streams &... streams )

#include <CGAL/IO/Indenting_ostream.h>

creates indenting guards for multiple streams with a custom indent string.

This overload allows specifying a custom indentation string instead of a number of spaces.

Template Parameters
StreamsThe stream types (deduced from arguments)
Parameters
indent_stringThe indentation string to use
streamsThe streams to apply indentation to
Returns
A tuple of Basic_indenting_stream_guard objects
See also
Basic_indenting_stream_guard

◆ make_indenting_guards() [2/2]

template<typename... Streams>
auto CGAL::IO::make_indenting_guards ( int spaces_per_level,
Streams &... streams )

#include <CGAL/IO/Indenting_ostream.h>

creates indenting guards for multiple streams simultaneously.

This helper function creates Basic_indenting_stream_guard objects for multiple streams at once. All streams will use the same indentation settings, and their original streambufs will be automatically restored when the guards go out of scope. The guards are returned in a tuple.

Template Parameters
StreamsThe stream types (deduced from arguments)
Parameters
spaces_per_levelNumber of spaces per indentation level
streamsThe streams to apply indentation to
Returns
A tuple of Basic_indenting_stream_guard objects
See also
Basic_indenting_stream_guard

Example usage:

auto guards = CGAL::IO::make_indenting_guards(2, std::cout, std::cerr);
std::cout << "Indented output\n";
std::cerr << "Indented error\n";
Examples
Stream_support/indenting_ostream.cpp.

◆ oformat() [1/2]

template<class T>
Output_rep< T > CGAL::IO::oformat ( const T & t)

#include <CGAL/IO/io.h>

Convenience function to construct an output representation (Output_rep) for type T.

Generic IO for type T.

◆ oformat() [2/2]

template<class T, class F>
Output_rep< T, F > CGAL::IO::oformat ( const T & t,
F format )

#include <CGAL/IO/io.h>

Convenience function to construct an output representation (Output_rep) for type T.

Generic IO for type T with formatting tag.

◆ set_ascii_mode()

Mode CGAL::IO::set_ascii_mode ( std::ios & s)

#include <CGAL/IO/io.h>

sets the mode of the IO stream s to be the ASCII mode.

Returns the previous mode of s.

CGAL::IO::Mode

See also
CGAL::IO::set_mode()
CGAL::IO::set_binary_mode()
CGAL::IO::set_pretty_mode()
CGAL::IO::get_mode()
CGAL::IO::is_ascii()
CGAL::IO::is_binary()
CGAL::IO::is_pretty()

◆ set_binary_mode()

Mode CGAL::IO::set_binary_mode ( std::ios & s)

#include <CGAL/IO/io.h>

sets the mode of the IO stream s to be the BINARY mode.

Returns the previous mode of s.

CGAL::IO::Mode

See also
CGAL::IO::set_mode()
CGAL::IO::set_ascii_mode()
CGAL::IO::set_pretty_mode()
CGAL::IO::get_mode()
CGAL::IO::is_ascii()
CGAL::IO::is_binary()
CGAL::IO::is_pretty()

◆ set_mode()

Mode CGAL::IO::set_mode ( std::ios & s,
Mode m )

◆ set_pretty_mode()

Mode CGAL::IO::set_pretty_mode ( std::ios & s)

#include <CGAL/IO/io.h>

sets the mode of the IO stream s to be the PRETTY mode.

Returns the previous mode of s.

CGAL::IO::Mode

See also
CGAL::IO::set_mode()
CGAL::IO::set_ascii_mode()
CGAL::IO::set_binary_mode()
CGAL::IO::get_mode()
CGAL::IO::is_ascii()
CGAL::IO::is_binary()
CGAL::IO::is_pretty()

◆ stream_supports_color()

template<typename CharT, typename Traits>
bool CGAL::IO::stream_supports_color ( const std::basic_ostream< CharT, Traits > & stream)

#include <CGAL/IO/Color_ostream.h>

checks if a stream is attached to a terminal that supports colors.

This function checks if the given output stream is connected to a terminal (TTY) that can display ANSI color codes. It performs the following checks:

  1. Verifies the stream is attached to a TTY device using isatty()
  2. Checks if the TERM environment variable indicates color support
  3. Respects the NO_COLOR environment variable (if set, colors are disabled)
  4. Respects the CLICOLOR_FORCE environment variable (if set, colors are enabled)
Parameters
streamThe output stream to check (e.g., std::cout, std::cerr)
Returns
true if the stream supports color output, false otherwise
Note
This function may return false negatives on some systems, but should never return false positives (it won't report color support where it doesn't exist).
See also
Basic_color_streambuf

Example usage:

if(CGAL::IO::stream_supports_color(std::cout)) {
CGAL::IO::Color_stream_guard guard(std::cout, CGAL::IO::Ansi_color::Red);
std::cout << "This text is red!\n";
} else {
std::cout << "Plain text output\n";
}
Examples
Stream_support/color_ostream.cpp.