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"
47 size_t Read(
void* buff,
size_t size);
55 char*
ReadLine(
char* output, uint64_t max_length);
62 size_t Write(
const void* buff,
size_t size);
76 absl::Status
Close(
int flags);
99 File(FILE* descriptor, absl::string_view
name);
114absl::Status
Open(absl::string_view filename, absl::string_view mode,
File** f,
118File*
OpenOrDie(absl::string_view filename, absl::string_view mode,
129 const google::protobuf::Message&
proto,
140 const google::protobuf::Message&
proto,
142absl::Status
SetContents(absl::string_view filename, absl::string_view contents,
144absl::StatusOr<std::string>
GetContents(absl::string_view path,
146absl::Status
GetContents(absl::string_view filename, std::string* output,
154 google::protobuf::Message*
proto);
156 google::protobuf::Message*
proto);
158 absl::string_view file_name);
160 absl::string_view file_name);
162 absl::string_view file_name);
164 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.
int64_t ReadToString(std::string *line, uint64_t max_length)
void ReadOrDie(void *buff, size_t size)
CpModelProto proto
The output proto.
const std::string name
A name for logging purposes.
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)