私は、rapidjson 0.1 (ios、xcode 6.1) で使用する gzstream 1.5 の単純なラッパーを作成しました。
問題: Peek() と Take() で eof をチェックする必要があります。それ以外の場合、最後の文字として '\377' (-1) を取得します。std::basic_stream::get() at eof によって返されることを私は知っています。
よりエレガントで適切でクリーンなソリューションは何ですか?
class GzOutStream {
public:
GzOutStream(std::string filename) : gs_(new ogzstream(filename.c_str())) {}
bool Good() { return gs_->good(); }
void Close() { delete gs_; gs_ = nullptr; }
size_t Tell() { return gs_->tellp(); }
void Put(char c) { gs_->put(c); }
// Not implemented
char* PutBegin() { return 0; }
size_t PutEnd(char*) { return 0; }
private:
ogzstream* gs_;
};
class GzInStream {
public:
GzInStream(std::string filename) : gs_(new igzstream(filename.c_str())) {}
bool Good() { return gs_->good(); }
void Close() { delete gs_; gs_ = nullptr; }
char Peek() { return gs_->eof()? '\0' : gs_->peek(); }
char Take() { return gs_->eof()? '\0' : gs_->get(); }
size_t Tell() { return gs_->tellg(); }
void Put(char c) { } // Stab
// Not implemented
char* PutBegin() { return 0; }
size_t PutEnd(char*) { return 0; }
private:
igzstream* gs_;
};