Zserio C++17 runtime library
1.3.0
Built for Zserio 2.20.0
Loading...
Searching...
No Matches
CppRuntimeException.cpp
Go to the documentation of this file.
1
#include <algorithm>
2
#include <cstring>
3
4
#include "
zserio/CppRuntimeException.h
"
5
6
namespace
zserio
7
{
8
9
CppRuntimeException::CppRuntimeException
(
const
char
*
message
) :
10
m_buffer()
11
{
12
append
(
message
);
13
}
14
15
CppRuntimeException::~CppRuntimeException
() =
default
;
16
17
const
char
*
CppRuntimeException::what
()
const
noexcept
18
{
19
return
m_buffer.data();
20
}
21
22
void
CppRuntimeException::append
(
const
char
*
message
)
23
{
24
const
size_t
available
= m_buffer.size() - 1 - m_len;
25
const
size_t
numCharsToAppend
=
strnlen
(
message
,
available
);
26
appendImpl(std::string_view(
message
,
numCharsToAppend
));
27
}
28
29
void
CppRuntimeException::append
(
const
char
*
message
,
size_t
messageLen
)
30
{
31
const
size_t
available
= m_buffer.size() - 1 - m_len;
32
const
size_t
numCharsToAppend
= std::min(
messageLen
,
available
);
33
appendImpl(std::string_view(
message
,
numCharsToAppend
));
34
}
35
36
void
CppRuntimeException::appendImpl(std::string_view
message
)
37
{
38
if
(
message
.size() > 0)
39
{
40
(
void
)std::copy(
message
.begin(),
message
.end(), m_buffer.begin() + m_len);
41
m_len +=
message
.size();
42
}
43
m_buffer.at(m_len) =
'\0'
;
44
}
45
46
CppRuntimeException
&
operator<<
(
CppRuntimeException
& exception,
const
char
*
message
)
47
{
48
exception.
append
(
message
);
49
return
exception;
50
}
51
52
CppRuntimeException
&
operator<<
(
CppRuntimeException
& exception,
bool
value)
53
{
54
return
exception << (value ?
"true"
:
"false"
);
55
}
56
57
CppRuntimeException
&
operator<<
(
CppRuntimeException
& exception,
float
value)
58
{
59
std::array<char, 24>
integerPartBuffer
= {};
60
std::array<char, 24>
floatingPartBuffer
= {};
61
const
char
*
integerPartString
=
nullptr
;
62
const
char
*
floatingPartString
=
nullptr
;
63
convertFloatToString
(
integerPartBuffer
,
floatingPartBuffer
, value,
integerPartString
,
floatingPartString
);
64
CppRuntimeException
&
result
= exception <<
integerPartString
;
65
if
(
floatingPartString
!=
nullptr
)
66
{
67
result
=
result
<<
"."
<<
floatingPartString
;
68
}
69
70
return
result
;
71
}
72
73
CppRuntimeException
&
operator<<
(
CppRuntimeException
& exception,
double
value)
74
{
75
return
exception << (static_cast<float>
(value));
76
}
77
78
CppRuntimeException
&
operator<<
(
CppRuntimeException
& exception, std::string_view value)
79
{
80
exception.
append
(value.data(), value.size());
81
return
exception;
82
}
83
84
}
// namespace zserio
CppRuntimeException.h
zserio::CppRuntimeException
Definition
CppRuntimeException.h:20
zserio::CppRuntimeException::~CppRuntimeException
~CppRuntimeException() override
zserio::CppRuntimeException::what
const char * what() const noexcept override
Definition
CppRuntimeException.cpp:17
zserio::CppRuntimeException::CppRuntimeException
CppRuntimeException(const char *message="")
Definition
CppRuntimeException.cpp:9
zserio::CppRuntimeException::append
void append(const char *message)
Definition
CppRuntimeException.cpp:22
zserio::View
Definition
Traits.h:15
zserio
Definition
AllocatorHolder.h:8
zserio::operator<<
CppRuntimeException & operator<<(CppRuntimeException &exception, const BasicBitBuffer< ALLOC > &bitBuffer)
Definition
BitBuffer.h:554
zserio::convertFloatToString
void convertFloatToString(std::array< char, 24 > &integerPartBuffer, std::array< char, 24 > &floatingPartBuffer, float value, const char *&integerPartString, const char *&floatingPartString)
Definition
StringConvertUtil.h:119
zserio
CppRuntimeException.cpp
Generated by
1.9.8