no message

master
zcy 2023-06-05 19:43:30 +08:00
parent 71185ab318
commit a72b03154a
11 changed files with 131 additions and 21 deletions

View File

@ -10,11 +10,11 @@ boost太大太臃肿且功能并不完善。
观察者 观察者
适配器模式 适配器模式
有限状态机 有限状态机
3. 基于chrono封装的时间助手函数。
3. 线程类。 4. 线程类。
4. 调试工具如打印内存为asii。 5. 调试工具如打印内存为asii。
5. 网络工具包含了http客户端tcp客户端。 6. 网络工具包含了http客户端tcp客户端。
6. 规范化的函数返回值。 7. 规范化的函数返回值。
依赖库以conan包形式来管理。 依赖库以conan包形式来管理。

View File

@ -2,11 +2,14 @@
#define CPP11FEATURETEST_LOGER_H #define CPP11FEATURETEST_LOGER_H
#include <stdio.h> #include <stdio.h>
#include <string>
#include <time.h> #include <time.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std; using namespace std;
typedef enum { typedef enum {
@ -35,6 +38,7 @@ public:
int Info(string,string file = __FILE__,int line = __LINE__); int Info(string,string file = __FILE__,int line = __LINE__);
int Warning(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 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&);
void operator<<(const string&); void operator<<(const string&);

View File

@ -103,3 +103,7 @@ void time_add(){
tt = system_clock::to_time_t ( tomorrow ); tt = system_clock::to_time_t ( tomorrow );
std::cout << "tomorrow will be: " << ctime(&tt); std::cout << "tomorrow will be: " << ctime(&tt);
} }
std::string stdtime(){
return time2strgm(get_time_us_greenwich());
}

View File

@ -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 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 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"); int64_t str2time(const std::string& s, const std::string& fmt="%Y-%m-%d %H:%M:%S");

View File

@ -351,3 +351,89 @@ Loger::Loger(string path,string prefix,bool old) {
mValid = true; 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;
}

View File

@ -12,6 +12,8 @@
#include <sstream> #include <sstream>
#include <iosfwd> #include <iosfwd>
#include <iomanip> #include <iomanip>
#include <Windows.h>
using namespace std; using namespace std;
@ -28,7 +30,7 @@ int64_t get_time(){
clock.now().time_since_epoch()).count(); clock.now().time_since_epoch()).count();
} }
int64_t get_time_us_greenwich() int64_t get_time_us()
{ {
chrono::system_clock clock; chrono::system_clock clock;
return chrono::duration_cast<chrono::microseconds>( return chrono::duration_cast<chrono::microseconds>(
@ -38,7 +40,7 @@ int64_t get_time_us_greenwich()
// 返回当前时间作为 本地(北京)时间 距离 GMT时间 1970-1-1 00:00:00 的微秒数等于get_gmtime_us加8小时 // 返回当前时间作为 本地(北京)时间 距离 GMT时间 1970-1-1 00:00:00 的微秒数等于get_gmtime_us加8小时
int64_t get_localtime_us() 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() int main()
{ {
std::cout<<"greenwill time: "<<get_time_us_greenwich()<<std::endl; std::cout<<"greenwill time: "<<get_time_us()<<std::endl;
std::cout<<"time format greenwich is "<<time2strgm(get_time_us_greenwich())<<std::endl; std::cout<<"time format greenwich is "<<time2strgm(get_time_us())<<std::endl;
std::cout<<"time format is "<<time2strlocal(get_time_us_greenwich())<<std::endl; std::cout<<"time format is "<<time2strlocal(get_time_us())<<std::endl;
for(int i = 0;i < 10;i++){
std::cout<<"time format is "<<time2strlocal(get_time_us())<<std::endl;
Sleep(1000);
}
return 0; return 0;
} }

View File

@ -75,3 +75,5 @@ int main(){
loger1.Debug("hello11212",FILE_POSITION); loger1.Debug("hello11212",FILE_POSITION);
} }

View File

@ -15,7 +15,7 @@
using namespace std; using namespace std;
void TestShuffle(){ void TestShuffle() {
int in[1024]; int in[1024];
for(int j = 0;j < 1024;j++){ for(int j = 0;j < 1024;j++){
in[j] = j; in[j] = j;
@ -83,7 +83,7 @@ void TestRingBufferTakeBack(){
fflush(stdout); fflush(stdout);
} }
void TestRingBufferTakeFront(){ void TestRingBufferTakeFront() {
int in[1024]; int in[1024];
int out[1024]; int out[1024];
@ -118,3 +118,6 @@ int main() {
TestShuffle(); TestShuffle();
// TestRingBufferTakeFront(); // TestRingBufferTakeFront();
} }

View File

@ -160,3 +160,9 @@ void main()
maxheap_print(); maxheap_print();
printf("\n"); printf("\n");
} }

View File

@ -39,7 +39,6 @@ void async_cb2(uv_async_t* handle)
} }
void idle_cb(uv_async_t *handle) { void idle_cb(uv_async_t *handle) {
printf("Idle callback\n"); printf("Idle callback\n");
uv_stop(uv_default_loop()); // 一定要在回调函数内去调用,主函数内调用不生效。 uv_stop(uv_default_loop()); // 一定要在回调函数内去调用,主函数内调用不生效。
@ -78,3 +77,5 @@ int main()
return 0; return 0;
} }

View File

@ -74,6 +74,7 @@ int write_png_file(char *file_name, pic_data *graph)
printf("[write_png_file] png_create_info_struct failed"); printf("[write_png_file] png_create_info_struct failed");
return -1; return -1;
} }
if (setjmp(png_jmpbuf(png_ptr))) if (setjmp(png_jmpbuf(png_ptr)))
{ {
printf("[write_png_file] Error during init_io"); printf("[write_png_file] Error during init_io");
@ -139,14 +140,12 @@ int write_png_file(char *file_name, pic_data *graph)
class CaptureCallBack : public webrtc::DesktopCapturer::Callback class CaptureCallBack : public webrtc::DesktopCapturer::Callback
{ {
virtual void OnCaptureResult(webrtc::DesktopCapturer::Result ret, virtual void OnCaptureResult(webrtc::DesktopCapturer::Result ret,
<<<<<<< HEAD
std::unique_ptr<webrtc::DesktopFrame> frame){ std::unique_ptr<webrtc::DesktopFrame> frame){
if(ret == webrtc::DesktopCapturer::Result::SUCCESS){ if(ret == webrtc::DesktopCapturer::Result::SUCCESS){
std::cout std::cout
<< "capture frame " << "capture frame "
<< frame.get()->size().width() << " " << frame.get()->size().width() << " "
<< frame.get()->size().height() << "\r\n"; << frame.get()->size().height() << "\r\n";
=======
std::unique_ptr<webrtc::DesktopFrame> frame) std::unique_ptr<webrtc::DesktopFrame> frame)
{ {
if (ret == webrtc::DesktopCapturer::Result::SUCCESS) if (ret == webrtc::DesktopCapturer::Result::SUCCESS)
@ -163,7 +162,6 @@ class CaptureCallBack : public webrtc::DesktopCapturer::Callback
write_png_file("test.png",&pic); write_png_file("test.png",&pic);
exit(0); exit(0);
>>>>>>> fc51075a61ea3d0ec07cbba77045e13b1c51b3a5
} }
} }
}; };