Created
September 18, 2020 14:34
-
-
Save shawnfeng0/f7fb181e1efe887c3a68890060652037 to your computer and use it in GitHub Desktop.
C++ version of LOGGER_TOKEN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ulog/ulog.h> | |
namespace ulog { | |
namespace token { | |
// void * | |
inline void print(const char *name, const void *value) { | |
logger_raw(false, "%s => %p", name ? name : "unnamed", value); | |
} | |
// const char * | |
inline void print(const char *name, const char *value) { | |
logger_raw(false, "%s => %s", name ? name : "unnamed", value ? value : ""); | |
} | |
inline void print(const char *name, const unsigned char *value) { | |
print(name, reinterpret_cast<const char *>(value)); | |
} | |
// double/float | |
inline void print(const char *name, double value) { | |
logger_raw(false, "%s => %f", name ? name : "unnamed", value); | |
} | |
inline void print(const char *name, float value) { | |
print(name, static_cast<double>(value)); | |
} | |
// signed integer | |
inline void print(const char *name, long long value) { | |
logger_raw(false, "%s => %" PRId64, name ? name : "unnamed", (int64_t)value); | |
} | |
inline void print(const char *name, long value) { | |
print(name, static_cast<long long>(value)); | |
} | |
inline void print(const char *name, int value) { | |
print(name, static_cast<long long>(value)); | |
} | |
inline void print(const char *name, short value) { | |
print(name, static_cast<long long>(value)); | |
} | |
inline void print(const char *name, char value) { | |
print(name, static_cast<long long>(value)); | |
} | |
// unsigned integer | |
inline void print(const char *name, unsigned long long value) { | |
logger_raw(false, "%s => %" PRIu64, name ? name : "unnamed", (uint64_t)value); | |
} | |
inline void print(const char *name, unsigned long value) { | |
print(name, static_cast<unsigned long long>(value)); | |
} | |
inline void print(const char *name, unsigned int value) { | |
print(name, static_cast<unsigned long long>(value)); | |
} | |
inline void print(const char *name, unsigned short value) { | |
print(name, static_cast<unsigned long long>(value)); | |
} | |
inline void print(const char *name, unsigned char value) { | |
print(name, static_cast<unsigned long long>(value)); | |
} | |
inline void print(const char *name, bool value) { | |
print(name, static_cast<unsigned long long>(value)); | |
} | |
} // namespace token | |
} // namespace ulog | |
#define L_TOKEN(x) ulog::token::print(#x, (x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment