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
openmsx::pointerError
void pointerError(unsigned id)
Definition: serialize_core.cc:13
unlikely
#define unlikely(x)
Definition: likely.hh:15
serialize.hh
openmsx::XmlInputArchive
Definition: serialize.hh:904
openmsx::XmlInputArchive::findAttribute
bool findAttribute(const char *name, unsigned &value)
Definition: serialize.cc:548
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:9
likely.hh
serialize_core.hh
openmsx::enumError
void enumError(const std::string &str)
Definition: serialize_core.cc:8
UNREACHABLE
#define UNREACHABLE
Definition: unreachable.hh:38
openmsx::loadVersionHelper
unsigned loadVersionHelper(MemInputArchive &, const char *, unsigned)
Definition: serialize_core.cc:30
openmsx::MemInputArchive
Definition: serialize.hh:746
openmsx::XmlInputArchive::canHaveOptionalAttributes
bool canHaveOptionalAttributes() const
Definition: serialize.hh:951
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5