diff --git a/CMakeLists.txt b/CMakeLists.txt index 70c5a80..227216f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ option(ENABLE_PROFILING "Enable asan" OFF) option(BUILD_TESTS "Enable testing" OFF) mark_as_advanced(ENABLE_PROFILING) -set(SOURCE_LIST "src/filerd.cpp" "src/string.cpp" "src/binary.cpp" "src/static_string.cpp" "src/threadpool.cpp") +set(SOURCE_LIST "src/filerd.cpp" "src/string.cpp" "src/binary.cpp" "src/static_string.cpp" "src/threadpool.cpp" "src/demangle.cpp") add_library(ensure OBJECT "src/ensure.cpp") target_compile_options(ensure PRIVATE -Wall -Wextra -pedantic -std=c++20) if(ENABLE_SHARED) diff --git a/include/rexy/buffer.hpp b/include/rexy/buffer.hpp index 86b8fb0..63a02f1 100644 --- a/include/rexy/buffer.hpp +++ b/include/rexy/buffer.hpp @@ -3,16 +3,16 @@ Copyright (C) 2021 rexy712 This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by + it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. + GNU General Public License for more details. - You should have received a copy of the GNU Affero General Public License + You should have received a copy of the GNU General Public License along with this program. If not, see . */ diff --git a/include/rexy/buffer.tpp b/include/rexy/buffer.tpp index c04d8a6..4c15e32 100644 --- a/include/rexy/buffer.tpp +++ b/include/rexy/buffer.tpp @@ -3,16 +3,16 @@ Copyright (C) 2021 rexy712 This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by + it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. + GNU General Public License for more details. - You should have received a copy of the GNU Affero General Public License + You should have received a copy of the GNU General Public License along with this program. If not, see . */ diff --git a/include/rexy/debug_print.hpp b/include/rexy/debug_print.hpp index 55f5c77..bdd68be 100644 --- a/include/rexy/debug_print.hpp +++ b/include/rexy/debug_print.hpp @@ -65,6 +65,21 @@ template print(Args&&...) -> print; #ifdef REXY_ENABLE_COLOR_DEBUG + template + struct print_succ{ + explicit print_succ(Args&&... args, const rexy::source_location& loc = rexy::source_location::current()){ + std::fprintf(stderr, "%s", detail::color_green); + std::fprintf(stderr, "%s:%s:%d: ", loc.file_name(), loc.function_name(), loc.line()); + std::fprintf(stderr, std::forward(args)...); + std::fprintf(stderr, "%s", detail::color_clear); + } + print_succ(const print_succ&) = delete; + print_succ(print_succ&&) = delete; + print_succ& operator=(const print_succ&) = delete; + print_succ& operator=(print_succ&&) = delete; + }; + template + print_succ(Args&&...) -> print_succ; template struct print_info{ explicit print_info(Args&&... args, const rexy::source_location& loc = rexy::source_location::current()){ @@ -111,6 +126,8 @@ template print_error(Args&&...) -> print_error; #else + template + using print_succ = print; template using print_info = print; template @@ -124,6 +141,8 @@ template using print = rexy::debug::print; template + using print_succ = rexy::debug::print_succ; + template using print_info = rexy::debug::print_info; template using print_warn = rexy::debug::print_warn; @@ -133,22 +152,25 @@ #else namespace verbose{ static constexpr inline void print(...){} + static constexpr inline void print_succ(...){} + static constexpr inline void print_info(...){} static constexpr inline void print_warn(...){} static constexpr inline void print_error(...){} - static constexpr inline void print_info(...){} } #endif //REXY_ENABLE_DEBUG_VERBOSE_OUTPUT } #else static constexpr inline void print(...){} + static constexpr inline void print_succ(...){} + static constexpr inline void print_info(...){} static constexpr inline void print_warn(...){} static constexpr inline void print_error(...){} - static constexpr inline void print_info(...){} namespace verbose{ static constexpr inline void print(...){} + static constexpr inline void print_succ(...){} + static constexpr inline void print_info(...){} static constexpr inline void print_warn(...){} static constexpr inline void print_error(...){} - static constexpr inline void print_info(...){} } #endif //REXY_ENABLE_DEBUG_OUTPUT diff --git a/src/demangle.cpp b/src/demangle.cpp new file mode 100644 index 0000000..88a6e4d --- /dev/null +++ b/src/demangle.cpp @@ -0,0 +1,48 @@ +/** + This file is a part of rexy's general purpose library + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "rexy/demangle.hpp" + +#if defined(__GNUC__) && !defined(_MSC_VER) + + #include //free + #include + #include //unique_ptr + #include //__cxa_demangle + + namespace util{ + std::string demangle(const char* name){ + int status = 0; + std::unique_ptr res{ + abi::__cxa_demangle(name, nullptr, nullptr, &status), + std::free + }; + return (status == 0) ? res.get() : name; + } + } + +#else + + #include + namespace util{ + std::string demangle(const char* name){ + return name; + } + } + +#endif