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>
55 const google::protobuf::Message&
proto,
57 bool append_extension_to_file_name =
true);
63template <
typename Proto>
66 std::vector<Proto> protos;
69 while (num_read != expected_num_records &&
71 protos.push_back(
proto);
76 <<
"File '" <<
file->filename()
77 <<
"'was not fully read, or something went wrong when closing "
78 "it. Is it the right format? (RecordIO of Protocol Buffers).";
80 if (expected_num_records >= 0) {
81 CHECK_EQ(num_read, expected_num_records)
82 <<
"There were less than the expected " << expected_num_records
90template <
typename Proto>
92 int expected_num_records) {
94 expected_num_records);
101template <
typename Proto>
103 return internal::ReadNumRecords<Proto>(filename, -1);
105template <
typename Proto>
107 return internal::ReadNumRecords<Proto>(
file, -1);
113template <
typename Proto>
116 p.Swap(&internal::ReadNumRecords<Proto>(filename, 1)[0]);
122template <
typename Proto>
124 const std::vector<Proto>& protos) {
127 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)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
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)
std::vector< Proto > ReadAllRecordsOrDie(absl::string_view filename)
void WriteRecordsOrDie(absl::string_view filename, const std::vector< Proto > &protos)
Proto ReadFileToProtoOrDie(absl::string_view filename)
bool ReadFileToProto(absl::string_view filename, google::protobuf::Message *proto)
Proto ReadOneRecordOrDie(absl::string_view filename)