Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
file.cc
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#include "ortools/port/file.h"
15
16#include <string>
17
18#include "absl/status/status.h"
19#include "absl/strings/string_view.h"
21
22#if !defined(__PORTABLE_PLATFORM__)
23#if !defined(_MSC_VER)
24#include <unistd.h>
25#endif
26
27#include "absl/strings/str_format.h"
28#include "absl/time/clock.h"
31#endif // !defined(__PORTABLE_PLATFORM__)
32
33namespace operations_research {
34
35::absl::Status PortableFileSetContents(absl::string_view file_name,
36 absl::string_view content) {
37#if defined(__PORTABLE_PLATFORM__)
38 return absl::Status(absl::StatusCode::kUnimplemented,
39 "File io is not implemented for this platform.");
40#else // defined(__PORTABLE_PLATFORM__)
41 return file::SetContents(file_name, content, file::Defaults());
42#endif // !defined(__PORTABLE_PLATFORM__)
43}
44
45::absl::Status PortableFileGetContents(absl::string_view file_name,
46 std::string* output) {
47#if defined(__PORTABLE_PLATFORM__)
48 return absl::Status(absl::StatusCode::kUnimplemented,
49 "File io is not implemented for this platform.");
50#else // defined(__PORTABLE_PLATFORM__)
51 return file::GetContents(file_name, output, file::Defaults());
52#endif // !defined(__PORTABLE_PLATFORM__)
53}
54
55::absl::Status PortableDeleteFile(absl::string_view file_name) {
56#if defined(__PORTABLE_PLATFORM__)
57 return absl::Status(absl::StatusCode::kUnimplemented,
58 "File io is not implemented for this platform.");
59#else // defined(__PORTABLE_PLATFORM__)
60 return file::Delete(file_name, file::Defaults());
61#endif // !defined(__PORTABLE_PLATFORM__)
62}
63} // namespace operations_research
absl::StatusOr< std::string > GetContents(absl::string_view path, Options options)
Definition file.cc:349
Options Defaults()
Definition file.h:86
absl::Status Delete(absl::string_view path, Options options)
Definition file.cc:491
absl::Status SetContents(absl::string_view file_name, absl::string_view contents, Options options)
Definition file.cc:389
OR-Tools root namespace.
::absl::Status PortableDeleteFile(absl::string_view file_name)
Definition file.cc:55
::absl::Status PortableFileGetContents(absl::string_view file_name, std::string *output)
Definition file.cc:45
::absl::Status PortableFileSetContents(absl::string_view file_name, absl::string_view content)
Definition file.cc:35