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);
70 int64_t
ReadToString(std::string*
const line, 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_;
123absl::Status
Open(
const absl::string_view& filename,
124 const absl::string_view& mode,
File** f,
int flags);
126 const absl::string_view& mode,
int flags);
127absl::Status
GetTextProto(
const absl::string_view& filename,
128 google::protobuf::Message*
proto,
int flags);
135absl::Status
SetTextProto(
const absl::string_view& filename,
136 const google::protobuf::Message&
proto,
int flags);
138 google::protobuf::Message*
proto,
int flags);
146 const google::protobuf::Message&
proto,
int flags);
147absl::Status
SetContents(
const absl::string_view& filename,
148 const absl::string_view& contents,
int flags);
149absl::Status
GetContents(
const absl::string_view& filename, std::string* output,
154bool ReadFileToString(
const absl::string_view& file_name, std::string* output);
156 const absl::string_view& file_name);
158 google::protobuf::Message*
proto);
160 google::protobuf::Message*
proto);
162 const absl::string_view& file_name);
164 const absl::string_view& file_name);
166 const absl::string_view& file_name);
168 const absl::string_view& file_name);
170absl::Status
Delete(
const absl::string_view& path,
int flags);
171absl::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)