Re: [Boost-users] Question about ifstream ranges
boost-users-bounces@lists.boost.org wrote:
Hello all!
I face the problem of partitioning a file that i read with ifstream into portions that are to be processed by some clients. I want to ensure that a client only views a specific
Pfligersdorffer, Christian wrote: part (window, range) of the stream. So far I store 2 streamoffsets posStart and posEnd, call seekg on the stream, pass it to the client by ref and rely on the client to check when it reached posEnd.
However, I certainly cannot copy the whole range into a new
stream object and pass that one. Efficiency does matter.
Any suggestions? Maybe some iterator-magic can be done?
How about Boost.Spirit file_iterator? That is a read-only RandomAccessIterator for files. http://spirit.sourceforge.net/distrib/spirit_1_8_3/libs/spirit /doc/file_iterator.html
Hello Shunsuke, that's a good idea but unfortunately I cannot use this class in my case. I have some special decoding ifstreams doing decompression and the like. So I'd really need an iterator that takes an i(f)stream object in it's constructor and wraps that. Thanks anyway! -- Christian Pfligersdorffer Dipl.-Ing. Bakk.rer.nat. Software Engineering EOS GmbH - Electro Optical Systems Robert-Stirling-Ring 1 D-82152 Krailling / Munich Phone +49 89 893 36-229 Fax +49 89 893 36-287 christian.pfligersdorffer@eos.info http://www.eos.info
Pfligersdorffer, Christian wrote:
Any suggestions? Maybe some iterator-magic can be done? How about Boost.Spirit file_iterator? That is a read-only RandomAccessIterator for files. http://spirit.sourceforge.net/distrib/spirit_1_8_3/libs/spirit /doc/file_iterator.html
Hello Shunsuke,
that's a good idea but unfortunately I cannot use this class in my case. I have some special decoding ifstreams doing decompression and the like. So I'd really need an iterator that takes an i(f)stream object in it's constructor and wraps that.
C++ has istream_iterator, but it seems useless in this case. In fact, istream_iterator can be converted into ForwardIterator using Boost.Spirit multi_pass iterator. http://spirit.sourceforge.net/distrib/spirit_1_8_3/libs/spirit/doc/multi_pas... Thus you can make portions before passing them to clients. But unfortunately multi_pass iterator may copy the whole range in many cases. Regards, -- Shunsuke Sogame
You can wrap the ifstream iterator by one of the boost::iterator lib iterators. http://www.boost.org/libs/iterator/doc/index.html For example transform iterator can first apply some some function to a chunk or sequence (e.g. see if it is at the end of a chunk and read a new one if required) and return an element pointed to. With Kind Regards, Ovanes Markarian On Thu, March 8, 2007 10:46, shunsuke wrote:
Pfligersdorffer, Christian wrote:
Any suggestions? Maybe some iterator-magic can be done? How about Boost.Spirit file_iterator? That is a read-only RandomAccessIterator for files. http://spirit.sourceforge.net/distrib/spirit_1_8_3/libs/spirit /doc/file_iterator.html
Hello Shunsuke,
that's a good idea but unfortunately I cannot use this class in my case. I have some special decoding ifstreams doing decompression and the like. So I'd really need an iterator that takes an i(f)stream object in it's constructor and wraps that.
C++ has istream_iterator, but it seems useless in this case. In fact, istream_iterator can be converted into ForwardIterator using Boost.Spirit multi_pass iterator. http://spirit.sourceforge.net/distrib/spirit_1_8_3/libs/spirit/doc/multi_pas... Thus you can make portions before passing them to clients. But unfortunately multi_pass iterator may copy the whole range in many cases.
Regards,
-- Shunsuke Sogame
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Pfligersdorffer, Christian wrote:
boost-users-bounces@lists.boost.org wrote:
Pfligersdorffer, Christian wrote:
Hello all!
I face the problem of partitioning a file that i read with
ifstream into portions that are to be processed by some clients. I want to ensure that a client only views a specific part (window, range) of the stream. So far I store 2 streamoffsets posStart and posEnd, call seekg on the stream, pass it to the client by ref and rely on the client to check when it reached posEnd.
However, I certainly cannot copy the whole range into a new
stream object and pass that one. Efficiency does matter.
Any suggestions? Maybe some iterator-magic can be done?
How about Boost.Spirit file_iterator? That is a read-only RandomAccessIterator for files. http://spirit.sourceforge.net/distrib/spirit_1_8_3/libs/spirit /doc/file_iterator.html
Hello Shunsuke,
that's a good idea but unfortunately I cannot use this class in my case. I have some special decoding ifstreams doing decompression and the like. So I'd really need an iterator that takes an i(f)stream object in it's constructor and wraps that.
Thanks anyway!
How about an iostreams restriction? http://boost.org/libs/iostreams/doc/functions/restrict.html I'm using it to pull data out of a zip file and zlib_decompressor to decompress it. :-) Also, http://www.teslacore.it/wiki/index.php?title=BoostPicks#Restriction has some sample code. Hope this helps! Phillip
participants (4)
-
Ovanes Markarian
-
Pfligersdorffer, Christian
-
Phillip Seaver
-
shunsuke