Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does STL "rdbuf" method name stand for?

Tags:

c++

stl

The user who asked the following question accepted "read buffer" pretty fast: What does rd stand for in rdstate and rdbuf?

I still wonder what "read buffer" would mean in the context of "std::ostream" (cout). I did not find ANY STL documentation describing this function as doing any "reading". Is that just a misnamed function? (...apparently, but maybe I am missing something)

like image 611
Maestro Avatar asked Sep 24 '15 20:09

Maestro


2 Answers

I still wonder what "read buffer" would mean in the context of "std::ostream" (cout).

It's "read" as in "read the value of" or "get the value of" not read as in "read from the stream".

It seems to be a common convention in the old Cfront code, e.g. see the Task library described in the Cfront 2.0 documentation which has several functions named like that, e.g. on page 2-5:

int    rdcount();
int    rdmode();
int    rdmax();
void   setmode(int);
void   setmax(int);

So "rd" and "set" seem to be used for names of getters and setters respectively.

That means the overload of rdbuf(basic_streambuf<C,T>*) that replaces the streambuf is misnamed, it should be setbuf, but that name is already used by the streambuf itself with a different meaning. That rdbuf "setter" overload was added later, the original design only had the "getter", as shown in the STRSTREAM(3C++) manual page at the end of the PDF linked to above:

class strstream : public strstreambase,  public iostream {
public:
                                 strstream();
                                 strstream(char*, int, int mode);
                 strstreambuf*   rdbuf() ;
                 char*           str();
};
like image 143
Jonathan Wakely Avatar answered Nov 16 '22 22:11

Jonathan Wakely


Raw Device/Data Buffer (rdbuf) <---- I prefer @Daniel Jour's comments.

input_stream is associated with a stream_buffer which is often instantiated by string_buffer or file_buffer.

like: explicit basic_istream( std::basic_streambuf* sb); reference:

https://en.cppreference.com/w/cpp/io/basic_istream/basic_istream

class basic_streambuf is an Abstraction of Raw Device. that means it may socket, file, namedpipe, mailslot, memory, graphycard-mem. so from high level, how to name the different devices?

I think both RD(raw device) and raw data are ok, but raw device more accurate, even 99.999% times it points to a memory.

like image 30
Osmond Ye Avatar answered Nov 16 '22 20:11

Osmond Ye