serialize.cc (4762:c94e103c83ad) serialize.cc (4841:89a9419e7361)
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 26 unchanged lines hidden (view full) ---

35#include <sys/stat.h>
36#include <errno.h>
37
38#include <fstream>
39#include <list>
40#include <string>
41#include <vector>
42
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 26 unchanged lines hidden (view full) ---

35#include <sys/stat.h>
36#include <errno.h>
37
38#include <fstream>
39#include <list>
40#include <string>
41#include <vector>
42
43#include "base/annotate.hh"
43#include "base/inifile.hh"
44#include "base/misc.hh"
45#include "base/output.hh"
46#include "base/str.hh"
47#include "base/trace.hh"
48#include "sim/eventq.hh"
49#include "sim/serialize.hh"
50#include "sim/sim_events.hh"

--- 122 unchanged lines hidden (view full) ---

173void
174paramOut(ostream &os, const std::string &name, const T &param)
175{
176 os << name << "=";
177 showParam(os, param);
178 os << "\n";
179}
180
44#include "base/inifile.hh"
45#include "base/misc.hh"
46#include "base/output.hh"
47#include "base/str.hh"
48#include "base/trace.hh"
49#include "sim/eventq.hh"
50#include "sim/serialize.hh"
51#include "sim/sim_events.hh"

--- 122 unchanged lines hidden (view full) ---

174void
175paramOut(ostream &os, const std::string &name, const T &param)
176{
177 os << name << "=";
178 showParam(os, param);
179 os << "\n";
180}
181
182template <class T>
183void
184arrayParamOut(ostream &os, const std::string &name,
185 const std::vector<T> &param)
186{
187 int size = param.size();
188 os << name << "=";
189 if (size > 0)
190 showParam(os, param[0]);
191 for (int i = 1; i < size; ++i) {
192 os << " ";
193 showParam(os, param[i]);
194 }
195 os << "\n";
196}
181
197
198
182template <class T>
183void
184paramIn(Checkpoint *cp, const std::string &section,
185 const std::string &name, T &param)
186{
187 std::string str;
188 if (!cp->find(section, name, str) || !parseParam(str, param)) {
189 fatal("Can't unserialize '%s:%s'\n", section, name);

--- 56 unchanged lines hidden (view full) ---

246 fatal(err);
247 }
248
249 // assign parsed value to vector
250 param[i] = scalar_value;
251 }
252}
253
199template <class T>
200void
201paramIn(Checkpoint *cp, const std::string &section,
202 const std::string &name, T &param)
203{
204 std::string str;
205 if (!cp->find(section, name, str) || !parseParam(str, param)) {
206 fatal("Can't unserialize '%s:%s'\n", section, name);

--- 56 unchanged lines hidden (view full) ---

263 fatal(err);
264 }
265
266 // assign parsed value to vector
267 param[i] = scalar_value;
268 }
269}
270
271template <class T>
272void
273arrayParamIn(Checkpoint *cp, const std::string &section,
274 const std::string &name, std::vector<T> &param)
275{
276 std::string str;
277 if (!cp->find(section, name, str)) {
278 fatal("Can't unserialize '%s:%s'\n", section, name);
279 }
254
280
281 // code below stolen from VectorParam<T>::parse().
282 // it would be nice to unify these somehow...
283
284 vector<string> tokens;
285
286 tokenize(tokens, str, ' ');
287
288 // Need this if we were doing a vector
289 // value.resize(tokens.size());
290
291 param.resize(tokens.size());
292
293 for (int i = 0; i < tokens.size(); i++) {
294 // need to parse into local variable to handle vector<bool>,
295 // for which operator[] returns a special reference class
296 // that's not the same as 'bool&', (since it's a packed
297 // vector)
298 T scalar_value;
299 if (!parseParam(tokens[i], scalar_value)) {
300 string err("could not parse \"");
301
302 err += str;
303 err += "\"";
304
305 fatal(err);
306 }
307
308 // assign parsed value to vector
309 param[i] = scalar_value;
310 }
311}
312
313
314
255void
256objParamIn(Checkpoint *cp, const std::string &section,
257 const std::string &name, SimObject * &param)
258{
259 if (!cp->findObj(section, name, param)) {
260 fatal("Can't unserialize '%s:%s'\n", section, name);
261 }
262}

--- 5 unchanged lines hidden (view full) ---

268template void \
269paramIn(Checkpoint *cp, const std::string &section, \
270 const std::string &name, type & param); \
271template void \
272arrayParamOut(ostream &os, const std::string &name, \
273 type const *param, int size); \
274template void \
275arrayParamIn(Checkpoint *cp, const std::string &section, \
315void
316objParamIn(Checkpoint *cp, const std::string &section,
317 const std::string &name, SimObject * &param)
318{
319 if (!cp->findObj(section, name, param)) {
320 fatal("Can't unserialize '%s:%s'\n", section, name);
321 }
322}

--- 5 unchanged lines hidden (view full) ---

328template void \
329paramIn(Checkpoint *cp, const std::string &section, \
330 const std::string &name, type & param); \
331template void \
332arrayParamOut(ostream &os, const std::string &name, \
333 type const *param, int size); \
334template void \
335arrayParamIn(Checkpoint *cp, const std::string &section, \
276 const std::string &name, type *param, int size);
336 const std::string &name, type *param, int size); \
337template void \
338arrayParamOut(ostream &os, const std::string &name, \
339 const std::vector<type> &param); \
340template void \
341arrayParamIn(Checkpoint *cp, const std::string &section, \
342 const std::string &name, std::vector<type> &param);
277
278INSTANTIATE_PARAM_TEMPLATES(signed char)
279INSTANTIATE_PARAM_TEMPLATES(unsigned char)
280INSTANTIATE_PARAM_TEMPLATES(signed short)
281INSTANTIATE_PARAM_TEMPLATES(unsigned short)
282INSTANTIATE_PARAM_TEMPLATES(signed int)
283INSTANTIATE_PARAM_TEMPLATES(unsigned int)
284INSTANTIATE_PARAM_TEMPLATES(signed long)

--- 53 unchanged lines hidden (view full) ---

338 fatal("couldn't mkdir %s\n", dir);
339
340 string cpt_file = dir + Checkpoint::baseFilename;
341 ofstream outstream(cpt_file.c_str());
342 time_t t = time(NULL);
343 outstream << "// checkpoint generated: " << ctime(&t);
344
345 globals.serialize(outstream);
343
344INSTANTIATE_PARAM_TEMPLATES(signed char)
345INSTANTIATE_PARAM_TEMPLATES(unsigned char)
346INSTANTIATE_PARAM_TEMPLATES(signed short)
347INSTANTIATE_PARAM_TEMPLATES(unsigned short)
348INSTANTIATE_PARAM_TEMPLATES(signed int)
349INSTANTIATE_PARAM_TEMPLATES(unsigned int)
350INSTANTIATE_PARAM_TEMPLATES(signed long)

--- 53 unchanged lines hidden (view full) ---

404 fatal("couldn't mkdir %s\n", dir);
405
406 string cpt_file = dir + Checkpoint::baseFilename;
407 ofstream outstream(cpt_file.c_str());
408 time_t t = time(NULL);
409 outstream << "// checkpoint generated: " << ctime(&t);
410
411 globals.serialize(outstream);
412 Annotate::annotations.serialize(outstream);
346 SimObject::serializeAll(outstream);
347}
348
349void
350Serializable::unserializeAll(const std::string &cpt_dir)
351{
352 setCheckpointDir(cpt_dir);
353 string dir = Checkpoint::dir();
354 string cpt_file = dir + Checkpoint::baseFilename;
355 string section = "";
356
357 DPRINTFR(Config, "Loading checkpoint dir '%s'\n",
358 dir);
359 Checkpoint *cp = new Checkpoint(dir, section);
360 unserializeGlobals(cp);
413 SimObject::serializeAll(outstream);
414}
415
416void
417Serializable::unserializeAll(const std::string &cpt_dir)
418{
419 setCheckpointDir(cpt_dir);
420 string dir = Checkpoint::dir();
421 string cpt_file = dir + Checkpoint::baseFilename;
422 string section = "";
423
424 DPRINTFR(Config, "Loading checkpoint dir '%s'\n",
425 dir);
426 Checkpoint *cp = new Checkpoint(dir, section);
427 unserializeGlobals(cp);
361
428 Annotate::annotations.unserialize(cp);
362 SimObject::unserializeAll(cp);
363}
364
365void
366Serializable::unserializeGlobals(Checkpoint *cp)
367{
368 globals.unserialize(cp);
369}

--- 134 unchanged lines hidden ---
429 SimObject::unserializeAll(cp);
430}
431
432void
433Serializable::unserializeGlobals(Checkpoint *cp)
434{
435 globals.unserialize(cp);
436}

--- 134 unchanged lines hidden ---