IStreamOut
本クラスは namespace TWE
内に定義されています。
出力ストリームの基底クラスで、以下のメソッドが定義されており、1バイトの出力、改行文字など特殊クラスを受け付けるためのメソッドが定義されています。
virtual inline IStreamOut& operator ()(char_t c) = 0
virtual inline IStreamOut& write_w(wchar_t c)
operator ()
はchar_t
型の1文字を出力するための仮想関数です。write_w()
はwchar_t
型の出力に対応します。
ストリームへの出力は<<
演算子を用います。最終的には上記の出力用の関数が呼び出されます。
以下の例はITermクラスでの実装例です。
class ITerm : public TWE::IStreamOut {
// ... 各種定義
ITerm& write(char_t c) {
// ... 1バイト入力を受け付ける処理
}
// StreamOut::operator () の実装
TWE::IStreamOut& operator ()(char_t c) {
write(c);
return *this;
}
};
operator <<
inline IStreamOut& operator << (char_t c)
inline IStreamOut& operator << (wchar_t c)
inline IStreamOut& operator << (IStreamSpecial& sc)
operator << の右オペランドとして以下の型に対応します。
右オペランドの型
解説
char_t
1バイト出力する
const char *
文字列を出力する
wchar_t
ワイド文字を出力する(派生クラスで対応がある場合)
IStreamSpecial&
特殊文字列を出力する
printfmt
printf()に相当する出力を行う
const int
printf("%d", n)に相当する出力を行う
double
printf("%.3%, n)に相当する出力を行う
IStreamSpecial
特殊な文字列などを指定するためのオブジェクトを定義するための基底クラスです。
class IStreamSpecial {
public:
virtual inline IStreamOut& operator ()(IStreamOut& of) = 0;
};
派生クラスとして CR LF (0x0d 0x0a) を出力する IStream_endl が定義されています。
class IStream_endl : public IStreamSpecial {
inline IStreamOut& operator ()(IStreamOut& of) {
// ... CR LF の出力
of ('\r');
of ('\n');
}
};
IStream_endl crlf;
オブジェクトcrlf
は以下のように使用します。
the_screen << "Hello World!" << crlf;
最終更新