Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » PROPOSAL: SerializeStore helper
PROPOSAL: SerializeStore helper [message #29413] Tue, 19 October 2010 12:05 Go to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
just a short add..

XmlizeStore exists, to be able to handle 'const T& x'
I couldnt find anything similar for Serialize..
here is a solution.

template<class T>
void SerializeStore(Stream& s, const T& x)
{
	ASSERT(s.IsStoring());
	s % const_cast<T&>(x);
}


this makes thing possible like
SerializeStore(s, mymap.GetKey(i));

without the hassle of a const_cast each time..and an ASSERT is there..

any better solution or didnt i think of every pitfall..
Re: PROPOSAL: SerializeStore helper [message #29422 is a reply to message #29413] Tue, 19 October 2010 15:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Tue, 19 October 2010 06:05

just a short add..

XmlizeStore exists, to be able to handle 'const T& x'
I couldnt find anything similar for Serialize..
here is a solution.

template<class T>
void SerializeStore(Stream& s, const T& x)
{
	ASSERT(s.IsStoring());
	s % const_cast<T&>(x);
}


this makes thing possible like
SerializeStore(s, mymap.GetKey(i));

without the hassle of a const_cast each time..and an ASSERT is there..

any better solution or didnt i think of every pitfall..



Well, the equivalent function is there, called "Store", but it now accepts only non-const parameter - so the change would be there...

The problem I possibly see with it (and in fact, maybe the XmlizeStore is wrong) is that you are giving option to client code to change const object... I mean, nothing prevents Serialize to mutate the object.

But perhaps I am wrong... Another opinion?
Re: PROPOSAL: SerializeStore helper [message #29426 is a reply to message #29422] Tue, 19 October 2010 15:47 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i think at a cetain point one needs to handle over control to tested and working code. there, trust begins Smile
otherwise, i wouldn't see the point of XmlizeStore as well.

also, to leave the user using const_cast at points he maybe doesn't really understand, 'just to make this damn thing compile', is probably more error prone.. it's to hide all that 'hacking' away from user.

just an opinion. you are to decide..
Previous Topic: no String::Replace() ?
Next Topic: PolyDeepCopyNew: MSC / GCC differ in behaviour
Goto Forum:
  


Current Time: Fri Apr 19 04:56:23 CEST 2024

Total time taken to generate the page: 0.02887 seconds