14 #ifndef OR_TOOLS_BASE_FILE_H_
15 #define OR_TOOLS_BASE_FILE_H_
21 #include "absl/status/status.h"
22 #include "absl/strings/string_view.h"
23 #include "google/protobuf/descriptor.h"
24 #include "google/protobuf/io/tokenizer.h"
25 #include "google/protobuf/message.h"
26 #include "google/protobuf/text_format.h"
37 static File*
Open(
const char*
const name,
const char*
const flag);
41 const char*
const mode) {
52 const char*
const flag) {
58 size_t Read(
void*
const buff,
size_t size);
62 void ReadOrDie(
void*
const buff,
size_t size);
66 char*
ReadLine(
char*
const output, uint64_t max_length);
73 size_t Write(
const void*
const buff,
size_t size);
77 void WriteOrDie(
const void*
const buff,
size_t size);
87 absl::Status
Close(
int flags);
113 File(FILE*
const descriptor,
const absl::string_view&
name);
116 const absl::string_view name_;
126 absl::Status
Open(
const absl::string_view& filename,
127 const absl::string_view& mode,
File** f,
int flags);
129 const absl::string_view& mode,
int flags);
130 absl::Status
GetTextProto(
const absl::string_view& filename,
131 google::protobuf::Message*
proto,
int flags);
132 template <
typename T>
133 absl::StatusOr<T>
GetTextProto(absl::string_view filename,
int flags) {
138 absl::Status
SetTextProto(
const absl::string_view& filename,
139 const google::protobuf::Message&
proto,
int flags);
141 google::protobuf::Message*
proto,
int flags);
142 template <
typename T>
149 const google::protobuf::Message&
proto,
int flags);
150 absl::Status
SetContents(
const absl::string_view& filename,
151 const absl::string_view& contents,
int flags);
152 absl::Status
GetContents(
const absl::string_view& filename, std::string* output,
157 bool ReadFileToString(
const absl::string_view& file_name, std::string* output);
159 const absl::string_view& file_name);
161 google::protobuf::Message*
proto);
163 google::protobuf::Message*
proto);
165 const absl::string_view& file_name);
167 const absl::string_view& file_name);
169 const absl::string_view& file_name);
171 const absl::string_view& file_name);
173 absl::Status
Delete(
const absl::string_view& path,
int flags);
174 absl::Status
Exists(
const absl::string_view& path,
int flags);
#define RETURN_IF_ERROR(expr)
static File * OpenOrDie(const absl::string_view &name, const char *const flag)
static File * OpenOrDie(const char *const name, const char *const flag)
int64_t ReadToString(std::string *const line, uint64_t max_length)
char * ReadLine(char *const output, uint64_t max_length)
static bool Exists(const char *const name)
void WriteOrDie(const void *const buff, size_t size)
void ReadOrDie(void *const buff, size_t size)
size_t Write(const void *const buff, size_t size)
size_t Read(void *const buff, size_t size)
bool WriteLine(const std::string &line)
static bool Delete(const char *const name)
absl::string_view filename() const
size_t WriteString(const std::string &line)
static File * Open(const absl::string_view &name, const char *const mode)
static bool Delete(const absl::string_view &name)
absl::Status WriteString(File *file, const absl::string_view &contents, int flags)
absl::Status GetContents(const absl::string_view &filename, std::string *output, int flags)
absl::Status GetBinaryProto(const absl::string_view filename, google::protobuf::Message *const proto, const int flags)
bool ReadFileToString(const absl::string_view &file_name, std::string *output)
absl::Status Delete(const absl::string_view &path, int flags)
File * OpenOrDie(const absl::string_view &filename, const absl::string_view &mode, int flags)
void WriteProtoToASCIIFileOrDie(const google::protobuf::Message &proto, const absl::string_view &file_name)
bool WriteProtoToFile(const google::protobuf::Message &proto, const absl::string_view &file_name)
absl::Status GetTextProto(const absl::string_view &filename, google::protobuf::Message *proto, int flags)
void WriteProtoToFileOrDie(const google::protobuf::Message &proto, const absl::string_view &file_name)
bool WriteProtoToASCIIFile(const google::protobuf::Message &proto, const absl::string_view &file_name)
absl::Status SetTextProto(const absl::string_view &filename, const google::protobuf::Message &proto, int flags)
bool WriteStringToFile(const std::string &data, const absl::string_view &file_name)
absl::Status SetBinaryProto(const absl::string_view &filename, const google::protobuf::Message &proto, int flags)
bool ReadFileToProto(const absl::string_view &file_name, google::protobuf::Message *proto)
absl::Status Exists(const absl::string_view &path, int flags)
absl::Status Open(const absl::string_view &filename, const absl::string_view &mode, File **f, int flags)
absl::Status SetContents(const absl::string_view &filename, const absl::string_view &contents, int flags)
void ReadFileToProtoOrDie(const absl::string_view &file_name, google::protobuf::Message *proto)