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
);
18 ar
& obj
.width
& obj
.lineno
;
23 // ar & obj.relocations;
32 // ar & obj.fmly & obj.gnus & obj.spcs & obj.scrp;
33 // dialect handled in post-serialization code
35 // ar & obj.gsub; // XXX duplicate with labels
38 static std::map
<const Dialect
*, boost::shared_ptr
<std::vector
<std::string
> > >
41 static void make_trans_map(const Dialect
*d
) {
42 if (dialect_trans_map
[d
])
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
);
53 ar
& obj
.dialect
->name
;
54 make_trans_map(obj
.dialect
);
55 ar
& dialect_trans_map
[obj
.dialect
];
60 boost::shared_ptr
<std::vector
<std::string
> > trans_map
;
64 const Dialect
*d
= obj
.dialect
= dialects
[name
].get();
66 throw creaturesException(
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());
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
);