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(const 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 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; return 0;
33 }
34 
35 unsigned 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:971
std::optional< T > findAttributeAs(const char *name)
Definition: serialize.hh:996
This file implemented 3 utility functions:
Definition: Autofire.cc:9
void pointerError(unsigned id)
unsigned loadVersionHelper(MemInputArchive &, const char *, unsigned)
void enumError(const std::string_view str)
#define UNREACHABLE
Definition: unreachable.hh:38