c++11 - Custom C++ stream for custom type -
i've read custom streams c++ seems people inherit std::streambuf
, std::istream
, , std::ostream
. inspecting type's declarations becomes clear these meant characters:
typedef basic_streambuf<char> streambuf;
the docs confirm this:
input stream objects can read , interpret input sequences of characters.
obviously, makes sense. i'm wondering correct way of implementing stream other types. not want allow text other forms of binary input/output (i have specific formats). obvious step seems to inherit basic
variants of above (basic_streambuf
, basic_istream
, , basic_ostream
) , use whatever type see fit template parameter. failed find confirmation right procedure. so, it?
edit clarification: have class called segment. these streams send/receive segments , segments on wifi connection these used in communication protocol. sending else break protocol. means stream cannot support other types.
this not answer question in terms of inheriting std::basic_*
non-char
types. following comments , given application, questioning need reimplement whole standard stream machinery segment
type, when can define class stream operator:
class segmentstream { public: segmentstream& operator<< ( const segment& s ); }
better yet clarify code defining methods send
, recv
instead of >>, <<
. or perhaps explain why not sufficient , why want use standard streams?
Comments
Post a Comment