nice error messages
parent
4e6863aafa
commit
637b4fa0e6
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.20)
|
||||
include(cmake/color.cmake)
|
||||
set(BLT_VERSION 5.1.7)
|
||||
set(BLT_VERSION 5.1.8)
|
||||
|
||||
set(BLT_TARGET BLT)
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@ namespace blt::logging
|
|||
EXPONENT, // 'e'
|
||||
FIXED_POINT, // 'f'
|
||||
GENERAL, // 'g'
|
||||
TYPE // 't'
|
||||
TYPE, // 't'
|
||||
UNSPECIFIED // default
|
||||
};
|
||||
|
||||
struct fmt_spec_t
|
||||
|
@ -64,7 +65,7 @@ namespace blt::logging
|
|||
i64 arg_id = -1;
|
||||
i64 width = -1;
|
||||
i64 precision = -1;
|
||||
fmt_type_t type = fmt_type_t::DECIMAL;
|
||||
fmt_type_t type = fmt_type_t::UNSPECIFIED;
|
||||
fmt_sign_t sign = fmt_sign_t::MINUS;
|
||||
bool leading_zeros = false;
|
||||
bool uppercase = false;
|
||||
|
|
|
@ -70,17 +70,11 @@ namespace blt::logging
|
|||
case fmt_sign_t::SPACE:
|
||||
if constexpr (std::is_arithmetic_v<T>)
|
||||
{
|
||||
if (type.type != fmt_type_t::BINARY && t >= 0)
|
||||
if (type.type != fmt_type_t::BINARY && static_cast<i64>(t) >= 0l)
|
||||
stream << ' ';
|
||||
}
|
||||
break;
|
||||
case fmt_sign_t::PLUS:
|
||||
if constexpr (std::is_arithmetic_v<T>)
|
||||
{
|
||||
if (t >= 0)
|
||||
stream << '+';
|
||||
}
|
||||
break;
|
||||
case fmt_sign_t::MINUS:
|
||||
break;
|
||||
}
|
||||
|
@ -129,23 +123,6 @@ namespace blt::logging
|
|||
stream << "{INVALID TYPE}";
|
||||
}
|
||||
break;
|
||||
case fmt_type_t::GENERAL:
|
||||
if constexpr (std::is_arithmetic_v<T>)
|
||||
{
|
||||
if (static_cast<u64>(t) > 10e12)
|
||||
exponential(stream);
|
||||
else
|
||||
fixed(stream);
|
||||
stream << t;
|
||||
}
|
||||
else
|
||||
{
|
||||
if constexpr (blt::meta::is_streamable_v<T>)
|
||||
stream << t;
|
||||
else
|
||||
stream << "{INVALID TYPE}";
|
||||
}
|
||||
break;
|
||||
case fmt_type_t::TYPE:
|
||||
stream << blt::type_string<T>();
|
||||
break;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 93201da2ba5a6aba0a6e57ada64973555629b3e3
|
||||
Subproject commit 7ef2e733416953b222851f9a360d7fc72d068ee5
|
|
@ -15,6 +15,7 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <blt/logging/fmt_tokenizer.h>
|
||||
|
@ -379,6 +380,23 @@ namespace blt::logging
|
|||
default:
|
||||
std::stringstream ss;
|
||||
ss << "Invalid type " << value;
|
||||
ss << std::endl << std::endl;
|
||||
ss << "Expected one of: " << std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "b | B" << std::setw(6) << ' ' << "Print as binary output" << std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "c" << std::setw(6) << ' ' << "Print as character output" << std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "d" << std::setw(6) << ' ' << "Print as decimal (base 10) output" << std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "o" << std::setw(6) << ' ' << "Print as octal (base 8) output" << std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "x | X" << std::setw(6) << ' ' << "Print as hexadecimal (base 16) output" <<
|
||||
std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "a | A" << std::setw(6) << ' ' << "Print floats as hexadecimal (base 16) output"
|
||||
<< std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "e | E" << std::setw(6) << ' ' << "Print floats in scientific notation" <<
|
||||
std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "f | F" << std::setw(6) << ' ' <<
|
||||
"Print floats in fixed point output, useful for setting precision of output" << std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "g | G" << std::setw(6) << ' ' <<
|
||||
"Print floats in general output, switching between fixed point and scientific notation based on magnitude" << std::endl;
|
||||
ss << std::setw(4) << ' ' << std::left << std::setw(5) << "t | T" << std::setw(6) << ' ' << "Print the type as a string" << std::endl;
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,11 +49,17 @@ namespace blt::logging
|
|||
if (spec.precision > 0)
|
||||
m_stream << std::setprecision(static_cast<i32>(spec.precision));
|
||||
else
|
||||
m_stream << std::setprecision(static_cast<int>(std::cout.precision()));
|
||||
m_stream << std::setprecision(16);
|
||||
if (spec.alternate_form)
|
||||
m_stream << std::showbase;
|
||||
if (spec.uppercase)
|
||||
m_stream << std::uppercase;
|
||||
else
|
||||
m_stream << std::nouppercase;
|
||||
if (spec.sign == fmt_sign_t::PLUS)
|
||||
m_stream << std::showpos;
|
||||
else
|
||||
m_stream << std::noshowpos;
|
||||
}
|
||||
|
||||
void logger_t::process_strings()
|
||||
|
@ -78,21 +84,16 @@ namespace blt::logging
|
|||
switch (spec.type)
|
||||
{
|
||||
case fmt_type_t::DECIMAL:
|
||||
stream << std::noboolalpha;
|
||||
stream << std::dec;
|
||||
break;
|
||||
case fmt_type_t::OCTAL:
|
||||
if (spec.alternate_form)
|
||||
stream << "0";
|
||||
stream << std::oct;
|
||||
break;
|
||||
case fmt_type_t::HEX:
|
||||
if (spec.alternate_form)
|
||||
stream << (spec.uppercase ? "0X" : "0x");
|
||||
stream << std::hex;
|
||||
break;
|
||||
case fmt_type_t::HEX_FLOAT:
|
||||
if (spec.alternate_form)
|
||||
stream << (spec.uppercase ? "0X" : "0x");
|
||||
stream << std::hexfloat;
|
||||
break;
|
||||
case fmt_type_t::EXPONENT:
|
||||
|
@ -101,6 +102,13 @@ namespace blt::logging
|
|||
case fmt_type_t::FIXED_POINT:
|
||||
stream << std::fixed;
|
||||
break;
|
||||
case fmt_type_t::GENERAL:
|
||||
stream << std::defaultfloat;
|
||||
break;
|
||||
case fmt_type_t::UNSPECIFIED:
|
||||
stream << std::boolalpha;
|
||||
stream << std::dec;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -41,13 +41,19 @@ int main()
|
|||
blt::logging::println("This is a println with hex with leading {:#.10x}", 4250);
|
||||
blt::logging::println("This is a println with binary {:#b}", 6969420);
|
||||
blt::logging::println("This is a println with binary with space {: #b}", 6969421);
|
||||
blt::logging::println("This is a println with binary with space {: b}", 69);
|
||||
blt::logging::println("This is a println with octal {:#o}", 6669);
|
||||
blt::logging::println("This is a println with hexfloat {:a}", 402.4320);
|
||||
blt::logging::println("This is a println with exponent {:e}", 44320902.4320);
|
||||
blt::logging::println("This is a println with exponent {:e}", 9532434234042340);
|
||||
blt::logging::println("This is a println with exponent {:g}", 953243.49);
|
||||
blt::logging::println("This is a println with exponent {:g}", 953243324023403240.49);
|
||||
blt::logging::println("This is a println with exponent {:e}", 9532434234042340.0);
|
||||
blt::logging::println("This is a println with general {:g}", 953243.49);
|
||||
blt::logging::println("This is a println with general {:g}", 953243324023403240.49);
|
||||
blt::logging::println("This is a println with a char {:c}", 66);
|
||||
blt::logging::println("This is a println with type {:t}", some_silly_type_t{});
|
||||
blt::logging::println("This is a println with boolean {}", true);
|
||||
blt::logging::println("This is a println with boolean as int {:d}", false);
|
||||
blt::logging::println("This is a println with boolean as hex {:#x}", true);
|
||||
blt::logging::println("This is a println with boolean as octal {:o}", true);
|
||||
blt::logging::println("This is a println with boolean as test {:h}", true);
|
||||
// blt::logging::println("This is println {}\twith a std::endl in the middle of it");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue