macOS小bug修复&更好的格式。
This commit is contained in:
14
大作业/Date.cpp
14
大作业/Date.cpp
@@ -3,7 +3,7 @@
|
||||
|
||||
Date::Date() : time(0), _isAny(true){};
|
||||
|
||||
Date::Date(const time_t &_time) : time(_time), _isAny(false) {};
|
||||
Date::Date(const time_t &_time) : time(_time), _isAny(false){};
|
||||
|
||||
Date::Date(const tm &_time) : _isAny(false) {
|
||||
tm temp = _time;
|
||||
@@ -41,13 +41,13 @@ std::string Date::toString() const {
|
||||
char buffer[20];
|
||||
tm curTime;
|
||||
|
||||
#ifdef __APPLE__
|
||||
curDate = *(localtime(&this->time));
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
curTime = *(localtime(&this->time));
|
||||
#endif
|
||||
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
localtime_s(&curTime, &this->time);
|
||||
#endif
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
localtime_s(&curTime, &this->time);
|
||||
#endif
|
||||
strftime(buffer, 20, "%F", &curTime);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,6 @@ public:
|
||||
};
|
||||
|
||||
class FileWriteError : public FileIOError {
|
||||
public:
|
||||
public:
|
||||
FileWriteError(const std::string msg);
|
||||
};
|
||||
@@ -221,9 +221,10 @@ void ListDisplay::reapplyFilter() {
|
||||
this->filteredRecordsPtrList.sort(
|
||||
[&](BaseRecord *const &recordAPtr,
|
||||
BaseRecord *const &recordBPtr) -> bool {
|
||||
return (recordAPtr->getRecordType() <
|
||||
recordBPtr->getRecordType() ==
|
||||
this->sortOrder || recordAPtr->getRecordType() == recordBPtr->getRecordType());
|
||||
return (
|
||||
recordAPtr->getRecordType() < recordBPtr->getRecordType() ==
|
||||
this->sortOrder ||
|
||||
recordAPtr->getRecordType() == recordBPtr->getRecordType());
|
||||
});
|
||||
break;
|
||||
default: {
|
||||
@@ -262,13 +263,13 @@ void ListDisplay::promptForFromDate() {
|
||||
time_t originTime = this->fromDate.getTime();
|
||||
tm curDate;
|
||||
|
||||
#ifdef __APPLE__
|
||||
#ifdef __APPLE__
|
||||
curDate = *(localtime(&originTime));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
localtime_s(&curDate, &originTime);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int tempInput;
|
||||
if (!this->fromDate.isAny()) {
|
||||
@@ -284,8 +285,7 @@ void ListDisplay::promptForFromDate() {
|
||||
// std::cin.ignore();
|
||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||
[](const int &num) { return num > 0; });
|
||||
curDate.tm_year =
|
||||
(tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||
curDate.tm_year = (tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||
<< "Month: " << resetOutputColor << std::flush;
|
||||
// std::cin >> tempInput;
|
||||
@@ -333,13 +333,13 @@ void ListDisplay::promptForToDate() {
|
||||
|
||||
tm curDate;
|
||||
|
||||
#ifdef __APPLE__
|
||||
#ifdef __APPLE__
|
||||
curDate = *(localtime(&originTime));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
localtime_s(&curDate, &originTime);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int tempInput;
|
||||
if (!this->toDate.isAny()) {
|
||||
@@ -355,8 +355,7 @@ void ListDisplay::promptForToDate() {
|
||||
// std::cin.ignore();
|
||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||
[](const int &num) { return num > 0; });
|
||||
curDate.tm_year =
|
||||
(tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||
curDate.tm_year = (tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||
<< "Month: " << resetOutputColor << std::flush;
|
||||
// std::cin >> tempInput;
|
||||
|
||||
@@ -15,8 +15,8 @@ enum SortBy {
|
||||
|
||||
class ListDisplay {
|
||||
private:
|
||||
const List<BaseRecord*> &allRecordsPtrList;
|
||||
List<BaseRecord*> filteredRecordsPtrList;
|
||||
const List<BaseRecord *> &allRecordsPtrList;
|
||||
List<BaseRecord *> filteredRecordsPtrList;
|
||||
Date fromDate;
|
||||
Date toDate;
|
||||
Student searchForStu;
|
||||
@@ -32,7 +32,7 @@ private:
|
||||
const std::string searchForRecordTypeToString() const;
|
||||
|
||||
public:
|
||||
ListDisplay(const List<BaseRecord*> &_allRecordsPtrList);
|
||||
ListDisplay(const List<BaseRecord *> &_allRecordsPtrList);
|
||||
bool hasNext();
|
||||
bool hasPrev();
|
||||
void next();
|
||||
@@ -44,9 +44,11 @@ public:
|
||||
void setSortOrder(const bool newOrder);
|
||||
// Filp the sort Order to the opposite way. Does not dispaly new result.
|
||||
void flipSortOrder();
|
||||
// Make sure the filteredRecordsPtrList matches current searching criteria. Does not display new result.
|
||||
// Make sure the filteredRecordsPtrList matches current searching criteria.
|
||||
// Does not display new result.
|
||||
void reapplyFilter();
|
||||
// Ask for a record ID, and display the complete info right away. If the requested ID does not exist, simply display an error message and exit.
|
||||
// Ask for a record ID, and display the complete info right away. If the
|
||||
// requested ID does not exist, simply display an error message and exit.
|
||||
void promptForRecordID();
|
||||
void promptForFromDate();
|
||||
void promptForToDate();
|
||||
|
||||
@@ -193,7 +193,8 @@ template <class E> E List<E>::pop(int index) {
|
||||
return removed.getContent();
|
||||
}
|
||||
|
||||
template <class E> List<E> &List<E>::remove(std::function<bool(const E &)> const &isTargetFunc) {
|
||||
template <class E>
|
||||
List<E> &List<E>::remove(std::function<bool(const E &)> const &isTargetFunc) {
|
||||
this->pop(this->index(isTargetFunc));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -49,13 +49,13 @@ void BaseRecord::promptForNewDate(bool showOriginal) {
|
||||
|
||||
tm curDate;
|
||||
|
||||
#ifdef __APPLE__
|
||||
#ifdef __APPLE__
|
||||
curDate = *(localtime(&originTime));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
localtime_s(&curDate, &originTime);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
tm newDate;
|
||||
int tempInput;
|
||||
@@ -72,8 +72,7 @@ void BaseRecord::promptForNewDate(bool showOriginal) {
|
||||
// std::cin.ignore();
|
||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||
[](const int &num) { return num > 0; });
|
||||
newDate.tm_year =
|
||||
(tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||
newDate.tm_year = (tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||
<< "Month: " << resetOutputColor << std::flush;
|
||||
// std::cin >> tempInput;
|
||||
|
||||
@@ -37,7 +37,6 @@ struct SaveRecord {
|
||||
StuRecord::RecordType recordType;
|
||||
};
|
||||
|
||||
|
||||
class BaseRecord {
|
||||
protected:
|
||||
int recordID;
|
||||
|
||||
@@ -31,4 +31,3 @@ public:
|
||||
bool matches(const Student &otherStu) const;
|
||||
bool operator==(const Student &otherStu) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -353,13 +353,13 @@ bool StudentInfoManager::cmdNew() {
|
||||
|
||||
tm curDate;
|
||||
|
||||
#ifdef __APPLE__
|
||||
#ifdef __APPLE__
|
||||
curDate = *(localtime(&curTime));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
localtime_s(&curDate, &curTime);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
tm newDate;
|
||||
newDate.tm_year = curDate.tm_year;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#endif
|
||||
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
#include <windows.h>
|
||||
#include <conio.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
using namespace ConsoleColorTool;
|
||||
@@ -179,21 +179,23 @@ void disableEchoBack() {
|
||||
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD mode = 0;
|
||||
GetConsoleMode(hStdin, &mode);
|
||||
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT) & (~ENABLE_LINE_INPUT) & (~ENABLE_PROCESSED_INPUT));
|
||||
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT) & (~ENABLE_LINE_INPUT) &
|
||||
(~ENABLE_PROCESSED_INPUT));
|
||||
}
|
||||
|
||||
void enableEchoBack() {
|
||||
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD mode = 0;
|
||||
GetConsoleMode(hStdin, &mode);
|
||||
SetConsoleMode(hStdin, mode | (ENABLE_ECHO_INPUT) | (ENABLE_LINE_INPUT) | (ENABLE_PROCESSED_INPUT));
|
||||
SetConsoleMode(hStdin, mode | (ENABLE_ECHO_INPUT) | (ENABLE_LINE_INPUT) |
|
||||
(ENABLE_PROCESSED_INPUT));
|
||||
}
|
||||
|
||||
const termSize getConsoleSize() {
|
||||
CONSOLE_SCREEN_BUFFER_INFO scrInfo;
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
GetConsoleScreenBufferInfo(hStdout, &scrInfo);
|
||||
return termSize{ .width=scrInfo.dwSize.X, .height=scrInfo.dwSize.Y };
|
||||
return termSize{.width = scrInfo.dwSize.X, .height = scrInfo.dwSize.Y};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <functional>
|
||||
|
||||
// Reference: https://cplusplus.com/forum/unices/36461/
|
||||
// Reference: https://isocpp.org/wiki/faq/input-output#turn-off-tty-echo
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include "Tools.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
#if defined _WIN64 || defined _WIN32
|
||||
system("chcp 65001");
|
||||
#endif
|
||||
#endif
|
||||
enableEchoBack(); // Just in case
|
||||
StudentInfoManager *studManager;
|
||||
if (argc > 1) {
|
||||
|
||||
Reference in New Issue
Block a user