stdio.h
Go to the documentation of this file.
1 // ===========================================================================
2 // Copyright (c) 2011-2012 University of Pennsylvania
3 // Copyright (c) 2013-2016 Andreas Schuh
4 // All rights reserved.
5 //
6 // See COPYING file for license information or visit
7 // https://cmake-basis.github.io/download.html#license
8 // ===========================================================================
9 
10 /**
11  * @file basis/stdio.h
12  * @brief Standard I/O functions.
13  *
14  * This module defines standard I/O functions for the input and output of
15  * messages from STDIN or to STDOUT/STDERR, respectively. In particular,
16  * it includes the cstdio header file of the standard C library as well
17  * as the iostream header file of the standard C++ library. Besides these
18  * common functions of the standard C/C++ libraries, it provides some
19  * additional useful auxiliary functions. Therefore, this header file
20  * may be included instead of cstdio, stdio.h, or iostream.
21  */
22 
23 #pragma once
24 #ifndef _BASIS_STDIO_H
25 #define _BASIS_STDIO_H
26 
27 
28 #include <cstdio> // standard C I/O library
29 #include <iostream> // standard C++ I/O library
30 #include <string> // C++ string class
31 
32 
33 namespace basis {
34 
35 
36 /// @addtogroup BasisCxxUtilities
37 /// @{
38 
39 
40 /**
41  * @brief Get size of terminal window.
42  *
43  * @param [out] lines Maximum number of lines or 0 if it could not be determined.
44  * @param [out] columns Maximum number of columns or 0 if it could not be determined.
45  */
46 void get_terminal_size(int& lines, int& columns);
47 
48 /**
49  * @brief Get maximum number of lines of terminal window.
50  *
51  * @returns Maximum number of lines of terminal window.
52  */
53 int get_terminal_lines();
54 
55 /**
56  * @brief Get maximum number of columns of terminal window.
57  *
58  * @returns Maximum number of columns of terminal window.
59  */
61 
62 /**
63  * @brief Print text, wrapped at a fixed maximum number of columns.
64  *
65  * This function is inspired by the TCLAP::StdOutput::spacePrint()
66  * method written by Michael E. Smoot.
67  *
68  * @param [out] os Output stream.
69  * @param [in] text Text to be printed.
70  * @param [in] width Maximum width of each line.
71  * Set to a value less or equal to disable automatic wrapping.
72  * @param [in] indent Indent of text on each line.
73  * @param [in] offset Additional indent of all lines except the first one.
74  */
75 std::ostream& print_wrapped(std::ostream& os,
76  const std::string& text,
77  int width,
78  int indent,
79  int offset);
80 
81 /// @}
82 // Doxygen group
83 
84 
85 } // namespace basis
86 
87 
88 #endif // _BASIS_STDIO_H
void get_terminal_size(int &lines, int &columns)
Get size of terminal window.
Definition: stdio.cxx:39
Definition: basis.h:34
int get_terminal_lines()
Get maximum number of lines of terminal window.
Definition: stdio.cxx:83
std::ostream & print_wrapped(std::ostream &os, const std::string &text, int width, int indent, int offset)
Print text, wrapped at a fixed maximum number of columns.
Definition: stdio.cxx:99
int get_terminal_columns()
Get maximum number of columns of terminal window.
Definition: stdio.cxx:91