From a60380c898a4f15812ac8cf1090066945b7c0813 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Thu, 19 Sep 2024 17:20:27 -0400 Subject: [PATCH] log boxing --- CMakeLists.txt | 2 +- include/blt/format/boxing.h | 111 ++++++++++++++++++++++++++++++++++++ include/blt/math/log_util.h | 4 +- include/blt/math/matrix.h | 2 +- 4 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 include/blt/format/boxing.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e8ad294..2553806 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.20.9) +set(BLT_VERSION 0.20.10) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/format/boxing.h b/include/blt/format/boxing.h new file mode 100644 index 0000000..aaaa1bd --- /dev/null +++ b/include/blt/format/boxing.h @@ -0,0 +1,111 @@ +#pragma once +/* + * Copyright (C) 2024 Brett Terpstra + * + * 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 . + */ + +#ifndef BLT_BOXING_H +#define BLT_BOXING_H + +#include +#include +#include + +namespace blt +{ + namespace detail + { + class log_box_base_t + { + public: + explicit log_box_base_t(std::string_view title, blt::size_t padding = 0): padding(padding), title(title) + {} + + template + void make_padding(Logger& logger) + { + for (blt::size_t i = 0; i < padding; i++) + logger << '-'; + } + + template + void make_full_width_line(Logger& logger) + { + for (blt::size_t i = 0; i < padding * 2 + 2 + title.size(); i++) + logger << '-'; + } + + template + void make_full_title(Logger& logger) + { + make_padding(logger); + if (padding > 0) + logger << "{"; + logger << title; + if (padding > 0) + logger << "}"; + make_padding(logger); + } + + protected: + blt::size_t padding; + std::string title; + }; + } + + template + class log_box_t : detail::log_box_base_t + { + public: + log_box_t(Logger& logger, std::string_view title, blt::size_t padding = 0): detail::log_box_base_t(title, padding), logger(logger) + { + make_full_title(logger); + logger << '\n'; + } + + ~log_box_t() + { + make_full_width_line(logger); + logger << '\n'; + } + private: + Logger& logger; + }; + + template<> + class log_box_t : detail::log_box_base_t + { + public: + log_box_t(blt::logging::logger logger, std::string_view title, blt::size_t padding = 0): detail::log_box_base_t(title, padding), logger(logger) + { + make_full_title(logger); + logger << '\n'; + } + + ~log_box_t() + { + make_full_width_line(logger); + logger << '\n'; + } + private: + blt::logging::logger logger; + }; + + template + log_box_t(Logger&& logger, std::string_view, blt::size_t) -> log_box_t; + +} + +#endif //BLT_BOXING_H diff --git a/include/blt/math/log_util.h b/include/blt/math/log_util.h index 2214f26..76be9cd 100644 --- a/include/blt/math/log_util.h +++ b/include/blt/math/log_util.h @@ -56,8 +56,8 @@ namespace blt return out; } - template - inline Writer& operator<<(Writer& out, const generalized_matrix& mat) + template + inline std::basic_ostream& operator<<(std::basic_ostream& out, const generalized_matrix& mat) { out << "Mat" << rows << 'x' << columns << "(\n"; for (blt::u32 c = 0; c < columns; c++) diff --git a/include/blt/math/matrix.h b/include/blt/math/matrix.h index 070e5cd..0334e57 100644 --- a/include/blt/math/matrix.h +++ b/include/blt/math/matrix.h @@ -122,7 +122,7 @@ namespace blt return *this; } - generalized_matrix transpose() + generalized_matrix transpose() const { generalized_matrix mat;