Topic: basic_filebuf question


Author: Martin Sebor <sebor@roguewave.com>
Date: Tue, 27 Mar 2001 18:37:51 CST
Raw View
Kiril Avdeiv wrote:
>
> Hi everybody!
>
> I'm writing a sort of parser, and would like to do replacement of certain character sequences in underflow. I have derived a class from std::filebuf, called parsing_filebuf. And in the parsing_filebuf::underflow I first call filebuf::underflow to do the actual work and set gptr(), egptr(), and eback(). In case everything goes well, I then call an algorithm that does the replacement. The replacement is always done in such a way that the resulting sequence is shorter than the one that filebuf_underflow returned in [eback(), egptr()). So, at the end of my overrider, I myself shorten the pending sequence by modifying the end pointer egptr() with a call to streambuf::setg.
>
> I find the above approach pretty elegant, and it's been working for me. I only wonder how portable what I'm doing is according to the standard.
>
> The implementation that I've looked at RogueWave does seem to be gratious enough to allow for such a technique to work.
>
> Would be helpful to any constructive recommendation or advice.

This approach should work, although for sequence conversion I would recommend
writing your own codecvt-derived facet. Doing so is considerably less involved
than implementing your own {over,under}flow() and will let you use it with any
stream or stream buffer object.

Regards
Martin

>
> With best regards.
> Kiril.
>
> --
> Posted from [213.17.94.30] by way of mx5.port.ru [194.67.23.40]
> via Mailgate.ORG Server - http://www.Mailgate.ORG
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: kavdeiv@mail.ru ("Kiril Avdeiv")
Date: Wed, 21 Mar 2001 22:10:42 GMT
Raw View
Hi everybody!

I'm writing a sort of parser, and would like to do replacement of certain character sequences in underflow. I have derived a class from std::filebuf, called parsing_filebuf. And in the parsing_filebuf::underflow I first call filebuf::underflow to do the actual work and set gptr(), egptr(), and eback(). In case everything goes well, I then call an algorithm that does the replacement. The replacement is always done in such a way that the resulting sequence is shorter than the one that filebuf_underflow returned in [eback(), egptr()). So, at the end of my overrider, I myself shorten the pending sequence by modifying the end pointer egptr() with a call to streambuf::setg.

I find the above approach pretty elegant, and it's been working for me. I only wonder how portable what I'm doing is according to the standard.

The implementation that I've looked at RogueWave does seem to be gratious enough to allow for such a technique to work.

Would be helpful to any constructive recommendation or advice.

With best regards.
Kiril.

--
Posted from [213.17.94.30] by way of mx5.port.ru [194.67.23.40]
via Mailgate.ORG Server - http://www.Mailgate.ORG

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]