Serialize boost::shared_ptr<T const> and C++11 enum classes

RCF support and general discussion.
Post Reply
Volker
Posts: 26
Joined: Wed May 23, 2012 3:27 pm

Serialize boost::shared_ptr<T const> and C++11 enum classes

Post 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

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: Serialize boost::shared_ptr<T const> and C++11 enum clas

Post 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);
}
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

Volker
Posts: 26
Joined: Wed May 23, 2012 3:27 pm

Re: Serialize boost::shared_ptr<T const> and C++11 enum clas

Post by Volker »

Perfect !

I will prepare a patch for our library deployment until the new version comes out.

Regards,

Volker

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: Serialize boost::shared_ptr<T const> and C++11 enum clas

Post by jarl »

If you download the latest RCF release, these issues are both fixed.
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

Post Reply