From d981333e9443b721c172b0f7af077fa965c6ed14 Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Thu, 18 Oct 2018 21:36:35 +0800 Subject: [PATCH] add a base class for reader --- paddle/fluid/operators/reader/ctr_reader.cc | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/paddle/fluid/operators/reader/ctr_reader.cc b/paddle/fluid/operators/reader/ctr_reader.cc index 6c24a1ce7..da109733d 100644 --- a/paddle/fluid/operators/reader/ctr_reader.cc +++ b/paddle/fluid/operators/reader/ctr_reader.cc @@ -72,29 +72,29 @@ static inline void parse_line( } } -// class Reader { -// public: -// virtual ~Reader() {} -// virtual bool HasNext() = 0; -// virtual void NextLine(std::string& line) = 0; -//}; - -class GzipReader { +class Reader { + public: + virtual ~Reader() {} + virtual bool HasNext() = 0; + virtual void NextLine(std::string* line) = 0; +}; + +class GzipReader : public Reader { public: explicit GzipReader(const std::string& file_name) : gzstream_(file_name.c_str()) {} ~GzipReader() {} - bool HasNext() { return gzstream_.peek() != EOF; } + bool HasNext() override { return gzstream_.peek() != EOF; } - void NextLine(std::string* line) { std::getline(gzstream_, *line); } + void NextLine(std::string* line) override { std::getline(gzstream_, *line); } private: igzstream gzstream_; }; -class MultiGzipReader { +class MultiGzipReader : public Reader { public: explicit MultiGzipReader(const std::vector& file_list) { for (auto& file : file_list) { @@ -102,7 +102,7 @@ class MultiGzipReader { } } - bool HasNext() { + bool HasNext() override { if (current_reader_index_ >= readers_.size()) { return false; } @@ -113,7 +113,7 @@ class MultiGzipReader { return true; } - void NextLine(std::string* line) { + void NextLine(std::string* line) override { readers_[current_reader_index_]->NextLine(line); } @@ -151,6 +151,7 @@ void CTRReader::ReadThread(const std::vector& file_list, for (auto& slots_to_data : batch_data) { std::vector lod_data{0}; std::vector batch_feasign; + std::vector batch_label; auto& feasign = slots_to_data[slot]; -- GitLab