Boost logo

Boost :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2005-08-02 08:32:37


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;
   }
};

}
}
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk