Skip to content

Commit

Permalink
Removed some redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed Jan 18, 2024
1 parent 7e73757 commit c0bf731
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 86 deletions.
58 changes: 20 additions & 38 deletions source/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Langulus::Logger

template<class... T>
concept Formattable = CT::Dense<T...>
and ((::fmt::is_formattable<T>::value) and ...);
and ((::fmt::is_formattable<Deref<T>>::value) and ...);

/// Color codes, consistent with ANSI/VT100 escapes
/// Also consistent with fmt::terminal_color
Expand Down Expand Up @@ -170,18 +170,15 @@ namespace Langulus::Logger
}

Interface& operator << (A::Interface&) noexcept;
Interface& operator << (const Exception&) noexcept;
Interface& operator << (const TextView&) noexcept;
Interface& operator << (const Command&) noexcept;
Interface& operator << (const Color&) noexcept;
Interface& operator << (const Emphasis&) noexcept;
Interface& operator << (const Style&) noexcept;
Interface& operator << (const Tabs&) noexcept;
Interface& operator << (const ::std::nullptr_t&) noexcept;
template<CT::Sparse T>
Interface& operator << (const T&) noexcept;
template<::Langulus::Logger::Formattable T>
Interface& operator << (const T&) noexcept;
Interface& operator << (const CT::Sparse auto&) noexcept;
Interface& operator << (const ::Langulus::Logger::Formattable auto&) noexcept;
ScopedTabs operator << (Tabs&&) noexcept;
};

Expand Down Expand Up @@ -243,38 +240,23 @@ namespace Langulus::Logger
///
LANGULUS_API(LOGGER) extern Interface Instance;

template<class... T>
decltype(auto) Line(T&&...) noexcept;
template<class... T>
decltype(auto) Append(T&&...) noexcept;

template<class... T>
decltype(auto) Section(T&&...) noexcept;

template<class... T>
decltype(auto) Fatal(T&&...) noexcept;
template<class... T>
decltype(auto) Error(T&&...) noexcept;
template<class... T>
decltype(auto) Warning(T&&...) noexcept;
template<class... T>
decltype(auto) Verbose(T&&...) noexcept;
template<class... T>
decltype(auto) Info(T&&...) noexcept;
template<class... T>
decltype(auto) Message(T&&...) noexcept;
template<class... T>
decltype(auto) Special(T&&...) noexcept;
template<class... T>
decltype(auto) Flow(T&&...) noexcept;
template<class... T>
decltype(auto) Input(T&&...) noexcept;
template<class... T>
decltype(auto) Network(T&&...) noexcept;
template<class... T>
decltype(auto) OS(T&&...) noexcept;
template<class... T>
decltype(auto) Prompt(T&&...) noexcept;
decltype(auto) Line(auto&&...) noexcept;
decltype(auto) Append(auto&&...) noexcept;

decltype(auto) Section(auto&&...) noexcept;

decltype(auto) Fatal(auto&&...) noexcept;
decltype(auto) Error(auto&&...) noexcept;
decltype(auto) Warning(auto&&...) noexcept;
decltype(auto) Verbose(auto&&...) noexcept;
decltype(auto) Info(auto&&...) noexcept;
decltype(auto) Message(auto&&...) noexcept;
decltype(auto) Special(auto&&...) noexcept;
decltype(auto) Flow(auto&&...) noexcept;
decltype(auto) Input(auto&&...) noexcept;
decltype(auto) Network(auto&&...) noexcept;
decltype(auto) OS(auto&&...) noexcept;
decltype(auto) Prompt(auto&&...) noexcept;

} // namespace Langulus::Logger

Expand Down
65 changes: 17 additions & 48 deletions source/Logger.inl
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,6 @@ namespace Langulus::Logger
return *this;
}

/// Write an exception
/// @param e - exception to write
/// @return a reference to the logger for chaining
LANGULUS(INLINED)
A::Interface& A::Interface::operator << (const Exception& e) noexcept {
#if LANGULUS(DEBUG)
Write(fmt::format("{}({} at {})",
e.GetName(), e.GetMessage(), e.GetLocation())
);
#else
Write(fmt::format("{}", e.GetName()));
#endif
return *this;
}

/// Push a command
/// @param c - the command to push
/// @return a reference to the logger for chaining
Expand Down Expand Up @@ -170,8 +155,7 @@ namespace Langulus::Logger
/// Dereference anything sparse, and route it through the logger again
/// @param anything - pointer to stringify
/// @return a reference to the logger for chaining
template<CT::Sparse T>
LANGULUS(INLINED)
template<CT::Sparse T> LANGULUS(INLINED)
A::Interface& A::Interface::operator << (const T& sparse) noexcept {
if constexpr (CT::BuiltinCharacter<T>) {
Write(sparse);
Expand All @@ -192,8 +176,7 @@ namespace Langulus::Logger
/// Stringify anything that has a valid fmt formatter
/// @param anything - type to stringify
/// @return a reference to the logger for chaining
template<::Langulus::Logger::Formattable T>
LANGULUS(INLINED)
template<::Langulus::Logger::Formattable T> LANGULUS(INLINED)
A::Interface& A::Interface::operator << (const T& anything) noexcept {
Write(fmt::format("{}", anything));
return *this;
Expand All @@ -219,8 +202,7 @@ namespace Langulus::Logger
/// A general new-line write function with color
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Line(T&&...arguments) noexcept {
if constexpr (sizeof...(arguments) > 0) {
Instance.NewLine();
Expand All @@ -232,8 +214,7 @@ namespace Langulus::Logger
/// A general same-line write function with color
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Append(T&&...arguments) noexcept {
if constexpr (sizeof...(arguments) > 0)
(Instance << ... << ::std::forward<T>(arguments));
Expand All @@ -245,8 +226,7 @@ namespace Langulus::Logger
/// scope's end
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a scoped tab
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Section(T&&...arguments) noexcept {
if constexpr (sizeof...(arguments) > 0) {
Instance.NewLine();
Expand All @@ -260,8 +240,7 @@ namespace Langulus::Logger
/// Write a new-line fatal error
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Fatal([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_FATALERRORS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -279,8 +258,7 @@ namespace Langulus::Logger
/// Write a new-line error
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Error([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_ERRORS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -298,8 +276,7 @@ namespace Langulus::Logger
/// Write a new-line warning
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Warning([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_WARNINGS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -317,8 +294,7 @@ namespace Langulus::Logger
/// Write a new-line with verbose information
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Verbose([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_VERBOSE
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -335,8 +311,7 @@ namespace Langulus::Logger
/// Write a new-line with information
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Info([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_INFOS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -353,8 +328,7 @@ namespace Langulus::Logger
/// Write a new-line with a personal message
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Message([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_MESSAGES
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -371,7 +345,7 @@ namespace Langulus::Logger
/// Write a new-line with special text
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
template<class...T> LANGULUS(INLINED)
decltype(auto) Special([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_SPECIALS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -388,8 +362,7 @@ namespace Langulus::Logger
/// Write a new-line with flow information
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Flow([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_FLOWS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -406,8 +379,7 @@ namespace Langulus::Logger
/// Write a new-line on user input
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Input([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_INPUTS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -424,8 +396,7 @@ namespace Langulus::Logger
/// Write a new-line with network message
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Network([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_NETWORKS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -442,8 +413,7 @@ namespace Langulus::Logger
/// Write a new-line with a message from OS
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) OS([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_OS
if constexpr (sizeof...(arguments) > 0) {
Expand All @@ -460,8 +430,7 @@ namespace Langulus::Logger
/// Write a new-line with an input prompt
/// @tparam ...T - a sequence of elements to log (deducible)
/// @return a reference to the logger for chaining
template<class... T>
LANGULUS(INLINED)
template<class...T> LANGULUS(INLINED)
decltype(auto) Prompt([[maybe_unused]] T&&...arguments) noexcept {
#ifdef LANGULUS_LOGGER_ENABLE_PROMPTS
if constexpr (sizeof...(arguments) > 0) {
Expand Down

0 comments on commit c0bf731

Please sign in to comment.