1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #ifndef TENSORFLOW_STREAM_EXECUTOR_LIB_PATH_H_
17 #define TENSORFLOW_STREAM_EXECUTOR_LIB_PATH_H_
18
19 #include "absl/strings/string_view.h"
20 #include "tensorflow/core/lib/io/path.h"
21 #include "tensorflow/stream_executor/platform/port.h"
22
23 namespace stream_executor {
24 namespace port {
25
26 using tensorflow::io::Dirname;
27
28 namespace internal {
29 // TODO(rspringer): Move to cc/implementation file.
30 // Not part of the public API.
31 string JoinPathImpl(std::initializer_list<absl::string_view> paths);
32 } // namespace internal
33
34 // Join multiple paths together.
35 // JoinPath unconditionally joins all paths together. For example:
36 //
37 // Arguments | JoinPath
38 // ---------------------------+---------------------
39 // '/foo', 'bar' | /foo/bar
40 // '/foo/', 'bar' | /foo/bar
41 // '/foo', '/bar' | /foo/bar
42 // '/foo', '/bar', '/baz' | /foo/bar/baz
43 //
44 // All paths will be treated as relative paths, regardless of whether or not
45 // they start with a leading '/'. That is, all paths will be concatenated
46 // together, with the appropriate path separator inserted in between.
47 // Arguments must be convertible to absl::string_view.
48 //
49 // Usage:
50 // string path = file::JoinPath("/var/log", dirname, filename);
51 // string path = file::JoinPath(FLAGS_test_srcdir, filename);
52 template <typename... T>
JoinPath(const T &...args)53 inline string JoinPath(const T&... args) {
54 return internal::JoinPathImpl({args...});
55 }
56
57 } // namespace port
58 } // namespace stream_executor
59
60 #endif // TENSORFLOW_STREAM_EXECUTOR_LIB_PATH_H_
61