45 #ifndef __SERIALIZE_HH__ 46 #define __SERIALIZE_HH__ 87 bool find(
const std::string §ion,
const std::string &entry,
90 bool findObj(
const std::string §ion,
const std::string &entry,
93 bool entryExists(
const std::string §ion,
const std::string &entry);
118 static std::string
setDir(
const std::string &base_name);
130 static std::string
dir();
200 pushName(name.c_str());
215 void pushName(
const char *
name);
268 serializeSection(cp, name.c_str());
283 void unserializeSection(
CheckpointIn &cp,
const char *name);
289 unserializeSection(cp, name.c_str());
297 static const std::string ¤tSection();
302 static void serializeAll(
const std::string &cpt_dir);
310 static std::stack<std::string>
path;
361 os << ((
sizeof(storage) == 1) ?
362 static_cast<unsigned int>(storage) : storage);
393 os << (
unsigned int)value;
434 os << (value ?
"true" :
"false");
471 fatal(
"Can't unserialize '%s:%s'\n", section, name);
481 T ¶m,
bool warn =
true)
487 warn(
"optional parameter %s:%s not present\n", section, name);
524 if (param.size() > 0)
527 while (it != param.end()) {
541 const std::set<T> ¶m)
543 typename std::set<T>::const_iterator it = param.begin();
546 if (param.size() > 0)
549 while (it != param.end()) {
563 const T *param,
unsigned size)
568 for (
unsigned i = 1;
i < size; ++
i) {
589 T *param,
unsigned size)
593 if (!cp.
find(section, name, str)) {
594 fatal(
"Can't unserialize '%s:%s'\n", section, name);
608 "Array size mismatch on %s:%s (Got %u, expected %u)'\n",
609 section,
name, tokens.size(), size);
618 std::string err(
"could not parse \"");
627 param[
i] = scalar_value;
640 if (!cp.
find(section, name, str)) {
641 fatal(
"Can't unserialize '%s:%s'\n", section, name);
654 param.resize(tokens.size());
663 std::string err(
"could not parse \"");
672 param[
i] = scalar_value;
685 if (!cp.
find(section, name, str)) {
686 fatal(
"Can't unserialize '%s:%s'\n", section, name);
696 std::string err(
"could not parse \"");
705 param.push_back(scalar_value);
718 if (!cp.
find(section, name, str)) {
719 fatal(
"Can't unserialize '%s:%s'\n", section, name);
729 std::string err(
"could not parse \"");
738 param.insert(scalar_value);
763 #define SERIALIZE_SCALAR(scalar) paramOut(cp, #scalar, scalar) 770 #define UNSERIALIZE_SCALAR(scalar) paramIn(cp, #scalar, scalar) 777 #define UNSERIALIZE_OPT_SCALAR(scalar) optParamIn(cp, #scalar, scalar) 786 #define SERIALIZE_ENUM(scalar) paramOut(cp, #scalar, (int)scalar) 793 #define UNSERIALIZE_ENUM(scalar) \ 796 paramIn(cp, #scalar, tmp); \ 797 scalar = static_cast<decltype(scalar)>(tmp); \ 805 #define SERIALIZE_ARRAY(member, size) \ 806 arrayParamOut(cp, #member, member, size) 813 #define UNSERIALIZE_ARRAY(member, size) \ 814 arrayParamIn(cp, #member, member, size) 821 #define SERIALIZE_CONTAINER(member) \ 822 arrayParamOut(cp, #member, member) 829 #define UNSERIALIZE_CONTAINER(member) \ 830 arrayParamIn(cp, #member, member) 837 #define SERIALIZE_EVENT(event) event.serializeSection(cp, #event); 844 #define UNSERIALIZE_EVENT(event) \ 846 event.unserializeSection(cp, #event); \ 847 eventQueue()->checkpointReschedule(&event); \ 855 #define SERIALIZE_OBJ(obj) obj.serializeSection(cp, #obj) 862 #define UNSERIALIZE_OBJ(obj) obj.unserializeSection(cp, #obj) 869 #define SERIALIZE_OBJPTR(objptr) paramOut(cp, #objptr, (objptr)->name()) 876 #define UNSERIALIZE_OBJPTR(objptr) \ 879 objParamIn(cp, #objptr, sptr); \ 880 objptr = dynamic_cast<decltype(objptr)>(sptr); \ 883 #endif // __SERIALIZE_HH__
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()
bool sectionExists(const std::string §ion)
static std::stack< std::string > path
void arrayParamOut(CheckpointOut &os, const std::string &name, const std::vector< T > ¶m)
SimObjectResolver & objNameResolver
static std::string currentDirectory
bool findObj(const std::string §ion, const std::string &entry, SimObject *&value)
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.
static std::string setDir(const std::string &base_name)
Set the current directory.
void paramIn(CheckpointIn &cp, const std::string &name, T ¶m)
void unserializeSection(CheckpointIn &cp, const std::string &name)
Base class to wrap object resolving functionality.
ScopedCheckpointSection(CP &cp, const std::string &name)
bool find(const std::string §ion, const std::string &entry, std::string &value)
const std::string _cptDir
void showParam(CheckpointOut &os, const T &value)
bool optParamIn(CheckpointIn &cp, const std::string &name, T ¶m, bool warn=true)
void debug_serialize(const std::string &cpt_dir)
bool parseParam(const std::string &s, T &value)
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.
ScopedCheckpointSection(CP &cp, const char *name)
static std::string dir()
Get the current checkout directory name.
std::ostream CheckpointOut
const std::string getCptDir()
typename BitfieldBackend::BitUnionBaseType< T >::Type BitUnionBaseType
static const std::string & currentSection()
Gets the fully-qualified name of the active section.
bool entryExists(const std::string §ion, const std::string &entry)
void nameOut(CheckpointIn &cp)
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
void unserialize(ThreadContext &tc, CheckpointIn &cp)
void serializeSection(CheckpointOut &cp, const std::string &name) const
Scoped checkpoint section helper class.
void objParamIn(CheckpointIn &cp, const std::string &name, SimObject *¶m)
Abstract superclass for simulation objects.
This class represents the contents of a ".ini" file.
static const char * baseFilename
void paramOut(CheckpointOut &os, const std::string &name, const T ¶m)
CheckpointIn(const std::string &cpt_dir, SimObjectResolver &resolver)