io_utils.h
#pragma once
#include<stdio.h>
#include<stdarg.h>
void PrintBinary(unsigned int value);
//#define PRINT_METADATA
#ifdef PRINT_METADATA
#define PRINTLNF(format,...) printf("("__FILE__":%d) %s: "format"\n",__LINE__,__FUNCTION__,##__VA_ARGS__)
#else
#define PRINTLNF(format,...)printf(format"\n",##__VA_ARGS__)
#endif
#define PRINT_CHAR(char_value) PRINTLNF(#char_value": %c",char_value)
#define PRINT_WCHAR(char_value)PRINTLNF(#char_value": %lc",char_value)
#define PRINT_INT(int_value)PRINTLNF(#int_value": %d",int_value)
#define PRINT_LONG(long_value)PRINTLNF(#long_value"%ld",long_value)
#define PRINT_LLONG(long_value)PRINTLNF(#long_value"%lld",long_value)
#define PRINT_BINARY(int_value)PrintBinary((unsigned int) int_value);
#define PRINT_HEX(int_value)PRINTLNF(#int_value": %#x",int_value)
#define PRINT_BOOL(bool_value)PRINTLNF(#bool_value": %s",bool_value?"true":"false")
#define PRINT_DOUBLE(double_value)PRINTLNF(#double_value": %g",double_value)
#define PRINT_STRING(string_value)PIRNTLNF(#string_value": %s",string_value)
#define PRINT_ARRAY(format,array,length)\
{\
for(int array_index = 0;array_index<length;++array_index)\
{\
printf(format,array[array_index]);\
}\
printf("\n");\
}
#define PRINT_INT_ARRAY_LN(array,length)\
{\
for(int i = 0;i<length;++i)\
{\
PRINTLNF(#array[i]"[%d]: %d",i,array[i]);\
}\
}
#define PRINT_INT_ARRAY(array,length)PRINT_ARRAY("%d",array,length)
#define PRINT_CHAR_ARRAY(array,length)PRINT_ARRAY("%c",array,length)
#define PRINT_DOUBLE_ARRAY(array,length)PRINT_ARRAY("%g",array,length)
time_utils.h
#pragma once
#if defined(_WIN32)
#include<sys/timeb.h>
#if defined(__UNIX__)||defined(__APPLE__)
#include<time.h>
#endif
typedef long long long_time_t;
long_time_t TimeInMillisecond(void) {
#if defined(_WIN32)
struct timeb time_buffer;
ftime(&time_buffer);
return time_buffer.time*1000LL+time_buffer.millitm;
#elif defined(__UNIX__)||defined(__APPLE__)
struct timeval time_value;
gettimeofday(&time_buffer,NULL);
return time_buffer.tv_sec*1000LL+time_buffer.tv_usec/1000;
#elif defined(__STDC__)&&__STDC__VERSION__==201112L
struct timespec timespec_value;
timespec_get(×pec_value,TIME_UTC);
return timespec_value.tv_sec*1000LL+timespec_value.tv_nsec/1000;
#else
time_t current_time = time(NULL);
return current_time*1000LL;
#endif
}
#endif
```