$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Eyal Susser (eyal.susser_at_[hidden])
Date: 2005-05-08 04:50:40
Hi,
   Boost is a really neat idea, I wish I had less trouble using it (so
embarrasing...).  Anyway, here's a streambuf class I wrote using
IOStream :
class CrIPCStreamOutput : public sink
{
public:
        CrIPCStreamOutput(RU8 * pio_pInputStorage , RS32 & pio_nStorageLen) :
                       m_pBuffer(pio_pInputStorage),
m_nBufferLen(pio_nStorageLen)
        {
        }
        virtual ~CrIPCStreamOutput()
        {
                
        }
        void write(const char * s , std::streamsize n)
        {
        if(!m_pBuffer)
                {
                        m_nBufferLen = -1;
                        return;
                }
                memcpy(m_pBuffer , s , n);
                m_nBufferLen = n;
        return;
        }
private:
        unsigned char *& m_pBuffer;
        int & m_nBufferLen;
};
In my main, I do:
int main()
{
        unsigned char p[256] = {0};
        int n = sizeof(p);
    streambuf_facade<CrIPCStreamOutput> sbo(CrIPCStreamOutput(p , n));
        //stream_facade<CrIPCStreamOutput> stro(CrIPCStreamOutput(p , n));
        iostream stro(&sbo);
        stro.write("Hello?" , 6);
        cout << p << endl;
        return 0;
}
But the ouput from cout is an empty string, although when debugging I
can see m_pBuffer being copied to.  How can I get this to work?  The
motivation for the whole thing is serialization:  I want to serialize
a class using the boos.serialization lib, for which I need a stream,
which has to have certain properties (not shown here).  I need to have
the archiver write to a specific buffer.  IOStreams should do it (I
got the reading side working fine), but how?
Thanks.