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 "StringOp.hh"
5 #include "likely.hh"
6 
7 namespace openmsx {
8 
9 void enumError(const std::string& str)
10 {
11  throw MSXException("Invalid enum value: " + str);
12 }
13 
14 void pointerError(unsigned id)
15 {
17  "Couldn't find pointer in archive with id " << id);
18 }
19 
20 
21 static void versionError(const char* className, unsigned latestVersion, unsigned version)
22 {
23  // note: the result of type_info::name() is implementation defined
24  // but should be ok to show in an error message
26  "your openMSX installation is too old (state contains type '" <<
27  className << "' with version " << version <<
28  ", while this openMSX installation only supports up to version " <<
29  latestVersion << ").");
30 }
31 
32 unsigned loadVersionHelper(MemInputArchive& /*ar*/, const char* /*className*/,
33  unsigned /*latestVersion*/)
34 {
35  UNREACHABLE; return 0;
36 }
37 
38 unsigned loadVersionHelper(XmlInputArchive& ar, const char* className,
39  unsigned latestVersion)
40 {
41  assert(ar.canHaveOptionalAttributes());
42  unsigned version;
43  if (!ar.findAttribute("version", version)) {
44  return 1;
45  }
46  if (unlikely(version > latestVersion)) {
47  versionError(className, latestVersion, version);
48  }
49  return version;
50 }
51 
52 } // namespace openmsx
bool findAttribute(const char *name, unsigned &value)
Definition: serialize.cc:536
#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