Skip to content

Commit

Permalink
Compile time __FILENAME__ extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanetzek committed Nov 21, 2018
1 parent 23dc73b commit 8d9b33e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/include/tangram/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@
* LOGS: Screen log, no LOG_LEVEL
*/

#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
//#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
// From: https://blog.galowicz.de/2016/02/20/short_file_macro/
static constexpr const char * past_last_slash(const char * const str, const char * const last_slash) {
return *str == '\0' ? last_slash :
*str == '/' ? past_last_slash(str + 1, str + 1) :
past_last_slash(str + 1, last_slash);
}

static constexpr const char * past_last_slash(const char * const str) {
return past_last_slash(str, str);
}

#define __FILENAME__ ({constexpr const char * const sf__ {past_last_slash(__FILE__)}; sf__;})

#define TANGRAM_MAX_BUFFER_LOG_SIZE 99999

#if LOG_LEVEL >= 3
Expand Down

0 comments on commit 8d9b33e

Please sign in to comment.