From 644dd609fd6016d6c42774a27a25f007d65891eb Mon Sep 17 00:00:00 2001 From: lovelyyoung <1002639516@qq.com> Date: Sat, 18 Apr 2020 15:51:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdparty/nick/StopWatch.h | 34 ++++++++++++++++++++ 3rdparty/nick/filetools.h | 65 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 3rdparty/nick/StopWatch.h create mode 100644 3rdparty/nick/filetools.h diff --git a/3rdparty/nick/StopWatch.h b/3rdparty/nick/StopWatch.h new file mode 100644 index 00000000..afa4ee97 --- /dev/null +++ b/3rdparty/nick/StopWatch.h @@ -0,0 +1,34 @@ +#pragma once +#include + +class StopWatch +{ +public: + StopWatch() { + _start = std::chrono::steady_clock::now(); + } + + void reset() { + _start = std::chrono::steady_clock::now(); + } + + double elapsed_s() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_ms() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_us() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_ns() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + +private: + std::chrono::steady_clock::time_point _start; +}; + diff --git a/3rdparty/nick/filetools.h b/3rdparty/nick/filetools.h new file mode 100644 index 00000000..cff77ee2 --- /dev/null +++ b/3rdparty/nick/filetools.h @@ -0,0 +1,65 @@ +#pragma once +#include +#ifdef WIN32 +#include +#endif +#include +#include + +class FileTools +{ +public: + + + static std::vector getFiles(std::string path) + { + std::vector files; + getFiles(path, files); + return files; + } + + static void write_log(std::string filename, std::string log) + { + std::string savepath; + std::string str = "D:"; + savepath = str+"\\"+filename; + std::ofstream ofs(savepath, std::ios::app); + + time_t timp; + struct tm* p; + time(&timp); + p=localtime(&timp); + ofs << p->tm_year+1900 << "/" << p->tm_mon+1 << "/" << p->tm_mday << " " << p->tm_hour << ":" << p->tm_min << ":" << p->tm_sec << " "<& files) + { +#ifdef WIN32 + //文件句柄 + long hFile = 0; + //文件信息 + struct _finddata_t fileinfo; + std::string p; + if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo))!=-1) + { + do + { + //如果是目录,迭代之 + //如果不是,加入列表 + if ((fileinfo.attrib & _A_SUBDIR)) + { + if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) + getFiles(p.assign(path).append("\\").append(fileinfo.name), files); + } + else + { + files.push_back(p.assign(path).append("\\").append(fileinfo.name)); + } + } while (_findnext(hFile, &fileinfo) == 0); + _findclose(hFile); + } +#endif + } + +};