IOStream - expose MemoryInputStream buffer and it's size
Hy, I want to implement a boost iostream MemoryInputStream like this: class MemoryInputDevice : public boost::iostreams::source { public: MemoryInputDevice(char* buffer, size_t size): buffer(buffer), size(size), pos(0) { } std::streamsize read(char* s, std::streamsize n); private: char* buffer; std::streamsize size; std::streamsize pos; }; typedef boost::iostreams::stream<MemoryInputDevice> MemoryInputStream; I want at the same time to expose to clients beside the istream interface a way for the client to get the pointer to the internal buffer and it's length (getting the pointer to the internal buffer could be questionable but in order not to copy buffer around there are cases where a parser of mine needs all the content of the internal buffer and I don't want to copy that around before passing it to the parser) Is therea way for MemoryInputStream user to get that info ? I was thinking at the stream->rdbuffer() method but it seems it does not give me what I want. Thanks in advance for your help -Ghita
For device type D, boost::iostreams::stream<D> defines D& operator*() and
D* operator->()
Clients of your stream can use them to access the buffer
2012/10/16 Gheorghe Marinca
Hy,
I want to implement a boost iostream MemoryInputStream like this:
class MemoryInputDevice : public boost::iostreams::source { public: MemoryInputDevice(char* buffer, size_t size): buffer(buffer), size(size), pos(0) { }
std::streamsize read(char* s, std::streamsize n);
private: char* buffer; std::streamsize size; std::streamsize pos; };
typedef boost::iostreams::stream<MemoryInputDevice> MemoryInputStream;
I want at the same time to expose to clients beside the istream interface a way for the client to get the pointer to the internal buffer and it's length (getting the pointer to the internal buffer could be questionable but in order not to copy buffer around there are cases where a parser of mine needs all the content of the internal buffer and I don't want to copy that around before passing it to the parser)
Is therea way for MemoryInputStream user to get that info ? I was thinking at the stream->rdbuffer() method but it seems it does not give me what I want. Thanks in advance for your help
-Ghita
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Gheorghe Marinca
-
Piotr Kowalski