| 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 |
|
| 22 |
|
| 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& , const char* , |
| 31 |
unsigned ) |
| 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 |
} |