Added conditional compilation and Const namespace with OS name
This commit is contained in:
93
base.cpp
93
base.cpp
@@ -62,7 +62,7 @@ typedef double F64;
|
||||
#define kib(x) ((x)*1024llu)
|
||||
#define mib(x) (kib(x)*1024llu)
|
||||
#define gib(x) (mib(x)*1024llu)
|
||||
#define JOIN1(X,Y) X##Y
|
||||
#define JOIN1(X,Y) X##Y
|
||||
#define JOIN(X,Y) JOIN1(X,Y)
|
||||
#define string_expand(x) (int)x.len, x.str
|
||||
|
||||
@@ -106,6 +106,19 @@ typedef double F64;
|
||||
# define OS_MAC 0
|
||||
#endif
|
||||
|
||||
#if OS_WINDOWS
|
||||
#define OS_NAME "Win32"_s
|
||||
#define OS_NAME_LOWER "win32"_s
|
||||
#elif OS_LINUX
|
||||
#define OS_NAME "Linux"_s
|
||||
#define OS_NAME_LOWER "linux"_s
|
||||
#elif OS_MAC
|
||||
#define OS_NAME "Mac"_s
|
||||
#define OS_NAME_LOWER "mac"_s
|
||||
#else
|
||||
#error Couldnt figure out the OS with C macros!
|
||||
#endif
|
||||
|
||||
struct String{
|
||||
U8 *str;
|
||||
S64 len;
|
||||
@@ -794,44 +807,6 @@ thread_ctx_init(){
|
||||
os_process_heap.kind = Allocator_OSHeap;
|
||||
}
|
||||
|
||||
#include "base_string.cpp"
|
||||
//-----------------------------------------------------------------------------
|
||||
// Logging
|
||||
//-----------------------------------------------------------------------------
|
||||
#define log_info(...) handle_log_message(Log_Kind_Normal, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
#define log_trace(...) handle_log_message(Log_Kind_Trace, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
#define log_error(...) handle_log_message(Log_Kind_Error, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
function void
|
||||
handle_log_message(Log_Kind kind, int line, const char *file, const char *str, ...){
|
||||
if(kind == Log_Kind_Trace) return;
|
||||
|
||||
Scratch scratch;
|
||||
STRING_FMT(scratch, str, message);
|
||||
if(thread_ctx.log_proc) thread_ctx.log_proc(kind, message, (char *)file, line);
|
||||
else{
|
||||
printf("%s", message.str);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Defer
|
||||
// http://www.gingerbill.org/article/2015/08/19/defer-in-cpp/
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename F>
|
||||
struct Defer_Scope {
|
||||
F f;
|
||||
Defer_Scope(F f) : f(f) {}
|
||||
~Defer_Scope() { f(); }
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
Defer_Scope<F> defer_func(F f) {
|
||||
return Defer_Scope<F>(f);
|
||||
}
|
||||
#define DEFER_1(x, y) x##y
|
||||
#define DEFER_2(x, y) DEFER_1(x, y)
|
||||
#define DEFER_3(x) DEFER_2(x, __COUNTER__)
|
||||
#define defer(code) auto DEFER_3(_defer_) = defer_func([&](){code;})
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Array
|
||||
@@ -987,6 +962,46 @@ test_array(){
|
||||
assert(thread_ctx.scratch->memory.data != 0);
|
||||
}
|
||||
|
||||
|
||||
#include "base_string.cpp"
|
||||
//-----------------------------------------------------------------------------
|
||||
// Logging
|
||||
//-----------------------------------------------------------------------------
|
||||
#define log_info(...) handle_log_message(Log_Kind_Normal, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
#define log_trace(...) handle_log_message(Log_Kind_Trace, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
#define log_error(...) handle_log_message(Log_Kind_Error, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
function void
|
||||
handle_log_message(Log_Kind kind, int line, const char *file, const char *str, ...){
|
||||
if(kind == Log_Kind_Trace) return;
|
||||
|
||||
Scratch scratch;
|
||||
STRING_FMT(scratch, str, message);
|
||||
if(thread_ctx.log_proc) thread_ctx.log_proc(kind, message, (char *)file, line);
|
||||
else{
|
||||
printf("%s", message.str);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Defer
|
||||
// http://www.gingerbill.org/article/2015/08/19/defer-in-cpp/
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename F>
|
||||
struct Defer_Scope {
|
||||
F f;
|
||||
Defer_Scope(F f) : f(f) {}
|
||||
~Defer_Scope() { f(); }
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
Defer_Scope<F> defer_func(F f) {
|
||||
return Defer_Scope<F>(f);
|
||||
}
|
||||
#define DEFER_1(x, y) x##y
|
||||
#define DEFER_2(x, y) DEFER_1(x, y)
|
||||
#define DEFER_3(x) DEFER_2(x, __COUNTER__)
|
||||
#define defer(code) auto DEFER_3(_defer_) = defer_func([&](){code;})
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Map
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user