sim: Replace fromInt/fromSimObject with decltype
This commit is contained in:
parent
db465fd788
commit
4411c97ee1
1 changed files with 11 additions and 23 deletions
|
@ -136,18 +136,6 @@ void arrayParamIn(CheckpointIn &cp, const std::string &name,
|
||||||
void
|
void
|
||||||
objParamIn(CheckpointIn &cp, const std::string &name, SimObject * ¶m);
|
objParamIn(CheckpointIn &cp, const std::string &name, SimObject * ¶m);
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void fromInt(T &t, int i)
|
|
||||||
{
|
|
||||||
t = (T)i;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void fromSimObject(T &t, SimObject *s)
|
|
||||||
{
|
|
||||||
t = dynamic_cast<T>(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// These macros are streamlined to use in serialize/unserialize
|
// These macros are streamlined to use in serialize/unserialize
|
||||||
// functions. It's assumed that serialize() has a parameter 'os' for
|
// functions. It's assumed that serialize() has a parameter 'os' for
|
||||||
|
@ -160,12 +148,12 @@ void fromSimObject(T &t, SimObject *s)
|
||||||
// ENUMs are like SCALARs, but we cast them to ints on the way out
|
// ENUMs are like SCALARs, but we cast them to ints on the way out
|
||||||
#define SERIALIZE_ENUM(scalar) paramOut(cp, #scalar, (int)scalar)
|
#define SERIALIZE_ENUM(scalar) paramOut(cp, #scalar, (int)scalar)
|
||||||
|
|
||||||
#define UNSERIALIZE_ENUM(scalar) \
|
#define UNSERIALIZE_ENUM(scalar) \
|
||||||
do { \
|
do { \
|
||||||
int tmp; \
|
int tmp; \
|
||||||
paramIn(cp, #scalar, tmp); \
|
paramIn(cp, #scalar, tmp); \
|
||||||
fromInt(scalar, tmp); \
|
scalar = static_cast<decltype(scalar)>(tmp); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define SERIALIZE_ARRAY(member, size) \
|
#define SERIALIZE_ARRAY(member, size) \
|
||||||
arrayParamOut(cp, #member, member, size)
|
arrayParamOut(cp, #member, member, size)
|
||||||
|
@ -193,11 +181,11 @@ void fromSimObject(T &t, SimObject *s)
|
||||||
#define SERIALIZE_OBJPTR(objptr) paramOut(cp, #objptr, (objptr)->name())
|
#define SERIALIZE_OBJPTR(objptr) paramOut(cp, #objptr, (objptr)->name())
|
||||||
|
|
||||||
#define UNSERIALIZE_OBJPTR(objptr) \
|
#define UNSERIALIZE_OBJPTR(objptr) \
|
||||||
do { \
|
do { \
|
||||||
SimObject *sptr; \
|
SimObject *sptr; \
|
||||||
objParamIn(cp, #objptr, sptr); \
|
objParamIn(cp, #objptr, sptr); \
|
||||||
fromSimObject(objptr, sptr); \
|
objptr = dynamic_cast<decltype(objptr)>(sptr); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic support for object serialization.
|
* Basic support for object serialization.
|
||||||
|
|
Loading…
Reference in a new issue