Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / ConsoleInterface / Toolbox.hpp
blob: 4c9544e2f8015d885b97c1664b1bb003908e4349 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef HEADER_CONSOLEINTERFACE_TOOLBOX
#define HEADER_CONSOLEINTERFACE_TOOLBOX

#include <iostream>

/*! \file Toolbox.hpp
 *  \brief Stores a wide range of functions for simpler/more automated printing.
 *
 * Adds a lot of functions for printing.
 *
 * \remark iostream is included by necessity (templated functions), you should only use the provided functions, if you can.
 */

#define MAX_LINE_WIDTH 1024

//! Clears the console screen
void clear();
//! Prints a title box
void titleBox(const char* title);
//! Prints a title sub box
void subTitleBox(const char* title);

//! Prints label, gets a whole line of input and stores it to output
void inputLineBox(const char* label, char* output, unsigned maxWidth, bool ignore = true);
//! Waits for user to press enter
void pressEnterToContinue(bool ignore = true);

//! Resets the ordered list starting number
void resetOrderedList(int starter = 1);

//! Prints a string as a table
void table(unsigned startNumber, unsigned columns, const char* items);

//! Semi-internal function that prints the spacing for sub boxes
void _printSubBoxSpacing();
//! Semi-internal function that prints the label of an input box
void _printInputBoxLabel(const char* label);
//! Semi-internal function that prints the latest ordered list index
void _printOrderedListBeginning();

//! Reads user input and stores it
template <typename T>
void read(T* storage) {
	std::cin >> storage;
}

//! Reads user input and stores it
template <typename T>
void read(T& storage) {
	std::cin >> storage;
}

//! Prints given item
template <typename T>
void print(const T* item) {
	std::cout << item;
}

//! Prints given item
template <typename T>
void print(const T& item) {
	std::cout << item;
}

//! Prints given item and an endline character
template <typename T>
void printLine(const T* item) {
	std::cout << item << std::endl;
}

//! Prints given item and an endline character
template <typename T>
void printLine(const T& item) {
	std::cout << item << std::endl;
}

//! Prints a label and then reads user input and stores it
template <typename T>
void inputBox(const char* label, T* output) {
	_printInputBoxLabel(label);
	std::cin >> *output;
}

//! Prints a label with sub box spacing and then reads user input and stores it
//! \sa _printSubBoxSpacing()
template <typename T>
void inputSubBox(const char* label, T* output) {
	_printSubBoxSpacing();
	_printInputBoxLabel(label);
	std::cin >> *output;
}

#endif