Skip to content

Commit d981333

Browse files
committed
add a base class for reader
1 parent a06173e commit d981333

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

paddle/fluid/operators/reader/ctr_reader.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,37 +72,37 @@ static inline void parse_line(
7272
}
7373
}
7474

75-
// class Reader {
76-
// public:
77-
// virtual ~Reader() {}
78-
// virtual bool HasNext() = 0;
79-
// virtual void NextLine(std::string& line) = 0;
80-
//};
81-
82-
class GzipReader {
75+
class Reader {
76+
public:
77+
virtual ~Reader() {}
78+
virtual bool HasNext() = 0;
79+
virtual void NextLine(std::string* line) = 0;
80+
};
81+
82+
class GzipReader : public Reader {
8383
public:
8484
explicit GzipReader(const std::string& file_name)
8585
: gzstream_(file_name.c_str()) {}
8686

8787
~GzipReader() {}
8888

89-
bool HasNext() { return gzstream_.peek() != EOF; }
89+
bool HasNext() override { return gzstream_.peek() != EOF; }
9090

91-
void NextLine(std::string* line) { std::getline(gzstream_, *line); }
91+
void NextLine(std::string* line) override { std::getline(gzstream_, *line); }
9292

9393
private:
9494
igzstream gzstream_;
9595
};
9696

97-
class MultiGzipReader {
97+
class MultiGzipReader : public Reader {
9898
public:
9999
explicit MultiGzipReader(const std::vector<std::string>& file_list) {
100100
for (auto& file : file_list) {
101101
readers_.emplace_back(std::make_shared<GzipReader>(file));
102102
}
103103
}
104104

105-
bool HasNext() {
105+
bool HasNext() override {
106106
if (current_reader_index_ >= readers_.size()) {
107107
return false;
108108
}
@@ -113,7 +113,7 @@ class MultiGzipReader {
113113
return true;
114114
}
115115

116-
void NextLine(std::string* line) {
116+
void NextLine(std::string* line) override {
117117
readers_[current_reader_index_]->NextLine(line);
118118
}
119119

@@ -151,6 +151,7 @@ void CTRReader::ReadThread(const std::vector<std::string>& file_list,
151151
for (auto& slots_to_data : batch_data) {
152152
std::vector<size_t> lod_data{0};
153153
std::vector<int64_t> batch_feasign;
154+
std::vector<int64_t> batch_label;
154155

155156
auto& feasign = slots_to_data[slot];
156157

0 commit comments

Comments
 (0)