19 #ifndef SINGA_IO_WRITER_H_ 20 #define SINGA_IO_WRITER_H_ 25 #include "singa/singa_config.h" 37 enum Mode { kCreate, kAppend };
55 virtual bool Open(
const std::string &path, Mode mode) = 0;
58 virtual void Close() = 0;
62 virtual bool Write(
const std::string &key,
const std::string &value) = 0;
65 virtual void Flush() = 0;
81 bool Open(
const std::string &path, Mode mode)
override;
83 bool Open(
const std::string &path, Mode mode,
int capacity);
85 void Close()
override;
87 bool Write(
const std::string &key,
const std::string &value)
override;
89 void Flush()
override;
91 inline std::string
path() {
return path_; }
99 std::string path_ =
"";
104 char *buf_ =
nullptr;
106 int capacity_ = 10485760;
110 const char kMagicWord[2] = {
's',
'g'};
118 bool Open(
const std::string &path, Mode mode)
override;
120 void Close()
override;
122 bool Write(
const std::string &key,
const std::string &value)
override;
124 void Flush()
override;
126 inline std::string
path() {
return path_; }
130 std::string path_ =
"";
137 class LMDBWriter :
public Writer {
140 ~LMDBWriter() {
Close(); }
142 bool Open(
const std::string &path, Mode mode)
override;
144 void Close()
override;
146 bool Write(
const std::string &key,
const std::string &value)
override;
148 void Flush()
override;
150 inline std::string path() {
return path_; }
153 void DoubleMapSize();
154 inline void MDB_CHECK(
int mdb_status);
158 std::string path_ =
"";
162 MDB_env *mdb_env_ =
nullptr;
164 std::vector<string> keys, values;
171 #endif // SINGA_IO_WRITER_H_ General Writer that provides functions for writing tuples.
Definition: writer.h:42
virtual void Close()=0
Release resources.
virtual bool Open(const std::string &path, Mode mode)=0
Open a file.
BinFile stores training/validation/test tuples.
Definition: writer.h:77
std::string path()
return path to binary file
Definition: writer.h:91
TextFileWriter write training/validation/test tuples in CSV file.
Definition: writer.h:114
virtual ~Writer()
In case that users forget to call Close() to release resources, e.g., memory, you can release them he...
Definition: writer.h:46
virtual bool Write(const std::string &key, const std::string &value)=0
Write a key-value tuple.
virtual void Flush()=0
Flush writing buffer if it has.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48
std::string path()
return path to text file
Definition: writer.h:126