diff --git a/README.md b/README.md index 20845e2..eda244f 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ boost太大太臃肿,且功能并不完善。 观察者 适配器模式 有限状态机 - -3. 线程类。 -4. 调试工具,如打印内存为asii。 -5. 网络工具,包含了http客户端,tcp客户端。 -6. 规范化的函数返回值。 +3. 基于chrono封装的时间助手函数。 +4. 线程类。 +5. 调试工具,如打印内存为asii。 +6. 网络工具,包含了http客户端,tcp客户端。 +7. 规范化的函数返回值。 依赖库以conan包形式来管理。 diff --git a/general/inc/loger.h b/general/inc/loger.h index e5350ba..6472e55 100644 --- a/general/inc/loger.h +++ b/general/inc/loger.h @@ -2,11 +2,14 @@ #define CPP11FEATURETEST_LOGER_H #include -#include #include #include #include #include +#include +#include +#include + using namespace std; typedef enum { @@ -35,6 +38,7 @@ public: int Info(string,string file = __FILE__,int line = __LINE__); int Warning(string,string file = __FILE__,int line = __LINE__); int Error(string,string file = __FILE__,int line = __LINE__); + int DumpOBJ(void *dst,int rowNum,int num,bool ifAsii,char *out); void operator+(const string&); void operator<<(const string&); diff --git a/general/src/function/glotime.cpp b/general/src/function/glotime.cpp index 66e674e..5c71842 100644 --- a/general/src/function/glotime.cpp +++ b/general/src/function/glotime.cpp @@ -102,4 +102,8 @@ void time_add(){ tt = system_clock::to_time_t ( tomorrow ); std::cout << "tomorrow will be: " << ctime(&tt); +} + +std::string stdtime(){ + return time2strgm(get_time_us_greenwich()); } \ No newline at end of file diff --git a/general/src/function/glotime.h b/general/src/function/glotime.h index eb6a658..0283e68 100644 --- a/general/src/function/glotime.h +++ b/general/src/function/glotime.h @@ -34,7 +34,8 @@ int64_t localstr2gmtime(const std::string& s, const std::string& fmt="%Y-%m-%d % // 字符串转微秒数,不考虑时区 std::string time2strgm(int64_t time_us, const std::string& fmt="%Y-%m-%d %H:%M:%S"); std::string time2strlocal(int64_t time_us,const std::string &fmt="%Y-%m-%d %H:%M:%S"); - +// 返回当前的标准时间 +std::string stdtime(); // 微秒数转字符串,不考虑时区 int64_t str2time(const std::string& s, const std::string& fmt="%Y-%m-%d %H:%M:%S"); diff --git a/general/src/loger.cpp b/general/src/loger.cpp index f8b56e1..a978b08 100644 --- a/general/src/loger.cpp +++ b/general/src/loger.cpp @@ -351,3 +351,89 @@ Loger::Loger(string path,string prefix,bool old) { mValid = true; } } + + + + +int Loger::DumpOBJ (void *dst,int rowNum,int num,bool ifAsii){ + char out [2048] = {0}; + int row = num / rowNum; + int left = num %rowNum; + if (left != 0){ + row += 1; + } + snprintf(out,5,"LN: "); + for (int z = 1;z < rowNum + 1; z++) { + char tmp[6] = {0}; + sprintf(tmp,"%02d ",z); + strcat(out,tmp); + } + strcat(out," "); + + if (ifAsii) { + for (int z = 1;z < rowNum + 1; z++) { + char tmp[6] = {0}; + sprintf(tmp,"%02d ",z); + strcat(out,tmp); + } + } + strcat(out,"\r\n"); + for(int i = 0;i < row;i ++) { + string rowstr; + char tmp[6] = {0}; + sprintf(tmp,"%02x",i + 1); + rowstr += string(tmp) + ": "; + //last row + if (i == row -1 && left != 0){ + for (int z = 0;z < rowNum; z++) { + char tmp[6] = {0}; + if (z < left){ + sprintf(tmp,"%02x",((unsigned char)(((unsigned char *)dst)[ z + i * rowNum]))); + }else{ + sprintf(tmp," "); + } + rowstr += string(tmp) + " "; + if (z == left - 1) { + if (!ifAsii) + rowstr += "\r\n"; + } + } + rowstr += " "; + if(ifAsii) { + for (int z = 0;z < left; z++) { + char tmp[6] = {0}; + sprintf(tmp,"%c",((unsigned char)(((unsigned char *)dst)[ z + i * rowNum]))); + rowstr += string(tmp) + " "; + if (z == left - 1){ + rowstr += "\r\n"; + } + } + } + }else{ + for (int z = 0;z < rowNum; z++) { + char tmp[6] = {0}; + sprintf(tmp,"%02x",((unsigned char)(((unsigned char *)dst)[ z + i * rowNum]))); + rowstr += string(tmp) + " "; + if (!ifAsii){ + if (z == rowNum - 1){ + rowstr += "\r\n"; + } + } + } + if(ifAsii){ + rowstr += " "; + for (int z = 0;z < rowNum; z++) { + char tmp[6] = {0}; + sprintf(tmp,"%c",((unsigned char)(((unsigned char *)dst)[ z + i * rowNum]))); + rowstr += string(tmp) + " "; + if (z == rowNum - 1){ + rowstr += "\r\n"; + } + } + } + } + strcat(out,rowstr.c_str()); + } + cout << out << "\r\n"; + return 0; +} \ No newline at end of file diff --git a/test/src/chrono/test.cpp b/test/src/chrono/test.cpp index caf16cc..191970c 100644 --- a/test/src/chrono/test.cpp +++ b/test/src/chrono/test.cpp @@ -12,6 +12,8 @@ #include #include #include +#include + using namespace std; @@ -28,7 +30,7 @@ int64_t get_time(){ clock.now().time_since_epoch()).count(); } -int64_t get_time_us_greenwich() +int64_t get_time_us() { chrono::system_clock clock; return chrono::duration_cast( @@ -38,7 +40,7 @@ int64_t get_time_us_greenwich() // 返回当前时间作为 本地(北京)时间 距离 GMT时间 1970-1-1 00:00:00 的微秒数,等于get_gmtime_us加8小时 int64_t get_localtime_us() { - return get_time_us_greenwich() + HOUR * 8; + return get_time_us() + HOUR * 8; } // 格林威治时间的微秒数格式化成本地时间字符串 @@ -110,10 +112,13 @@ void time_format(){ int main() { - std::cout<<"greenwill time: "< frame){ if(ret == webrtc::DesktopCapturer::Result::SUCCESS){ std::cout << "capture frame " << frame.get()->size().width() << " " << frame.get()->size().height() << "\r\n"; -======= std::unique_ptr frame) { if (ret == webrtc::DesktopCapturer::Result::SUCCESS) @@ -163,7 +162,6 @@ class CaptureCallBack : public webrtc::DesktopCapturer::Callback write_png_file("test.png",&pic); exit(0); ->>>>>>> fc51075a61ea3d0ec07cbba77045e13b1c51b3a5 } } };