0

I am working on an application the will need to sequentially encode/decode a series of bytes, and put them to a stream once they have been processed.

My plan was to subclass ostream and provide a constructor MyEncodeStream(istream) using istream.

I must admit though I am at a loss as to what to do next, which methods should be overridden? What is the standard facility for doing this.

Please provide example code for a this simple case:

  1. A char is pulled from the input buffer
  2. The char is manipulated by char manipulationFunc(char in)
  3. The char is put to a buffer
  4. MyEncodeStream stops blocking so the char can be read
  5. Does ostream provide a read function that should be overridden which operator << calls, or is operator<< the function that should be overridden?
BenMorel
  • 34,448
  • 50
  • 182
  • 322
awiebe
  • 3,758
  • 4
  • 22
  • 33
  • I am aware of http://stackoverflow.com/questions/4482116/inherit-stdostream I have googled, I just couldn't get a straight answer. – awiebe Mar 24 '13 at 04:20
  • With regards to 5, I think you mean `operator <<`, and that is implementation defined (differs per compiler). – Tushar Mar 24 '13 at 04:22
  • 1
    It isn't clear why you need anything special like that. It seems like you could just read the character from an istream, call the function, then write the result to an ostream. – Vaughn Cato Mar 24 '13 at 04:23
  • I am writing a class that encapsulates the encoding process, provides an input facility and provides an output stream for someone else to read at their leisure. – awiebe Mar 24 '13 at 04:25
  • Indeed you are mixing up your functionality, you want an encode/decode class(s), then you should be able to use the normal I/O streams to read/write your encoded/decoded data. – Chris Desjardins Mar 24 '13 at 04:32
  • 2
    Very related question [How to write custom input stream in C++?](http://stackoverflow.com/questions/14086417/how-to-write-custom-input-stream-in-c?rq=1) – Bo Persson Mar 24 '13 at 04:41
  • Why not just write your encoding/decoding as a Filter for [boost.iostreams](http://www.boost.org/doc/libs/release/libs/iostreams/doc/index.html)? – Cubbi Dec 02 '13 at 15:45

1 Answers1

-1

I figured it out, I was confused. What I wanted to do was to subclass an input stream with an input stream as an argument for the constructor, that way when the custom input stream is read it can read from the standard input mechanism. I was looking up subclassing output streams, which is why google wasn't turning up many results.

awiebe
  • 3,758
  • 4
  • 22
  • 33