50 #ifndef __SERIALIZE_HH__ 51 #define __SERIALIZE_HH__ 86 bool find(
const std::string §ion,
const std::string &entry,
89 bool findObj(
const std::string §ion,
const std::string &entry,
93 bool entryExists(
const std::string §ion,
const std::string &entry);
111 static std::string
setDir(
const std::string &base_name);
117 static std::string
dir();
183 pushName(name.c_str());
197 void pushName(
const char *
name);
238 serializeSection(cp, name.c_str());
251 void unserializeSection(
CheckpointIn &cp,
const char *name);
254 unserializeSection(cp, name.c_str());
258 static const std::string ¤tSection();
263 static void serializeAll(
const std::string &cpt_dir);
267 static std::stack<std::string>
path;
308 os << ((
sizeof(storage) == 1) ?
309 static_cast<unsigned int>(storage) : storage);
331 os << (
unsigned int)value;
360 os << (value ?
"true" :
"false");
388 fatal(
"Can't unserialize '%s:%s'\n", section, name);
395 T ¶m,
bool warn =
true)
401 warn(
"optional parameter %s:%s not present\n", section, name);
432 if (param.size() > 0)
435 while (it != param.end()) {
446 const std::set<T> ¶m)
448 typename std::set<T>::const_iterator it = param.begin();
451 if (param.size() > 0)
454 while (it != param.end()) {
465 const T *param,
unsigned size)
470 for (
unsigned i = 1;
i < size; ++
i) {
489 T *param,
unsigned size)
493 if (!cp.
find(section, name, str)) {
494 fatal(
"Can't unserialize '%s:%s'\n", section, name);
508 "Array size mismatch on %s:%s (Got %u, expected %u)'\n",
509 section,
name, tokens.size(), size);
518 std::string err(
"could not parse \"");
527 param[
i] = scalar_value;
537 if (!cp.
find(section, name, str)) {
538 fatal(
"Can't unserialize '%s:%s'\n", section, name);
551 param.resize(tokens.size());
560 std::string err(
"could not parse \"");
569 param[
i] = scalar_value;
579 if (!cp.
find(section, name, str)) {
580 fatal(
"Can't unserialize '%s:%s'\n", section, name);
590 std::string err(
"could not parse \"");
599 param.push_back(scalar_value);
609 if (!cp.
find(section, name, str)) {
610 fatal(
"Can't unserialize '%s:%s'\n", section, name);
620 std::string err(
"could not parse \"");
629 param.insert(scalar_value);
643 #define SERIALIZE_SCALAR(scalar) paramOut(cp, #scalar, scalar) 645 #define UNSERIALIZE_SCALAR(scalar) paramIn(cp, #scalar, scalar) 646 #define UNSERIALIZE_OPT_SCALAR(scalar) optParamIn(cp, #scalar, scalar) 649 #define SERIALIZE_ENUM(scalar) paramOut(cp, #scalar, (int)scalar) 651 #define UNSERIALIZE_ENUM(scalar) \ 654 paramIn(cp, #scalar, tmp); \ 655 scalar = static_cast<decltype(scalar)>(tmp); \ 658 #define SERIALIZE_ARRAY(member, size) \ 659 arrayParamOut(cp, #member, member, size) 661 #define UNSERIALIZE_ARRAY(member, size) \ 662 arrayParamIn(cp, #member, member, size) 664 #define SERIALIZE_CONTAINER(member) \ 665 arrayParamOut(cp, #member, member) 667 #define UNSERIALIZE_CONTAINER(member) \ 668 arrayParamIn(cp, #member, member) 670 #define SERIALIZE_EVENT(event) event.serializeSection(cp, #event); 672 #define UNSERIALIZE_EVENT(event) \ 674 event.unserializeSection(cp, #event); \ 675 eventQueue()->checkpointReschedule(&event); \ 678 #define SERIALIZE_OBJ(obj) obj.serializeSection(cp, #obj) 679 #define UNSERIALIZE_OBJ(obj) obj.unserializeSection(cp, #obj) 681 #define SERIALIZE_OBJPTR(objptr) paramOut(cp, #objptr, (objptr)->name()) 683 #define UNSERIALIZE_OBJPTR(objptr) \ 686 objParamIn(cp, #objptr, sptr); \ 687 objptr = dynamic_cast<decltype(objptr)>(sptr); \ 690 #endif // __SERIALIZE_HH__
void showParam(CheckpointOut &os, const T &value)
bool to_bool(const std::string &value, bool &retval)
Turn a string representation of a boolean into a boolean value.
#define fatal(...)
This implements a cprintf based fatal() function.
const std::string & name()
static std::stack< std::string > path
SimObjectResolver & objNameResolver
static std::string currentDirectory
bool parseParam(const std::string &s, T &value)
Base class to wrap object resolving functionality.
ScopedCheckpointSection(CP &cp, const std::string &name)
void serializeSection(CheckpointOut &cp, const std::string &name) const
void unserializeSection(CheckpointIn &cp, const std::string &name)
bool find(const std::string §ion, const std::string &entry, std::string &value)
void paramOut(CheckpointOut &os, const std::string &name, const T ¶m)
void debug_serialize(const std::string &cpt_dir)
void objParamIn(CheckpointIn &cp, const std::string &name, SimObject *¶m)
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
bool to_number(const std::string &value, VecPredRegContainer< NumBits, Packed > &p)
Helper functions used for serialization/de-serialization.
Basic support for object serialization.
std::ostream CheckpointOut
bool sectionExists(const std::string §ion)
typename BitfieldBackend::BitUnionBaseType< T >::Type BitUnionBaseType
static const std::string & currentSection()
Get the fully-qualified name of the active section.
void nameOut(CheckpointIn &cp)
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
bool entryExists(const std::string §ion, const std::string &entry)
void unserialize(ThreadContext &tc, CheckpointIn &cp)
bool findObj(const std::string §ion, const std::string &entry, SimObject *&value)
ScopedCheckpointSection(CP &cp, const char *name)
Scoped checkpoint section helper class.
bool optParamIn(CheckpointIn &cp, const std::string &name, T ¶m, bool warn=true)
Abstract superclass for simulation objects.
This class represents the contents of a ".ini" file.
static const char * baseFilename
CheckpointIn(const std::string &cpt_dir, SimObjectResolver &resolver)
void arrayParamOut(CheckpointOut &os, const std::string &name, const std::vector< T > ¶m)
void arrayParamIn(CheckpointIn &cp, const std::string &name, T *param, unsigned size)
Extract values stored in the checkpoint, and assign them to the provided array container.
void paramIn(CheckpointIn &cp, const std::string &name, T ¶m)
static std::string setDir(const std::string &base_name)