From 4411c97ee186e0bc6e1c65a91b24e81ea246be70 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Tue, 1 Sep 2015 13:40:25 +0100 Subject: [PATCH] sim: Replace fromInt/fromSimObject with decltype --- src/sim/serialize.hh | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index 356547881..374e1a4d7 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -136,18 +136,6 @@ void arrayParamIn(CheckpointIn &cp, const std::string &name, void objParamIn(CheckpointIn &cp, const std::string &name, SimObject * ¶m); -template -void fromInt(T &t, int i) -{ - t = (T)i; -} - -template -void fromSimObject(T &t, SimObject *s) -{ - t = dynamic_cast(s); -} - // // These macros are streamlined to use in serialize/unserialize // 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 #define SERIALIZE_ENUM(scalar) paramOut(cp, #scalar, (int)scalar) -#define UNSERIALIZE_ENUM(scalar) \ - do { \ - int tmp; \ - paramIn(cp, #scalar, tmp); \ - fromInt(scalar, tmp); \ - } while (0) +#define UNSERIALIZE_ENUM(scalar) \ + do { \ + int tmp; \ + paramIn(cp, #scalar, tmp); \ + scalar = static_cast(tmp); \ + } while (0) #define SERIALIZE_ARRAY(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 UNSERIALIZE_OBJPTR(objptr) \ - do { \ - SimObject *sptr; \ - objParamIn(cp, #objptr, sptr); \ - fromSimObject(objptr, sptr); \ - } while (0) + do { \ + SimObject *sptr; \ + objParamIn(cp, #objptr, sptr); \ + objptr = dynamic_cast(sptr); \ + } while (0) /** * Basic support for object serialization. -- 2.30.2