-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.hpp
144 lines (119 loc) · 5.12 KB
/
tools.hpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// -*- mode:c++; tab-width:4 -*-
// File: tools.hpp ----------------------------------------------------
// Header file for the C++ tools library.
// Authors: Alice E. Fischer and Michael J. Fischer.
// Modified October 2019 by Ferhat Erata.
#pragma once
// Use -DDEBUG on the g++ command line to build the debug version
#ifdef DEBUG
// Macro to print and then run a line of source code
#define v(a) \
cout << "\n[" #a "]" << endl; \
a
// Macro to print a variable
#define p(a) \
cout << #a " = " << a << endl; \
a
// Macro to print a key and value
#define kv(a, b) cout << "[" #a << "\t= " << b << " ]" << endl;
// Macro to print destructors
#define d(a) cout << "\n Deleting " << #a << " " << this << dec << "...";
// Macro to print a debug separator
#define separator() \
cout << "\n"; \
cout << "---------------------------------------------------------------"; \
cout << "\n";
#else
#define DEBUG 0
// alternative way to define them:
#define v(a) a
#define p(a) a
#define kv(a, b)
#define d(a)
#define separator()
#endif
// -------------------------------------------------------------------
// Local definitions.
// Please enter your own name.
// -------------------------------------------------------------------
#define NAME "Ferhat Erata"
#define CLASS "CPSC 454/554"
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <cctype> // for isspace() and isdigit()
#include <cerrno>
#include <cmath>
#include <cstdarg> // for functions with variable # of arguments
#include <cstdio> // for C compatability
#include <cstdlib> // for malloc() and calloc()
#include <cstring> // for time_t, time() and ctime()
#include <ctime>
#include <unistd.h>
namespace color {
inline const auto red = "\033[0;31m";
inline const auto green = "\033[0;32m";
inline const auto yellow = "\033[0;33m";
inline const auto blue = "\033[0;34m";
inline const auto magenta = "\033[0;35m";
inline const auto cyan = "\033[0;36m";
inline const auto bold = "\033[1m";
inline const auto reset_bold = "\033[21m";
inline const auto underline = "\033[4m";
inline const auto reset_underline = "\033[24m";
inline const auto reset = "\033[0m";
} // namespace color
using namespace std;
// -------------------------------------------------------------------
// Macros to make more convenient use of standard library functions.
// -------------------------------------------------------------------
#define DUMPp(p) \
"\n" << hex << " " #p " @ " << (unsigned)&p \
<< " value = " << (unsigned)p << " " #p " --> " << dec << *p
#define DUMPv(k) \
"\n" << hex << " " #k " @ " << (unsigned)&k << " value = " << dec << k
// -------------------------------------------------------------------
// Routine screen and process management.-----------------------------
// -------------------------------------------------------------------
void fbanner(ostream& fout);
#define banner() fbanner(cout)
void fbye();
#define bye() fbye()
void delay(int);
// -------------------------------------------------------------------
// I/O Extension. ----------------------------------------------------
// -------------------------------------------------------------------
istream& flush(istream& is); // Used in cin >>x >>flush;
// -------------------------------------------------------------------
// Fatal error handling. ---------------------------------------------------
// -------------------------------------------------------------------
// The fatal family of tools are to provide a quick way
// to terminate a program with a descriptive message.
// While these tools should not be used in production code,
// they can be quite useful during program development
// and testing.
// The fatal() function (lower-case "f").
// This is called like C's printf() function to produce a
// formatted error comment.
void fatal(const char* format, ...);
// The Fatal() class for use with throw.
// This class is for fatal error exceptions.
// The constructor takes a format argument followed by any number
// of data arguments.
// It formats and stores an error message of at most 255 bytes.
// The what() member function returns the stored string.
class Fatal : public std::exception {
private:
char msg[256];
public:
explicit Fatal(const char* format, ...);
[[nodiscard]] const char* what() const noexcept override { return msg; }
};
// -------------------------------------------------------------------
// Time and date. ----------------------------------------------------
// -------------------------------------------------------------------
void when(char* date, char* hour);
char* today(char* date);
char* oclock(char* hour);