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 #include "likely.hh"
5 
6 namespace openmsx {
7 
8 void enumError(const std::string& 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 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; return 0;
34 }
35 
36 unsigned loadVersionHelper(XmlInputArchive& ar, const char* className,
37  unsigned latestVersion)
38 {
39  assert(ar.canHaveOptionalAttributes());
40  unsigned version;
41  if (!ar.findAttribute("version", version)) {
42  return 1;
43  }
44  if (unlikely(version > latestVersion)) {
45  versionError(className, latestVersion, version);
46  }
47  return version;
48 }
49 
50 } // namespace openmsx
bool findAttribute(const char *name, unsigned &value)
Definition: serialize.cc:534
#define unlikely(x)
Definition: likely.hh:15
void pointerError(unsigned id)
unsigned loadVersionHelper(MemInputArchive &, const char *, unsigned)
bool canHaveOptionalAttributes() const
Definition: serialize.hh:810
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void enumError(const std::string &str)
#define UNREACHABLE
Definition: unreachable.hh:35