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
5namespace openmsx {
6
7void enumError(std::string_view str)
8{
9 throw MSXException("Invalid enum value: ", str);
10}
11
12void 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
29unsigned loadVersionHelper(MemInputArchive& /*ar*/, const char* /*className*/,
30 unsigned /*latestVersion*/)
31{
33}
34
35unsigned loadVersionHelper(XmlInputArchive& ar, const char* className,
36 unsigned latestVersion)
37{
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
static constexpr bool CAN_HAVE_OPTIONAL_ATTRIBUTES
Definition serialize.hh:983
std::optional< T > findAttributeAs(const char *name)
This file implemented 3 utility functions:
Definition Autofire.cc:11
void enumError(std::string_view str)
void pointerError(unsigned id)
unsigned loadVersionHelper(MemInputArchive &, const char *, unsigned)
#define UNREACHABLE