Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
Namespaces | |
namespace | internal |
Typedefs | |
using | Options = int |
Functions | |
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(). | |
File * | OpenOrDie (absl::string_view filename, absl::string_view mode, Options options) |
absl::StatusOr< std::string > | GetContents (absl::string_view path, Options options) |
absl::Status | GetContents (absl::string_view filename, std::string *output, Options options) |
absl::Status | WriteString (File *file, absl::string_view contents, Options options) |
absl::Status | SetContents (absl::string_view filename, absl::string_view contents, Options options) |
bool | ReadFileToString (absl::string_view file_name, std::string *output) |
bool | WriteStringToFile (absl::string_view data, absl::string_view file_name) |
bool | ReadFileToProto (absl::string_view file_name, google::protobuf::Message *proto) |
void | ReadFileToProtoOrDie (absl::string_view file_name, google::protobuf::Message *proto) |
bool | WriteProtoToASCIIFile (const google::protobuf::Message &proto, absl::string_view file_name) |
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 | WriteProtoToFileOrDie (const google::protobuf::Message &proto, absl::string_view file_name) |
absl::Status | GetTextProto (absl::string_view filename, google::protobuf::Message *proto, Options options) |
absl::Status | SetTextProto (absl::string_view filename, const google::protobuf::Message &proto, Options options) |
absl::Status | GetBinaryProto (const absl::string_view filename, google::protobuf::Message *proto, Options options) |
absl::Status | SetBinaryProto (absl::string_view filename, const google::protobuf::Message &proto, Options options) |
absl::Status | Delete (absl::string_view path, Options options) |
absl::Status | Exists (absl::string_view path, Options options) |
Options | Defaults () |
template<typename T > | |
absl::StatusOr< T > | GetTextProto (absl::string_view filename, Options options) |
template<typename T > | |
absl::StatusOr< T > | GetBinaryProto (absl::string_view filename, Options options) |
absl::Status | Match (std::string_view pattern, std::vector< std::string > *result, const file::Options &options) |
absl::Status | IsDirectory (std::string_view path, const file::Options &options) |
absl::Status | RecursivelyCreateDir (std::string_view path, const file::Options &options) |
std::string | JoinPath (absl::string_view path1, absl::string_view path2) |
bool | IsAbsolutePath (absl::string_view path) |
Return true if path is absolute. | |
std::string | AddSlash (absl::string_view path) |
absl::string_view | Dirname (absl::string_view path) |
absl::string_view | Basename (absl::string_view path) |
std::pair< absl::string_view, absl::string_view > | SplitPath (absl::string_view path) |
absl::string_view | Stem (absl::string_view path) |
absl::string_view | Extension (absl::string_view path) |
std::string | CleanPath (const absl::string_view unclean_path) |
std::string | CollapseSlashes (absl::string_view path) |
std::string | JoinPath () |
std::string | JoinPath (absl::string_view path) |
template<typename... T> | |
std::string | JoinPath (absl::string_view path1, absl::string_view path2, absl::string_view path3, const T &... args) |
template<typename... T> | |
std::string | JoinPathRespectAbsolute (const T &... args) |
std::string | TempFile (absl::string_view prefix) |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. A set of file pathname manipulation routines. Calls to each of the following functions assume their input is well-formed (for some currently nebulous definition of the word). You can get a well-formed path by using file::CleanPath(), and future versions of this API may require this.
This collection is largely modelled on Python's os.path module. Filenames are restricted to ASCII characters in most filesystems at Google. There are additional restrictions and quirks for some filesystems. For example, see file/colossus/base/cfs_path.h for filename character set restrictions for Colossus.
One additional filename quirk: for legacy reasons, filenames of the forms: localhost:pathname hostname:pathname hostname.domainname:pathname will all route to ///<file/localfile and use only the pathname part, so long as hostname/hostname.domainname refer to the current host. The primary implication of this behavior is that filenames that do not begin with a leading '/' and that have a ':' before any '/' may be interpreted differently depending on the hostname where they are evaluated.
using file::Options = int |
std::string file::AddSlash | ( | absl::string_view | path | ) |
absl::string_view file::Basename | ( | absl::string_view | path | ) |
Returns the part of the path after the final "/". If there is no "/" in the path, the result is the same as the input.
std::string file::CleanPath | ( | absl::string_view | path | ) |
Path cleaning utilities.
Common sorts of surprises along those lines:
Check for absolute path and determine initial backtrack limit.
Process all parts
1dot ".<whateverisnext>", check for END or SEP.
2dot END or SEP (".." | "../<whateverisnext>").
We can backtrack the previous part
Empty.
Failed to backtrack and we can't skip it either. Rewind and copy.
We can never backtrack over a copied "../" part so set new limit.
If not parsed, copy entire part until the next SEP or EOS.
Skip consecutive SEP occurrences
Calculate and check the length of the cleaned path.
Remove trailing '/' except if it is root path ("/" ==> path_length := 1)
The cleaned path is empty; assign "." as per the spec.
std::string file::CollapseSlashes | ( | absl::string_view | path | ) |
absl::Status file::Delete | ( | absl::string_view | path, |
Options | options ) |
absl::string_view file::Dirname | ( | absl::string_view | path | ) |
absl::Status file::Exists | ( | absl::string_view | path, |
Options | options ) |
absl::string_view file::Extension | ( | absl::string_view | path | ) |
absl::StatusOr< T > file::GetBinaryProto | ( | absl::string_view | filename, |
Options | options ) |
absl::Status file::GetBinaryProto | ( | const absl::string_view | filename, |
google::protobuf::Message * | proto, | ||
Options | options ) |
absl::Status file::GetContents | ( | absl::string_view | filename, |
std::string * | output, | ||
Options | options ) |
absl::StatusOr< std::string > file::GetContents | ( | absl::string_view | path, |
Options | options ) |
absl::Status file::GetTextProto | ( | absl::string_view | filename, |
google::protobuf::Message * | proto, | ||
Options | options ) |
absl::StatusOr< T > file::GetTextProto | ( | absl::string_view | filename, |
Options | options ) |
bool file::IsAbsolutePath | ( | absl::string_view | path | ) |
absl::Status file::IsDirectory | ( | std::string_view | path, |
const file::Options & | options ) |
Definition at line 64 of file filesystem.cc.
|
inline |
Join multiple paths together. JoinPath and JoinPathRespectAbsolute have slightly different semantics. JoinPath unconditionally joins all paths together, whereas JoinPathRespectAbsolute ignores any segments prior to the last absolute path. For example:
Arguments | JoinPath | JoinPathRespectAbsolute ------------------------—+------------------—+--------------------— 'foo', 'bar' | foo/bar | foo/bar '/foo', 'bar' | /foo/bar | /foo/bar '/foo/', 'bar' | /foo/bar | /foo/bar '/foo', '/bar' | /foo/bar | /bar '/foo/', '/bar' | /foo/bar | /bar '/foo', '/bar', '/baz' | /foo/bar/baz | /baz
The first path may be relative or absolute. All subsequent paths will be treated as relative paths, regardless of whether or not they start with a leading '/'. That is, all paths will be concatenated together, with the appropriate path separator inserted in between. Arguments must be convertible to absl::string_view.
Usage: string path = file::JoinPath("/cns", dirname, filename); string path = file::JoinPath(FLAGS_test_srcdir, filename);
0, 1, 2-path specializations exist to optimize common cases.
std::string file::JoinPath | ( | absl::string_view | path1, |
absl::string_view | path2 ) |
40% of the time in JoinPath() is from calls with 2 arguments, so we specialize that case.
|
inline |
|
inline |
Join multiple paths together, respecting intermediate absolute paths. All paths will be joined together, but if any of the paths is absolute (as defined by IsAbsolutePath()), all prior path segments will be ignored. This is the behavior of the old File::JoinPath(). Arguments must be convertible to absl::string_view.
Usage: string path = file::JoinPathRespectAbsolute("/cns", dirname, filename); string path = file::JoinPathRespectAbsolute(FLAGS_test_srcdir, filename);
absl::Status file::Match | ( | std::string_view | pattern, |
std::vector< std::string > * | result, | ||
const file::Options & | options ) |
Definition at line 33 of file filesystem.cc.
absl::Status file::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().
The caller should free the File after closing it by passing *f to delete.
bool file::ReadFileToProto | ( | absl::string_view | file_name, |
google::protobuf::Message * | proto ) |
Attempt to decode ASCII before deciding binary. Do it in this order because it is much harder for a binary encoding to happen to be a valid ASCII encoding than the other way around. For instance "index: 1\n" is a valid (but nonsensical) binary encoding. We want to avoid printing errors for valid binary encodings if the ASCII parsing fails, and so specify a no-op error collector.
Re-parse the ASCII, just to show the diagnostics (we could also get them out of the ErrorCollector but this way is easier).
void file::ReadFileToProtoOrDie | ( | absl::string_view | file_name, |
google::protobuf::Message * | proto ) |
bool file::ReadFileToString | ( | absl::string_view | file_name, |
std::string * | output ) |
absl::Status file::RecursivelyCreateDir | ( | std::string_view | path, |
const file::Options & | options ) |
Definition at line 74 of file filesystem.cc.
absl::Status file::SetBinaryProto | ( | absl::string_view | filename, |
const google::protobuf::Message & | proto, | ||
Options | options ) |
absl::Status file::SetContents | ( | absl::string_view | filename, |
absl::string_view | contents, | ||
Options | options ) |
absl::Status file::SetTextProto | ( | absl::string_view | filename, |
const google::protobuf::Message & | proto, | ||
Options | options ) |
std::pair< absl::string_view, absl::string_view > file::SplitPath | ( | absl::string_view | path | ) |
Return the parts of the path, split on the final "/". If there is no "/" in the path, the first part of the output is empty and the second is the input. If the only "/" in the path is the first character, it is the first part of the output.
Handle the case with no '/' in 'path'.
Handle the case with a single leading '/' in 'path'.
absl::string_view file::Stem | ( | absl::string_view | path | ) |
Returns the part of the basename of path prior to the final ".". If there is no "." in the basename, this is equivalent to file::Basename(path).
std::string file::TempFile | ( | absl::string_view | prefix | ) |
Definition at line 25 of file temp_path.cc.
bool file::WriteProtoToASCIIFile | ( | const google::protobuf::Message & | proto, |
absl::string_view | file_name ) |
void file::WriteProtoToASCIIFileOrDie | ( | const google::protobuf::Message & | proto, |
absl::string_view | file_name ) |
bool file::WriteProtoToFile | ( | const google::protobuf::Message & | proto, |
absl::string_view | file_name ) |
void file::WriteProtoToFileOrDie | ( | const google::protobuf::Message & | proto, |
absl::string_view | file_name ) |