Boost logo

Boost Users :

From: Eyal Susser (eyal.susser_at_[hidden])
Date: 2005-05-08 04:50:40


   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
        CrIPCStreamOutput(RU8 * pio_pInputStorage , RS32 & pio_nStorageLen) :


        virtual ~CrIPCStreamOutput()

        void write(const char * s , std::streamsize n)
                        m_nBufferLen = -1;


                memcpy(m_pBuffer , s , n);

                m_nBufferLen = n;


        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?


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at