19 #ifndef SINGA_IO_READER_H_ 20 #define SINGA_IO_READER_H_ 25 #include "singa/singa_config.h" 50 virtual bool Open(
const std::string& path) = 0;
53 virtual void Close() = 0;
59 virtual bool Read(std::string* key, std::string* value) = 0;
63 virtual int Count() = 0;
74 bool Open(
const std::string& path)
override;
76 bool Open(
const std::string& path,
int capacity);
78 void Close()
override;
80 bool Read(std::string* key, std::string* value)
override;
86 inline std::string
path() {
return path_; }
93 bool ReadField(std::string* content);
96 bool PrepareNextField(
int size);
100 std::string path_ =
"";
104 char* buf_ =
nullptr;
108 int capacity_ = 10485760;
112 const char kMagicWord[2] = {
's',
'g'};
120 bool Open(
const std::string& path)
override;
122 void Close()
override;
124 bool Read(std::string* key, std::string* value)
override;
126 int Count()
override;
130 inline std::string
path() {
return path_; }
134 std::string path_ =
"";
142 class LMDBReader :
public Reader {
145 ~LMDBReader() {
Close(); }
147 bool Open(
const std::string& path)
override;
149 void Close()
override;
151 bool Read(std::string* key, std::string* value)
override;
153 int Count()
override;
157 inline std::string path() {
return path_; }
159 inline bool valid() {
return valid_; }
163 void Seek(MDB_cursor_op op);
164 inline void MDB_CHECK(
int mdb_status);
168 std::string path_ =
"";
170 MDB_env* mdb_env_ =
nullptr;
174 MDB_txn* mdb_txn_ =
nullptr;
176 MDB_cursor* mdb_cursor_ =
nullptr;
178 MDB_val mdb_key_, mdb_value_;
188 #endif // SINGA_IO_READER_H_ virtual void SeekToFirst()=0
Seek to the first tuple when the cursor arrives to the end of the file.
std::string path()
return path to binary file
Definition: reader.h:86
std::string path()
return path to text file
Definition: reader.h:130
General Reader that provides functions for reading tuples.
Definition: reader.h:41
Binfilereader reads tuples from binary file with key-value pairs.
Definition: reader.h:70
virtual ~Reader()
In case that users forget to call Close() to release resources, e.g., memory, you can release them he...
Definition: reader.h:45
virtual bool Open(const std::string &path)=0
path is the path to the storage, could be a file path, database connection, or hdfs path...
TextFileReader reads tuples from CSV file.
Definition: reader.h:116
virtual int Count()=0
Iterate through all tuples to get the num of all tuples.
virtual bool Read(std::string *key, std::string *value)=0
Read a tuple.
virtual void Close()=0
Release resources.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48