c++ - Handling unget and putback with file streams -


i have implemented std::basic_streambuf derived wrapper around std::basic_filebuf converts between encodings. within wrapper use single buffer both input , output. buffering technique comes this article.

now, problem can't figure out this. internal buffer filled on calls underflow. according article, when switching input output, buffer should put in state of limbo. this, need unget unread data in buffer. reading docs , source codes, unget , putback not guaranteed succeed. leave me invalid tellg pointer next input operation.

i'm not asking write me, asking advice how manage ungetting data std::basic_filebuf in way not fail.

i think, sure way calculate bytes written file , adjust offset accordingly. it's not simple sounds though. filebuf may have associated locale, unknown @ compile time. tried getting facet , passing data through it's out member, doesn't work. read data may have non default mbstate_t value, , codecvt objects write bom.

basically, it's impossible calculate 'on file' length of section of file data after has passed through codecvt.

i have tagged question 'c' since 'c'-file streams work buffers , use , put pointers. std::basic_filebuf wrapper around 'c'-file stream. answers in 'c' applicable problem.

does have suggestions how implement unlimited unget on file streams?


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -