[ox/std] Improve noexcept correctness and make Error parameters into references
This commit is contained in:
parent
ee6929c7f0
commit
85f3904115
2
deps/ox/src/ox/std/fmt.hpp
vendored
2
deps/ox/src/ox/std/fmt.hpp
vendored
@ -52,7 +52,7 @@ class FmtArg {
|
|||||||
const char *out = nullptr;
|
const char *out = nullptr;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr FmtArg(T v) noexcept {
|
constexpr FmtArg(const T &v) noexcept {
|
||||||
if constexpr(is_bool_v<T>) {
|
if constexpr(is_bool_v<T>) {
|
||||||
out = v ? "true" : "false";
|
out = v ? "true" : "false";
|
||||||
} else if constexpr(is_integral_v<T>) {
|
} else if constexpr(is_integral_v<T>) {
|
||||||
|
23
deps/ox/src/ox/std/trace.hpp
vendored
23
deps/ox/src/ox/std/trace.hpp
vendored
@ -35,9 +35,10 @@ struct TraceMsg {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Error model(T *io, ox::trace::TraceMsg *obj) {
|
constexpr Error model(T *io, ox::trace::TraceMsg *obj) {
|
||||||
auto err = OxError(0);
|
auto err = OxError(0);
|
||||||
io->setTypeInfo("ox::trace::TraceMsg", 5);
|
io->setTypeInfo("ox::trace::TraceMsg", 5);
|
||||||
|
oxReturnError(io->field("ch", &obj->ch));
|
||||||
oxReturnError(io->field("file", &obj->file));
|
oxReturnError(io->field("file", &obj->file));
|
||||||
oxReturnError(io->field("line", &obj->line));
|
oxReturnError(io->field("line", &obj->line));
|
||||||
oxReturnError(io->field("time", &obj->time));
|
oxReturnError(io->field("time", &obj->time));
|
||||||
@ -52,7 +53,7 @@ class OutStream {
|
|||||||
TraceMsg m_msg;
|
TraceMsg m_msg;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr OutStream(const char *file, int line, const char *ch, const char *msg = "") {
|
constexpr OutStream(const char *file, int line, const char *ch, const char *msg = "") noexcept {
|
||||||
m_msg.file = file;
|
m_msg.file = file;
|
||||||
m_msg.line = line;
|
m_msg.line = line;
|
||||||
m_msg.ch = ch;
|
m_msg.ch = ch;
|
||||||
@ -61,7 +62,7 @@ class OutStream {
|
|||||||
|
|
||||||
#ifdef OX_USE_STDLIB
|
#ifdef OX_USE_STDLIB
|
||||||
template<std::size_t fmtSegmentCnt, typename ...Args>
|
template<std::size_t fmtSegmentCnt, typename ...Args>
|
||||||
constexpr OutStream(const char *file, int line, const char *ch, detail::Fmt<fmtSegmentCnt> fmtSegments, std::array<detail::FmtArg, fmtSegmentCnt - 1> elements) {
|
constexpr OutStream(const char *file, int line, const char *ch, detail::Fmt<fmtSegmentCnt> fmtSegments, std::array<detail::FmtArg, fmtSegmentCnt - 1> elements) noexcept {
|
||||||
//static_assert(sizeof...(args) == fmtSegmentCnt - 1, "Wrong number of trace arguments for format.");
|
//static_assert(sizeof...(args) == fmtSegmentCnt - 1, "Wrong number of trace arguments for format.");
|
||||||
m_msg.file = file;
|
m_msg.file = file;
|
||||||
m_msg.line = line;
|
m_msg.line = line;
|
||||||
@ -93,12 +94,12 @@ class OutStream {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline ~OutStream() {
|
inline ~OutStream() noexcept {
|
||||||
oxTraceHook(m_msg.file, m_msg.line, m_msg.ch, m_msg.msg.c_str());
|
oxTraceHook(m_msg.file, m_msg.line, m_msg.ch, m_msg.msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr OutStream &operator<<(const T &v) {
|
constexpr OutStream &operator<<(const T &v) noexcept {
|
||||||
if (m_msg.msg.len()) {
|
if (m_msg.msg.len()) {
|
||||||
m_msg.msg += m_delimiter;
|
m_msg.msg += m_delimiter;
|
||||||
}
|
}
|
||||||
@ -106,7 +107,7 @@ class OutStream {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr OutStream &operator<<(Error err) {
|
constexpr OutStream &operator<<(const Error &err) noexcept {
|
||||||
if (m_msg.msg.len()) {
|
if (m_msg.msg.len()) {
|
||||||
m_msg.msg += m_delimiter;
|
m_msg.msg += m_delimiter;
|
||||||
}
|
}
|
||||||
@ -117,7 +118,7 @@ class OutStream {
|
|||||||
/**
|
/**
|
||||||
* del sets the delimiter between log segments.
|
* del sets the delimiter between log segments.
|
||||||
*/
|
*/
|
||||||
constexpr OutStream &del(const char *delimiter) {
|
constexpr OutStream &del(const char *delimiter) noexcept {
|
||||||
m_delimiter = delimiter;
|
m_delimiter = delimiter;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -128,12 +129,12 @@ class OutStream {
|
|||||||
class NullStream {
|
class NullStream {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr NullStream(const char*, int, const char*, const char* = "") {
|
constexpr NullStream(const char*, int, const char*, const char* = "") noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OX_USE_STDLIB
|
#ifdef OX_USE_STDLIB
|
||||||
template<std::size_t fmtSegmentCnt, typename ...Args>
|
template<std::size_t fmtSegmentCnt, typename ...Args>
|
||||||
constexpr NullStream(const char*, int, const char*, detail::Fmt<fmtSegmentCnt>, std::array<detail::FmtArg, fmtSegmentCnt - 1>) {
|
constexpr NullStream(const char*, int, const char*, detail::Fmt<fmtSegmentCnt>, std::array<detail::FmtArg, fmtSegmentCnt - 1>) noexcept {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template<std::size_t fmtSegmentCnt, typename ...Args>
|
template<std::size_t fmtSegmentCnt, typename ...Args>
|
||||||
@ -142,11 +143,11 @@ class NullStream {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr NullStream &operator<<(const T&) {
|
constexpr NullStream &operator<<(const T&) noexcept {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr NullStream &del(const char*) {
|
constexpr NullStream &del(const char*) noexcept {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user