14#ifndef OR_TOOLS_UTIL_FILE_UTIL_H_
15#define OR_TOOLS_UTIL_FILE_UTIL_H_
20#include "absl/status/statusor.h"
21#include "absl/strings/string_view.h"
22#include "google/protobuf/message.h"
38 google::protobuf::Message*
proto);
40template <
typename Proto>
57 const google::protobuf::Message&
proto,
59 bool append_extension_to_file_name =
true);
65template <
typename Proto>
68 std::vector<Proto> protos;
71 while (num_read != expected_num_records &&
73 protos.push_back(
proto);
78 <<
"File '" <<
file->filename()
79 <<
"'was not fully read, or something went wrong when closing "
80 "it. Is it the right format? (RecordIO of Protocol Buffers).";
82 if (expected_num_records >= 0) {
83 CHECK_EQ(num_read, expected_num_records)
84 <<
"There were less than the expected " << expected_num_records
92template <
typename Proto>
94 int expected_num_records) {
96 expected_num_records);
103template <
typename Proto>
105 return internal::ReadNumRecords<Proto>(filename, -1);
107template <
typename Proto>
109 return internal::ReadNumRecords<Proto>(
file, -1);
115template <
typename Proto>
118 p.Swap(&internal::ReadNumRecords<Proto>(filename, 1)[0]);
124template <
typename Proto>
126 const std::vector<Proto>& protos) {
129 for (
const Proto&
proto : protos) {
#define CHECK_EQ(val1, val2)
bool ReadProtocolMessage(P *const proto)
bool WriteProtocolMessage(const P &proto)
File * OpenOrDie(const absl::string_view &filename, const absl::string_view &mode, int flags)
std::vector< Proto > ReadNumRecords(File *file, int expected_num_records)
Collection of objects used to extend the Constraint Solver library.
Proto ReadFileToProtoOrDie(absl::string_view filename)
absl::StatusOr< std::string > ReadFileToString(absl::string_view filename)
bool WriteProtoToFile(absl::string_view filename, const google::protobuf::Message &proto, ProtoWriteFormat proto_write_format, bool gzipped, bool append_extension_to_file_name)
void WriteRecordsOrDie(absl::string_view filename, const std::vector< Proto > &protos)
std::vector< Proto > ReadAllRecordsOrDie(absl::string_view filename)
bool ReadFileToProto(absl::string_view filename, google::protobuf::Message *proto)
Proto ReadOneRecordOrDie(absl::string_view filename)