Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
temp_path.h
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// emulates g3/file/util/temp_path.h
15#ifndef ORTOOLS_BASE_TEMP_PATH_H_
16#define ORTOOLS_BASE_TEMP_PATH_H_
17
18#include <string>
19
20#include "absl/status/status.h"
21#include "absl/strings/string_view.h"
22#include "ortools/base/file.h"
23
24class TempPath {
25 public:
26 // default mode to create directories (a+rwx):
27 static constexpr int kDefaultMode = 0777;
28
29 explicit TempPath(absl::string_view prefix);
30 TempPath(absl::string_view prefix, absl::Status* status);
31
32 // TempPath is moveable, but not copyable.
33 TempPath(TempPath&& rhs);
34 TempPath(const TempPath& rhs) = delete;
36 TempPath& operator=(const TempPath& rhs) = delete;
37
38 ~TempPath();
39
40 // Returns the path which was created by this object.
41 std::string path() const { return path_; }
42
43 enum Location {
45 };
46
47 static TempPath* Create(Location location);
48
49 private:
50 // Internal constructor for Create* methods.
51 TempPath(const std::string& dirname, file::Options options,
52 absl::Status* status);
53
54 // Shared initialization among constructors.
55 // Makes directory given by path() and `options`.
56 absl::Status Init(file::Options options);
57
58 std::string path_;
59};
60
61namespace file {} // namespace file
62
63#endif // ORTOOLS_BASE_TEMP_PATH_H_
static TempPath * Create(Location location)
Definition temp_path.cc:56
static constexpr int kDefaultMode
Definition temp_path.h:27
TempPath(const TempPath &rhs)=delete
TempPath(absl::string_view prefix)
Definition temp_path.cc:37
std::string path() const
Definition temp_path.h:41
TempPath & operator=(const TempPath &rhs)=delete
TempPath & operator=(TempPath &&rhs)
Definition temp_path.cc:48
Definition file.cc:327
int Options
Definition file.h:84