iostream は streambuf object の pointer を引数とする constructor があり、これにより streambuf と iostream が結びつけられる。 istream の公開インターフェイスは istream& operator>> を除いて explicit istream(streambuf* sb); virtual ~istream(); class sentry; streamsize gcount() const; int get(); istream& get(char& c); istream& get(char* s, streamsize n); istream& get(char* s, streamsize n, char delim); istream& get(streambuf& sb); istream& get(streambuf& sb, char delim); istream& getline(char* s, streamsize n); istream& getline(char* s, streamsize n, char delim); istream& ignore(streamsize n = 1, int delim = traits::eof()); int peek(); istream& read(char* s, streamsize n); streamsize readsome(char* s, streamsize n); istream& putback(char c); istream& unget(); int sync(); pos_type tellg(); istream& seekg(pos_type); istream& seekg(off_type, ios_base::seekdir); 同様に ostream について、ostream& operator<< を除いて explicit ostream(streambuf* sb); virtual ~ostream(); class sentry; ostream& put(char c); ostream& write(const char* s, streamsize n); ostream& flush(); pos_type tellp(); ostream& seekp(pos_type); ostream& seekp(off_type, ios_base::seekdir); このほか書式付き入出力に用いるものとして istream& ws(istream& is); ostream& endl(ostream& os); ostream& ends(ostream& os); ostream& flush(ostream& os); がある。iostream は istream と ostream の両方を継承しており、constructor と destructor 以外に独自の公開インターフェイスは持っていない。 入出力 stream 中では streambuf の pointer は単なるメンバーであり、 従って公開インターフェイスでアクセスされる(はず)。 つまり、公開インターフェイスを実装すればよい。 ここさえ直接実装すれば限定公開インターフェイスなどは 実装する必要はない(はず)。 streambuf の公開インターフェイスのうち、重要と思われるものは int pubsync(); streamsize in_avail(); int snextc(); int sbumpc(); int sgetc(); streamsize sgetn(char* s, streamsize n); int sputbackc(char c); int sungetc(); int sputc(char c); streamsize sputn(const char* s, streamsize n); 規約では
が呼ばれるだけである。 これらは引数、戻り値も含めて一致している。 更に規約によると
と等価である。 |