OXYGENHUB
◆ main openmsx / src / serialize_core.cc
1.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "serialize_core.hh"
2
3
#include "MSXException.hh"
4
#include "serialize.hh"
5
6
namespace openmsx {
7
8
void enumError(std::string_view str)
9
{
10
	throw MSXException("Invalid enum value: ", str);
11
}
12
13
void pointerError(unsigned id)
14
{
15
	throw MSXException("Couldn't find pointer in archive with id ", id);
16
}
17
18
19
[[noreturn]] static void versionError(const char* className, unsigned latestVersion, unsigned version)
20
{
21
	// note: the result of type_info::name() is implementation defined
22
	//       but should be ok to show in an error message
23
	throw MSXException(
24
		"your openMSX installation is too old (state contains type '",
25
		className, "' with version ", version,
26
		", while this openMSX installation only supports up to version ",
27
		latestVersion, ").");
28
}
29
30
unsigned loadVersionHelper(MemInputArchive& /*ar*/, const char* /*className*/,
31
                           unsigned /*latestVersion*/)
32
{
33
	UNREACHABLE;
34
}
35
36
unsigned loadVersionHelper(XmlInputArchive& ar, const char* className,
37
                           unsigned latestVersion)
38
{
39
	assert(ar.CAN_HAVE_OPTIONAL_ATTRIBUTES);
40
	auto version = ar.findAttributeAs<unsigned>("version");
41
	if (!version) return 1;
42
	if (*version > latestVersion) [[unlikely]] {
43
		versionError(className, latestVersion, *version);
44
	}
45
	return *version;
46
}
47
48
} // namespace openmsx