今度は書き込む方。BYTEとかの定義はReaderと同じと思ってください。
同じように抽象クラス。
class Writer { public: virtual ~Writer() {} void writeByte(BYTE value) { write(value); } void writeHalf(HALF value) { writeByte(static_cast<BYTE>(value >> BITS_PER_BYTE)); writeByte(static_cast<BYTE>(value)); } void writeWord(WORD value) { writeHalf(static_cast<HALF>(value >> BITS_PER_HALF)); writeHalf(static_cast<HALF>(value)); } protected: virtual void write(BYTE value) = 0; };
そんでもって具象クラス。
class ByteArrayWriter : public Writer { public: ByteArrayWriter(BYTE* values, int length) : itr_(values), end_(values + length) {} protected: void write(BYTE value) { if(itr_ < end_) { *itr_++ = value; } } private: BYTE* itr_; BYTE* end_; };