CIOF v1.0.0-build
Char Input Output Format - A simple Input and Output utility library
Loading...
Searching...
No Matches
ciof.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "CIOFpredefines.hpp"
4
5#if __cplusplus >= CIOF_DEFAULT_CPP_STD
6
7#define __CIOF_OK
8
9#include <string>
10
11namespace ciof
12{
13 /**
14 * @brief Set output configuration for ciof::impl::__out() function and its wrappers
15 */
16 typedef struct CIOFOutputConfig
17 {
18 // Add a space between parameter automaticalliy
19 bool spacing = false;
20
21 // Ignore custom and predefined formatting keywords
22 bool ignoreAllFormating = false;
23
24 // Process config
25 bool processing = true;
26
27 // Set delimiter for spacing
28 std::string spacingDelimeter = " ";
30
31 /**
32 * @brief Set output type for ciof::impl::__out() function and its helper functions
33 * Out : To Standard Output
34 * Err : To Standard Error
35 * Log : To Standard Log (Error, unbuffered)
36 */
37 enum class OutputType
38 {
39 Out, // std::cout
40 Err, // std::cerr
41 Log, // std::clog
42 };
43
44 /**
45 * @brief Set output style:
46 * Bold
47 * Italic
48 * Underline
49 * Strikethrough
50 */
58
59 /**
60 * @brief Set default output configuration
61 */
63
64 /**
65 * @brief Implementation functions
66 */
67 namespace impl
68 {
69 /**
70 * @brief Convert to string safely
71 * @param _val any convertable type to string
72 * @return std::string total converted strig
73 */
74 template <typename T>
75 std::string toString(const T &_val);
76
77 /**
78 * @brief Parse the params for printing and echoing
79 * @return _fmt parameter 1 to parse
80 * @return _args parameter 2 to the last one to parse
81 * @return std::string Total parsed
82 */
83 template <typename T, typename ... Args>
84 std::string parse(T _fmt, Args ... _args);
85
86 /**
87 * @brief Output the with its corresponding type either to:
88 * - Standard output
89 * - Standard error
90 * - Standard log (AKA: Error but unbuffered)
91 * @param _outType Type for OUT, ERR or LOG
92 * @param _t Text to add
93 */
94 template <typename T>
95 void __out(const OutputType &_outType, T _t);
96
97 /**
98 * @brief Output the with its corresponding type either to:
99 * - Standard output
100 * - Standard error
101 * - Standard log (AKA: Error but unbuffered)
102 * @param _outType Type for OUT, ERR or LOG
103 * @param _t Text to add
104 * @param _args More text to add
105 */
106 template <typename T, typename ... Args>
107 void __out(const OutputType &_outType, T _t, Args ... _args);
108 }
109
110 // NOTE: OUTPUT
111
112 // PRINT
113 /**
114 * @brief Print a new line
115 */
116 void print();
117
118 /**
119 * @brief Print to the standard output for `_t`
120 * @param _t Message to print
121 */
122 template <typename T>
123 void print(T _t);
124
125 /**
126 * @brief Print to the standard output for `_t`
127 * @param _t Message to print
128 * @param _args More messages to add
129 */
130 template <typename T, typename ... Args>
131 void print(T _t, Args ... _args);
132
133 /**
134 * @brief Print to the standard log for `_t`
135 * @param _t Message to print
136 */
137 template <typename T>
138 void printLog(T _t);
139
140 /**
141 * @brief Print to the standard log for `_t`
142 * @param _t Message to print
143 * @param _args More messages to add
144 */
145 template <typename T, typename ... Args>
146 void printLog(T _t, Args ... _args);
147
148 /**
149 * @brief Print to the standard error for `_t`
150 * @param _t Message to print
151 */
152 template <typename T>
153 void printError(T _t);
154
155 /**
156 * @brief Print to the standard error for `_t`
157 * @param _t Message to print
158 * @param _args More messages to add
159 */
160 template <typename T, typename ... Args>
161 void printError(T _t, Args ... _args);
162
163 // ECHO
164 /**
165 * @brief Echo to the standard output for `_t`
166 * @param _t Message to print
167 */
168 template <typename T>
169 void echo(T _t);
170
171 /**
172 * @brief Echo to the standard output for `_t`
173 * @param _t Message to print
174 * @param _args More messages to add
175 */
176 template <typename T, typename ... Args>
177 void echo(T _t, Args ... _args);
178
179 /**
180 * @brief Echo to the standard log for `_t`
181 * @param _t Message to print
182 */
183 template <typename T>
184 void echoLog(T _t);
185
186 /**
187 * @brief Echo to the standard log for `_t`
188 * @param _t Message to print
189 * @param _args More messages to add
190 */
191 template <typename T, typename ... Args>
192 void echoLog(T _t, Args ... _args);
193
194 /**
195 * @brief Echo to the standard error for `_t`
196 * @param _t Message to print
197 */
198 template <typename T>
199 void echoError(T _t);
200
201 /**
202 * @brief Echo to the standard log for `_t`
203 * @param _t Message to print
204 * @param _args More messages to add
205 */
206 template <typename T, typename ... Args>
207 void echoError(T _t, Args ... _args);
208
209 // NOTE: INPUT
210 /**
211 * @brief Get full input from the user with a prompt
212 * @param _prompt Prompt to user
213 * @param _var Variable to store the value
214 */
215 template <typename T>
216 void input(const std::string &_prompt, T *_var);
217
218 /**
219 * @brief Get full input from the user
220 * @param _prompt Prompt to user
221 * @param _var Variable to store the value
222 */
223 template <typename T>
224 void input(T *_var);
225
226 // NOTE: UTILS
227 /**
228 * @brief Get everything as a string format
229 * @param _t First param of the string
230 * @param _args Rest of the params of the string
231 * @return std::string Return the formatted string
232 */
233 template <typename T, typename ... Args>
234 std::string format(T _t, Args ... _args);
235
236 /**
237 * @brief Set the styles according to the `OutputStyle` type
238 * @param _style Set the style (Bold, Italics, Underline, ...)
239 * @return std::string Escape code according to the style
240 */
241 std::string styleSet(const OutputStyle &_style);
242
243 /**
244 * @brief Reset all the styles and colors in the terminal
245 * @return std::string Escape code to ereset colors and styles from terminal
246 */
247 std::string styleReset();
248
249 /**
250 * @brief Set the colors from the default color palette from the terminal
251 * @param _color Integer for color
252 * @return std::string Escape code to set the code
253 */
254 std::string colorSet(int _color);
255
256 /**
257 * @brief Set the RGB color in the terminal
258 * @param r Red color
259 * @param g Green color
260 * @param b Blue color
261 * @return std::string Color escape sequence for RGB colors
262 */
263 std::string rgbSet(unsigned int r, unsigned int g, unsigned int b);
264
265 /**
266 * @brief Initialize ANSI text option in Windows 10 or later
267 * NOTE: ONLY WORKS IN WINDOWS 10 OR LATER
268 */
269 void initANSI();
270
271 /**
272 * @brief Get the set cursor position using _row and _col
273 * @param _row Row to set (X)
274 * @param _col Column to set (Y)
275 * @return std::string Return the string to set the position using ANSI
276 */
277 std::string getCursorPos(int _row, int _col);
278
279 /**
280 * @brief Get the set cursor position using _row and _col
281 * Essentially calls the `getCursorPos()` function and then sets the row and col according to the `getCursorPos()` function
282 * @param _row Row to set (X)
283 * @param _col Column to set (Y)
284 */
285 void cursorPos(int _row, int _col);
286}
287
288#include "ciof.ipp"
289
290#else
291# error "Cannot compile with the current C++ standard"
292# pragma message("Use C++ " CIOF_TOSTRING(CIOF_DEFAULT_CPP_STD) " or higer instead of " CIOF_TOSTRING(__cplusplus))
293#endif // __cplusplus
294
Implementation functions.
Definition ciof.hpp:68
std::string parse(T _fmt, Args ... _args)
Parse the params for printing and echoing.
void __out(const OutputType &_outType, T _t)
Output the with its corresponding type either to:
std::string toString(const T &_val)
Convert to string safely.
Definition ciof.hpp:12
void initANSI()
Initialize ANSI text option in Windows 10 or later NOTE: ONLY WORKS IN WINDOWS 10 OR LATER.
Definition ciof.cpp:26
struct ciof::CIOFOutputConfig CIOFOutputConfig
Set output configuration for ciof::impl::__out() function and its wrappers.
void cursorPos(int _row, int _col)
Get the set cursor position using _row and _col Essentially calls the getCursorPos() function and the...
Definition ciof.cpp:23
std::string getCursorPos(int _row, int _col)
Get the set cursor position using _row and _col.
Definition ciof.cpp:20
OutputType
Set output type for ciof::impl::__out() function and its helper functions Out : To Standard Output Er...
Definition ciof.hpp:38
std::string styleReset()
Reset all the styles and colors in the terminal.
Definition ciof.cpp:56
std::string rgbSet(unsigned int r, unsigned int g, unsigned int b)
Set the RGB color in the terminal.
Definition ciof.cpp:62
std::string format(T _t, Args ... _args)
Get everything as a string format.
void printLog(T _t)
Print to the standard log for _t
OutputStyle
Set output style: Bold Italic Underline Strikethrough.
Definition ciof.hpp:52
CIOFOutputConfig outputConf
Set default output configuration.
Definition ciof.cpp:15
void printError(T _t)
Print to the standard error for _t
void input(const std::string &_prompt, T *_var)
Get full input from the user with a prompt.
void print()
Print a new line.
Definition ciof.cpp:17
std::string styleSet(const OutputStyle &_style)
Set the styles according to the OutputStyle type.
Definition ciof.cpp:44
void echo(T _t)
Echo to the standard output for _t
std::string colorSet(int _color)
Set the colors from the default color palette from the terminal.
Definition ciof.cpp:59
void echoError(T _t)
Echo to the standard error for _t
void echoLog(T _t)
Echo to the standard log for _t
Set output configuration for ciof::impl::__out() function and its wrappers.
Definition ciof.hpp:17
std::string spacingDelimeter
Definition ciof.hpp:28