-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.cpp
More file actions
93 lines (75 loc) · 2.83 KB
/
message.cpp
File metadata and controls
93 lines (75 loc) · 2.83 KB
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
/*****************************************************************************
* @file message.cpp *
* @brief 信息处理类 *
* @details 用于打印程序运行过程中需要展示的信息,包括警告和报错 *
* @author Dong Yu *
* @email 213191838@seu.edu.cn *
* @version 0.9 *
* @date 2022/10/31 *
* *
*----------------------------------------------------------------------------*
* Change History : *
* <Date> | <Version> | <Author> | <Description> *
*----------------------------------------------------------------------------*
* 2022/10/28 | 0.1 | Dong Yu | Copy from User-Equilibrium v0.9 *
*----------------------------------------------------------------------------*
* 2022/10/31 | 0.9 | Dong Yu | Added Timer (with a problem) *
*----------------------------------------------------------------------------*
* *
*****************************************************************************/
#include "stdafx.h"
#include "message.h"
#include <windows.h> // TODO: ???
bool timer = false;
LARGE_INTEGER freq;
LARGE_INTEGER beginTime;
LARGE_INTEGER endTime;
void StartTimer() {
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&beginTime);
timer = true;
}
void StatusMessage(const string& message) {
// 后续在参数与格式方面可以继续拓展
if (timer) {
StatusTime();
}
cout << message << endl;
}
void StatusIter(const int& num, const int& len, const string& fill) {
// cout << "iter = " << setfill(fill) << setw(len) << num << ": ";
if (timer) {
StatusTime();
}
cout << "iter = " << num << ": ";
}
void StatusTime() {
QueryPerformanceCounter(&endTime);
int timeOfMicroSecond = (double)(endTime.QuadPart - beginTime.QuadPart) * 1e6 / (double)freq.QuadPart;
cout << "[" << setfill('0') << setw(8) << to_string(timeOfMicroSecond) << "] ";
}
void StatusMessageB(const string& message, const string& connector) {
if (timer) {
StatusTime();
}
cout << message << connector;
}
void StatusMessageA(const string& message) {
if (message == "")
cout << "Succeed!" << endl;
else
cout << message << endl;
}
void Warning(const string& message) {
if (timer) {
StatusTime();
}
cout << "Warning: " << message << endl;
}
void ExitMessage(const string& message) {
if (timer) {
StatusTime();
}
cout << "Error: " << message << endl;
exit(EXIT_FAILURE);
}