mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd: Add exception message generation bypass constructor.
This commit is contained in:
parent
dffb39f8cc
commit
2c231ac187
2 changed files with 18 additions and 4 deletions
|
@ -52,6 +52,8 @@ struct exception
|
||||||
:std::exception
|
:std::exception
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
IRCD_OVERLOAD(generate_skip)
|
||||||
|
|
||||||
char buf[BUFSIZE];
|
char buf[BUFSIZE];
|
||||||
|
|
||||||
ssize_t generate(const char *const &name, const char *const &fmt, va_list ap) noexcept;
|
ssize_t generate(const char *const &name, const char *const &fmt, va_list ap) noexcept;
|
||||||
|
@ -63,7 +65,7 @@ struct exception
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
exception() noexcept
|
exception(const generate_skip_t = {}) noexcept
|
||||||
{
|
{
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -106,24 +108,36 @@ struct name \
|
||||||
:parent \
|
:parent \
|
||||||
{ \
|
{ \
|
||||||
name(const char *const fmt = " ", ...) noexcept AFP(2, 3) \
|
name(const char *const fmt = " ", ...) noexcept AFP(2, 3) \
|
||||||
|
:parent{generate_skip} \
|
||||||
{ \
|
{ \
|
||||||
va_list ap; \
|
va_list ap; \
|
||||||
va_start(ap, fmt); \
|
va_start(ap, fmt); \
|
||||||
generate(#name, fmt, ap); \
|
generate(#name, fmt, ap); \
|
||||||
va_end(ap); \
|
va_end(ap); \
|
||||||
} \
|
} \
|
||||||
};
|
\
|
||||||
|
name(const generate_skip_t) noexcept \
|
||||||
|
:parent{generate_skip} \
|
||||||
|
{ \
|
||||||
|
} \
|
||||||
|
}; \
|
||||||
|
|
||||||
#define IRCD_EXCEPTION_HIDENAME(parent, name) \
|
#define IRCD_EXCEPTION_HIDENAME(parent, name) \
|
||||||
struct name \
|
struct name \
|
||||||
:parent \
|
:parent \
|
||||||
{ \
|
{ \
|
||||||
name(const char *const fmt = " ", ...) noexcept AFP(2, 3) \
|
name(const char *const fmt, ...) noexcept AFP(2, 3) \
|
||||||
|
parent{generate_skip_t} \
|
||||||
{ \
|
{ \
|
||||||
va_list ap; \
|
va_list ap; \
|
||||||
va_start(ap, fmt); \
|
va_start(ap, fmt); \
|
||||||
generate(fmt, ap); \
|
generate(fmt, ap); \
|
||||||
va_end(ap); \
|
va_end(ap); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
name(const generate_skip_t = {}) noexcept \
|
||||||
|
:parent{generate_skip} \
|
||||||
|
{ \
|
||||||
} \
|
} \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ noexcept
|
||||||
{
|
{
|
||||||
size_t size(0);
|
size_t size(0);
|
||||||
const bool empty(!fmt || !fmt[0] || fmt[0] == ' ');
|
const bool empty(!fmt || !fmt[0] || fmt[0] == ' ');
|
||||||
size = rb_strlcpy(buf, name, sizeof(buf));
|
size = rb_strlcat(buf, name, sizeof(buf));
|
||||||
size = rb_strlcat(buf, empty? "." : ": ", sizeof(buf));
|
size = rb_strlcat(buf, empty? "." : ": ", sizeof(buf));
|
||||||
if(size < sizeof(buf))
|
if(size < sizeof(buf))
|
||||||
size += vsnprintf(buf + size, sizeof(buf) - size, fmt, ap);
|
size += vsnprintf(buf + size, sizeof(buf) - size, fmt, ap);
|
||||||
|
|
Loading…
Reference in a new issue