14#ifndef OR_TOOLS_BASE_FILE_H_
15#define OR_TOOLS_BASE_FILE_H_
22#include "absl/status/status.h"
23#include "absl/status/statusor.h"
24#include "absl/strings/string_view.h"
25#include "google/protobuf/message.h"
36 static File*
Open(absl::string_view
filename, absl::string_view mode);
45 size_t Read(
void* buff,
size_t size);
53 char*
ReadLine(
char* output, uint64_t max_length);
57 int64_t
ReadToString(std::string* line, uint64_t max_length);
60 size_t Write(
const void* buff,
size_t size);
64 void WriteOrDie(
const void* buff,
size_t size);
74 absl::Status
Close(
int flags);
97 File(FILE* descriptor, absl::string_view name);
112absl::Status
Open(absl::string_view filename, absl::string_view mode,
File** f,
116File*
OpenOrDie(absl::string_view filename, absl::string_view mode,
119 google::protobuf::Message* proto,
Options options);
127 const google::protobuf::Message& proto,
130 google::protobuf::Message* proto,
Options options);
138 const google::protobuf::Message& proto,
140absl::Status
SetContents(absl::string_view filename, absl::string_view contents,
142absl::StatusOr<std::string>
GetContents(absl::string_view path,
144absl::Status
GetContents(absl::string_view filename, std::string* output,
152 google::protobuf::Message* proto);
154 google::protobuf::Message* proto);
156 absl::string_view file_name);
158 absl::string_view file_name);
160 absl::string_view file_name);
162 absl::string_view file_name);
#define RETURN_IF_ERROR(expr)
absl::string_view filename() const
Returns the file name.
static bool Delete(absl::string_view filename)
Deletes a file.
bool WriteLine(absl::string_view line)
Writes a string to file and append a "\n".
size_t Write(const void *buff, size_t size)
Writes "size" bytes of buff to file, buff should be pre-allocated.
size_t Read(void *buff, size_t size)
Reads "size" bytes to buff from file, buff should be pre-allocated.
static File * OpenOrDie(absl::string_view filename, absl::string_view mode)
void WriteOrDie(const void *buff, size_t size)
static void Init()
Inits internal data structures.
size_t Size()
Returns file size.
char * ReadLine(char *output, uint64_t max_length)
static bool Exists(absl::string_view filename)
Tests if a file exists.
size_t WriteString(absl::string_view str)
Writes a string to file.
bool Flush()
Flushes buffer.
bool Close()
Closes the file and delete the underlying FILE* descriptor.
int64_t ReadToString(std::string *line, uint64_t max_length)
void ReadOrDie(void *buff, size_t size)
absl::Status SetTextProto(absl::string_view filename, const google::protobuf::Message &proto, Options options)
absl::StatusOr< std::string > GetContents(absl::string_view path, Options options)
bool WriteProtoToASCIIFile(const google::protobuf::Message &proto, absl::string_view file_name)
absl::Status Exists(absl::string_view path, Options options)
absl::Status Open(absl::string_view filename, absl::string_view mode, File **f, Options options)
As of 2016-01, these methods can only be used with flags = file::Defaults().
absl::Status SetBinaryProto(absl::string_view filename, const google::protobuf::Message &proto, Options options)
bool ReadFileToString(absl::string_view file_name, std::string *output)
bool ReadFileToProto(absl::string_view file_name, google::protobuf::Message *proto)
absl::Status SetContents(absl::string_view filename, absl::string_view contents, Options options)
bool WriteStringToFile(absl::string_view data, absl::string_view file_name)
absl::Status WriteString(File *file, absl::string_view contents, Options options)
void WriteProtoToASCIIFileOrDie(const google::protobuf::Message &proto, absl::string_view file_name)
bool WriteProtoToFile(const google::protobuf::Message &proto, absl::string_view file_name)
void ReadFileToProtoOrDie(absl::string_view file_name, google::protobuf::Message *proto)
void WriteProtoToFileOrDie(const google::protobuf::Message &proto, absl::string_view file_name)
absl::Status Delete(absl::string_view path, Options options)
absl::Status GetTextProto(absl::string_view filename, google::protobuf::Message *proto, Options options)
absl::Status GetBinaryProto(const absl::string_view filename, google::protobuf::Message *proto, Options options)
File * OpenOrDie(absl::string_view filename, absl::string_view mode, Options options)