C1: deny drops into black holes
[openc2e.git] / ser / s_caosScript.h
blob02cac10e04f1b08232db249d60cf9fbe4eaafcd1
1 #ifndef SER_CAOSSCRIPT_H
2 #define SER_CAOSSCRIPT_H 1
4 #include "serialization.h"
5 #include "ser/s_caosVar.h"
6 #include "caosScript.h"
7 #include "ser/s_bytecode.h"
8 #include "ser/s_shared_str.h"
10 #include <boost/serialization/shared_ptr.hpp>
11 #include <boost/serialization/vector.hpp>
12 #include <boost/serialization/string.hpp>
13 #include <boost/serialization/map.hpp>
15 BOOST_CLASS_IMPLEMENTATION(toktrace, boost::serialization::object_serializable);
16 BOOST_CLASS_TRACKING(toktrace, boost::serialization::track_never);
17 SERIALIZE(toktrace) {
18 ar & obj.width & obj.lineno;
21 SERIALIZE(script) {
22 // ar & obj.linked;
23 // ar & obj.relocations;
24 // ar & obj.labels;
26 ar & obj.ops;
27 ar & obj.consts;
28 ar & obj.bytestrs;
29 ar & obj.code;
30 ar & obj.tokinfo;
32 // ar & obj.fmly & obj.gnus & obj.spcs & obj.scrp;
33 // dialect handled in post-serialization code
34 ar & obj.filename;
35 // ar & obj.gsub; // XXX duplicate with labels
38 static std::map<const Dialect *, boost::shared_ptr<std::vector<std::string> > >
39 dialect_trans_map;
41 static void make_trans_map(const Dialect *d) {
42 if (dialect_trans_map[d])
43 return;
44 std::vector<std::string> *p = new std::vector<std::string>(d->cmdcount());
45 dialect_trans_map[d] = boost::shared_ptr<std::vector<std::string> >(p);
46 const struct cmdinfo *ci;
47 for (int i = 0; i < d->cmdcount(); i++) {
48 (*p)[i] = std::string(d->getcmd(i)->lookup_key);
52 POST_SAVE(script) {
53 ar & obj.dialect->name;
54 make_trans_map(obj.dialect);
55 ar & dialect_trans_map[obj.dialect];
58 POST_LOAD(script) {
59 std::string name;
60 boost::shared_ptr<std::vector<std::string> > trans_map;
61 ar & name;
62 ar & trans_map;
64 const Dialect *d = obj.dialect = dialects[name].get();
65 if (!d) {
66 throw creaturesException(
67 boost::str(
68 boost::format("Deserialization error: Unknown dialect '%s'") % name
73 for (size_t i = 0; i < obj.ops.size(); i++) {
74 if (obj.ops[i].opcode == CAOS_CMD || obj.ops[i].opcode == CAOS_SAVE_CMD) {
75 std::string cmdname = (*trans_map)[obj.ops[i].argument];
76 const cmdinfo *ci = d->find_command(cmdname.c_str());
77 if (!ci) {
78 throw creaturesException(
79 boost::str(boost::format("Deserialization error: Unknown key '%s' in dialect '%s'") % cmdname % name));
81 obj.ops[i].argument = d->cmd_index(ci);
86 #endif