提交 6229c1f8 authored 作者: blu's avatar blu

big refacting of communitation architect

上级 e302ec6b
......@@ -6,7 +6,92 @@
"optional": "cpp",
"string": "cpp",
"set": "cpp",
"thread": "cpp"
"thread": "cpp",
"filesystem": "cpp",
"__config": "cpp",
"iosfwd": "cpp",
"__bit_reference": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__functional_base": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"coroutine": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"ostream": "cpp",
"queue": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string_view": "cpp",
"strstream": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"valarray": "cpp",
"vector": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"memory_resource": "cpp"
},
"C_Cpp.errorSquiggles": "Disabled"
}
\ No newline at end of file
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include "inc/fs.h"
#include "inc/spdlog/spdlog.h"
using namespace std;
int test_last_write_time(){
fs::path p = fs::current_path() / "example.bin";
std::ofstream(p.c_str()).put('a'); // create file
auto ftime = fs::last_write_time(p);
// assuming system_clock for this demo
// note: not true on MSVC or GCC 9; C++20 will allow portable output
std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n';
fs::last_write_time(p, ftime + 1h); // move file write time 1 hour to the future
ftime = fs::last_write_time(p); // read back from the filesystem
cftime = decltype(ftime)::clock::to_time_t(ftime);
std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n';
fs::remove(p);
return 0;
}
void ftime2ctime(fs::file_time_type ftime){
std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
std::cout << "\t\twt: " << std::asctime(std::localtime(&cftime)) << std::endl;
}
int LoadVideoFiles(string path, map<long, string> &ts2fileName, list<long> &tsRing) {
int ret = 0;
try{
for (const auto & entry : fs::directory_iterator(path))
{
if(entry.file_size() == 0 || !entry.is_regular_file()) {
spdlog::warn("LoasdVideoFiles skipped {} (empty or directory)", entry.path().c_str());
}
auto ftime = fs::last_write_time(entry.path());
auto ts = decltype(ftime)::clock::to_time_t(ftime);
spdlog::debug("ts: {}, file: {}", ts, entry.path().c_str());
if(ts2fileName.count(ts) != 0) {
spdlog::warn("LoasdVideoFiles multiple files with same timestamp: {}, {}(skipped), ", ts2fileName[ts], entry.path().c_str());
continue;
}
tsRing.insert(std::lower_bound(tsRing.begin(), tsRing.end(), ts), ts);
ts2fileName[ts] = entry.path();
}
// for(auto &i: tsRing) {
// spdlog::debug("ts: {}, file: {}", i, ts2fileName[i]);
// }
}catch(exception &e) {
spdlog::error("LoasdVideoFiles exception : {}", e.what());
ret = -1;
}
return ret;
}
int main(int argc, const char *argv[]) {
std::string path = argv[1];
list<long> tsRing;
map<long, string> ts2fileName;
LoadVideoFiles(path, ts2fileName, tsRing);
return 0;
}
\ No newline at end of file
......@@ -13,26 +13,4 @@ update: 2019/08/23
#include "utils.hpp"
#include "av_common.hpp"
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
#if __has_include(<filesystem>)
#define GHC_USE_STD_FS
#include <filesystem>
namespace fs {
using namespace std::filesystem;
using ifstream = std::ifstream;
using ofstream = std::ofstream;
using fstream = std::fstream;
}
#endif
#endif
#ifndef GHC_USE_STD_FS
#include "ghc/fs_fwd.hpp"
namespace fs {
using namespace ghc::filesystem;
using ifstream = ghc::filesystem::ifstream;
using ofstream = ghc::filesystem::ofstream;
using fstream = ghc::filesystem::fstream;
}
#endif
#endif
#ifndef __EV_FS_H__
#define __EV_FS_H__
// #if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
// #if __has_include(<filesystem>)
// #define GHC_USE_STD_FS
// #include <filesystem>
// namespace fs = std::filesystem;
// #endif
// #endif
// #ifndef GHC_USE_STD_FS
#include <ghc/filesystem.hpp>
namespace fs = ghc::filesystem;
// #endif
#endif
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论