From 2b24e6bb84420b5cdea7c6f9087b00e18b603a59 Mon Sep 17 00:00:00 2001 From: Terik23 Date: Thu, 22 Mar 2018 19:09:55 +0500 Subject: [PATCH] v0.1.3 --- example/example.cpp | 3 +++ src/nameof.hpp | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index b1751b9..3bd187c 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -84,6 +84,9 @@ void TestCase1() { std::cout << NAMEOF_VAR(someVar.SomeField) << std::endl; // SomeField std::cout << NAMEOF_VAR((&someVar)->SomeField) << std::endl; // SomeField std::cout << NAMEOF_VAR(::someVar) << std::endl; // someVar + + std::cout << NAMEOF_FULL(someVar.SomeField) << std::endl; // someVar.SomeField + std::cout << NAMEOF_FULL(&SomeStruct::SomeMethod2) << std::endl; // &SomeStruct::SomeMethod2 } void TestCase2() { diff --git a/src/nameof.hpp b/src/nameof.hpp index dcadab7..6ec9381 100644 --- a/src/nameof.hpp +++ b/src/nameof.hpp @@ -1,5 +1,5 @@ // nameof() c++ https://github.com/Terik23/Nameof -// Vesion 0.1.2 +// Vesion 0.1.3 // // Licensed under the MIT License . // Copyright(c) 2016 - 2018 Terik23 @@ -28,9 +28,7 @@ namespace nameof { -#define NAMEOF_RAW_(x) #x -#define NAMEOF_RAW(x) NAMEOF_RAW_(x) - +template constexpr const char* Nameof(const char* name, const size_t length) { return length == 0 ? name : (name[length - 1] == ' ' || name[length - 1] == '.' || @@ -39,21 +37,32 @@ constexpr const char* Nameof(const char* name, const size_t length) { name[length - 1] == '+' || name[length - 1] == '~' || name[length - 1] == '-' || name[length - 1] == '!') ? &name[length] - : Nameof(name, length - 1); + : Nameof(name, length - 1); } +} + +#define NAMEOF_RAW_(x) #x +#define NAMEOF_RAW(x) NAMEOF_RAW_(x) + // Used to obtain the string name of a variable, function and etc. -template -constexpr const char* Nameof(const char* name, const size_t length) { return Nameof(name, length); } #define NAMEOF(name) nameof::Nameof(NAMEOF_RAW(name), sizeof(NAMEOF_RAW(name)) / sizeof(char) - 1) +#define NAMEOF_FULL(name) nameof::Nameof(NAMEOF_RAW(name), 0) + #define NAMEOF_VARIABLE(variable) NAMEOF(variable) -#define NAMEOF_VAR(var) NAMEOF_VARIABLE(var) +#define NAMEOF_VAR(var) NAMEOF(var) + +#define NAMEOF_VARIABLE_FULL(variable) NAMEOF_FULL(variable) +#define NAMEOF_VAR_FULL(var) NAMEOF_FULL(var) #define NAMEOF_FUNCTION(function) NAMEOF(function) -#define NAMEOF_FUN(fun) NAMEOF_FUNCTION(fun) +#define NAMEOF_FUN(fun) NAMEOF(fun) + +#define NAMEOF_FUNCTION_FULL(function) NAMEOF_FULL(function) +#define NAMEOF_FUN_FULL(fun) NAMEOF_FULL(fun) // Used to obtain the string name of a type. #define NAMEOF_TYPE(type) nameof::Nameof(NAMEOF_RAW(type), sizeof(NAMEOF_RAW(type)) / sizeof(char) - 1) -} \ No newline at end of file +#define NAMEOF_TYPE_FULL(type) nameof::Nameof(NAMEOF_RAW(type), 0)