openMSX
serialize_core.cc
Go to the documentation of this file.
1
#include "
serialize_core.hh
"
2
#include "
serialize.hh
"
3
#include "
MSXException.hh
"
4
5
namespace
openmsx
{
6
7
void
enumError
(std::string_view str)
8
{
9
throw
MSXException
(
"Invalid enum value: "
, str);
10
}
11
12
void
pointerError
(
unsigned
id
)
13
{
14
throw
MSXException
(
"Couldn't find pointer in archive with id "
,
id
);
15
}
16
17
18
[[noreturn]]
static
void
versionError(
const
char
* className,
unsigned
latestVersion,
unsigned
version)
19
{
20
// note: the result of type_info::name() is implementation defined
21
// but should be ok to show in an error message
22
throw
MSXException(
23
"your openMSX installation is too old (state contains type '"
,
24
className,
"' with version "
, version,
25
", while this openMSX installation only supports up to version "
,
26
latestVersion,
")."
);
27
}
28
29
unsigned
loadVersionHelper
(
MemInputArchive
&
/*ar*/
,
const
char
*
/*className*/
,
30
unsigned
/*latestVersion*/
)
31
{
32
UNREACHABLE
;
33
}
34
35
unsigned
loadVersionHelper
(
XmlInputArchive
& ar,
const
char
* className,
36
unsigned
latestVersion)
37
{
38
assert(ar.
CAN_HAVE_OPTIONAL_ATTRIBUTES
);
39
auto
version = ar.
findAttributeAs
<
unsigned
>(
"version"
);
40
if
(!version)
return
1;
41
if
(*version > latestVersion) [[unlikely]] {
42
versionError(className, latestVersion, *version);
43
}
44
return
*version;
45
}
46
47
}
// namespace openmsx
MSXException.hh
openmsx::MSXException
Definition
MSXException.hh:12
openmsx::MemInputArchive
Definition
serialize.hh:763
openmsx::XmlInputArchive
Definition
serialize.hh:922
openmsx::XmlInputArchive::CAN_HAVE_OPTIONAL_ATTRIBUTES
static constexpr bool CAN_HAVE_OPTIONAL_ATTRIBUTES
Definition
serialize.hh:972
openmsx::XmlInputArchive::findAttributeAs
std::optional< T > findAttributeAs(const char *name)
Definition
serialize.hh:997
openmsx
This file implemented 3 utility functions:
Definition
Autofire.cc:11
openmsx::enumError
void enumError(std::string_view str)
Definition
serialize_core.cc:7
openmsx::pointerError
void pointerError(unsigned id)
Definition
serialize_core.cc:12
openmsx::loadVersionHelper
unsigned loadVersionHelper(MemInputArchive &, const char *, unsigned)
Definition
serialize_core.cc:29
serialize.hh
serialize_core.hh
UNREACHABLE
#define UNREACHABLE
Definition
unreachable.hh:40
Generated on Thu Dec 19 2024 23:13:46 for openMSX by
1.9.8