Page 1 of 1
Serialize boost::shared_ptr<T const> and C++11 enum classes
Posted: Mon Nov 11, 2013 4:29 pm
by Volker
Hi Jarl,
we have problems serializing the types mentioned above via SF. The interface including the shared pointer looks like the following :
Code: Select all
RCF_BEGIN(I_ManagerMaster, "I_ManagerMaster")
RCF_METHOD_R2(
ManagerInfo,
registerManager,
std::string const &,
std::vector<boost::shared_ptr<Report const> > const &)
RCF_END(I_ManagerMaster)
After removing the const-declaration for the class
Report the serialization works.
Regards,
Volker
Re: Serialize boost::shared_ptr<T const> and C++11 enum clas
Posted: Wed Nov 13, 2013 10:31 am
by jarl
For serialization of shared_ptr<const T>, if you open RCF\include\SF\SerializeSmartPtr.hpp, and change this line:
Code: Select all
if (pt && ctx.getEnabled() && ctx.query( pt, typeid(SmartPtrT), pv ))
, to
Code: Select all
if (pt && ctx.getEnabled() && ctx.query( (void *) pt, typeid(SmartPtrT), pv ))
, and this line:
Code: Select all
ctx.add( pt, typeid(SmartPtrT), *ppt );
to
Code: Select all
ctx.add( (void *) pt, typeid(SmartPtrT), *ppt );
, it should work. These changes will be in the next release.
To serialize C++11 enum classes - for now, you'll need to write a simple serialization function for each enum:
Code: Select all
template<typename T, typename U>
inline void serializeAs(SF::Archive & ar, T &t)
{
if (ar.isWrite())
{
U u = static_cast<U>(t);
ar & u;
}
else
{
U u;
ar & u;
t = static_cast<T>(u);
}
}
enum class DayOfWeek : short { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
void serialize(SF::Archive & ar, DayOfWeek & d)
{
serializeAs<DayOfWeek, short>(ar, d);
}
Re: Serialize boost::shared_ptr<T const> and C++11 enum clas
Posted: Wed Nov 13, 2013 5:40 pm
by Volker
Perfect !
I will prepare a patch for our library deployment until the new version comes out.
Regards,
Volker
Re: Serialize boost::shared_ptr<T const> and C++11 enum clas
Posted: Fri Apr 25, 2014 2:33 pm
by jarl
If you download the latest RCF release, these issues are both fixed.