[1.33.0][iostreams][serialization]

I've spent the last several hours trying to update my project with 1.33.0.RC. The only changes were naming issues with iostreams, and the getting rid of the lovely :) asserts on serialization inclusions previous to archive inclusions. Also an issue with operator << and const_cast-ing appears below, and switching to the standard BOOST_SHARED_POINTER_EXPORT_GUID macro which now appears to handle pointers in namespaces properly. All compiles and links succesfully under VC7.1. Rudimentary xml serialization seems to save/load succesfully. I am having an problems when using iostreams/serialization together to support copy/paste/drag/drop under Windows MFC. Which all worked flawlessly using 1.32.0 along with pre-release iostreams. I'd appreciate it if anyone sees anything blatantly wrong with the code below. CSharedFileSink::write is not being called at all. This leads and assert in MFC's CSharedFile::Detach because the file has never been written to. The member CSafeDataSource::GlobalArchiveHdl instantiates a CSharedFileOStream and attempts to serialize it's mVal data member to a binary archive. Thanks in advance, Jeff namespace adi { namespace mfc { namespace clipboard { struct CSharedFileSink : public boost::iostreams::sink { CSharedFile& mSharedFile; CSharedFileSink( CSharedFile& aSharedFile ) : boost::iostreams::sink() , mSharedFile(aSharedFile) {} std::streamsize write( const char* s, std::streamsize n ) { mSharedFile.Write( s, n ); return n; } }; class CSharedFileOStream : private boost::base_from_member<CSharedFile> , public boost::iostreams::stream<CSharedFileSink> { typedef boost:: base_from_member<CSharedFile > tSharedFile; typedef boost::iostreams::stream<CSharedFileSink> tBase; public: CSharedFileOStream() : tSharedFile( GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT ) , tBase( CSharedFileSink( tSharedFile::member ) ) {} HGLOBAL Detach(){ return tSharedFile::member.Detach(); } }; template< class T > class CSafeDataSource : public COleDataSource { typedef T value_type; value_type mVal; HGLOBAL GlobalArchiveHdl() { CSharedFileOStream lOut; boost::archive::binary_oarchive oa( lOut ); // oa & mVal; // same result as below oa << const_cast<const value_type&>(mVal); //BOOST_1_33_0 return lOut.Detach(); } CSafeDataSource( const T& aVal ) : COleDataSource(),mVal(aVal){ DelayRenderData( NativeFormat() ); } friend void ToClipBoard<T>( const T& aVal ); friend void Drag<T>( const T& aVal , tDragImagePtr aDragImagePtr , DWORD aDropEffect ); public: static CLIPFORMAT NativeFormat(){ return RegisteredClipboardFormat<value_type>(); } virtual BOOL OnRenderGlobalData( LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal ) { if( lpFormatEtc->cfFormat == NativeFormat() ) { return (*phGlobal = GlobalArchiveHdl())? TRUE : FALSE; } return FALSE; } }; } } }

I can't see anything wrong with it. To see the problem I would have to have to trace into the << operartor down to iostreams. As an aside, is there a reason that
wouldn't be better replaced with: HGLOBAL GlobalArchiveHdl() const // this function doesn't modify its class variables { CSharedFileOStream lOut; boost::archive::binary_oarchive oa( lOut ); oa << mVal; return lOut.Detach(); } Robert Ramey

Robert, "Robert Ramey" <ramey@rrsd.com> wrote in message news:dco35o$gv4$1@sea.gmane.org...
I can't see anything wrong with it. To see the problem I would have to have to trace into the << operartor down to iostreams.
As stated in my other post, I had forgotten to flush the stream.
Uh, your right that is better. I've gotten past here, but I'm having problems with archive_exception::unregistered_class being thrown even though I'm calling BOOST_SHARED_POINTER_EXPORT_GUID when saving a set of shared_ptr's. I'll try to track down what's going on here. Jeff

Consider the following: I presume your going to be loading archives which which were saved with 1.32 a) so this means you should be including BOOST_..._132.hpp so that you can load the old archives. b) However, this will save new archives in the new format. The new format doesn't need the BOOST_SHARED_POINTER_EXPORT_GUID . However, the new format will require export of the underlying type - something that BOOST_SHARED_POINTER_EXPORT_GUID did as a side-effect. So, that might be a good place to look. Robert Ramey Jeff Flinn wrote:

"Robert Ramey" <ramey@rrsd.com> wrote in message news:dcob30$c8r$1@sea.gmane.org...
I'm lucky enough to not need to support 1.32 archives. I was aware of the shared_ptr_132.hpp issue from following the devel list.
Ok, I missed that there was no longer a need for BOOST_SHARED_POINTER_EXPORT_GUID in reading the changes section. Also I never #included boost/serialization/shared_ptr_132.hpp so I'm surprised that I didn't get a compiler error that BOOST_SHARED_POINTER_EXPORT_GUID was not defined. Most likely a VC7.1 oddity/bug. I changed to BOOST_SHARED_POINTER_EXPORT_GUID(along with a clean build) and lo-and-behold all works like a charm! In fact I've been able to clean up a lot of kluges required to work around VC7.1 ICE's. I previously had to separate more than 3 exports macro calls into multiple files. Compilation is also much faster. A very, very nice improvement in serialization, iostreams and all the rest of Boost! Congratulations and Thanks to all involved! Jeff
participants (2)
-
Jeff Flinn
-
Robert Ramey