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. 线程类。
4. 调试工具如打印内存为asii。
5. 网络工具包含了http客户端tcp客户端。
6. 规范化的函数返回值。
3. 基于chrono封装的时间助手函数。
4. 线程类。
5. 调试工具如打印内存为asii。
6. 网络工具包含了http客户端tcp客户端。
7. 规范化的函数返回值。
依赖库以conan包形式来管理。

View File

@ -2,11 +2,14 @@
#define CPP11FEATURETEST_LOGER_H
#include <stdio.h>
#include <string>
#include <time.h>
#include <fstream>
#include <iostream>
#include <mutex>
#include <stdio.h>
#include <string.h>
#include <string>
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&);

View File

@ -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());
}

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 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");

View File

@ -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;
}

View File

@ -12,6 +12,8 @@
#include <sstream>
#include <iosfwd>
#include <iomanip>
#include <Windows.h>
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<chrono::microseconds>(
@ -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: "<<get_time_us_greenwich()<<std::endl;
std::cout<<"time format greenwich is "<<time2strgm(get_time_us_greenwich())<<std::endl;
std::cout<<"time format is "<<time2strlocal(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())<<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;
}

View File

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

View File

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

View File

@ -159,4 +159,10 @@ void main()
printf("\n== 最 大 堆: ");
maxheap_print();
printf("\n");
}
}

View File

@ -39,7 +39,6 @@ void async_cb2(uv_async_t* handle)
}
void idle_cb(uv_async_t *handle) {
printf("Idle callback\n");
uv_stop(uv_default_loop()); // 一定要在回调函数内去调用,主函数内调用不生效。
@ -78,3 +77,5 @@ int main()
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");
return -1;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
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
{
virtual void OnCaptureResult(webrtc::DesktopCapturer::Result ret,
<<<<<<< HEAD
std::unique_ptr<webrtc::DesktopFrame> frame){
if(ret == webrtc::DesktopCapturer::Result::SUCCESS){
std::cout
<< "capture frame "
<< frame.get()->size().width() << " "
<< frame.get()->size().height() << "\r\n";
=======
std::unique_ptr<webrtc::DesktopFrame> 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
}
}
};