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/stream_executor/platform/port.h"
21
22 namespace stream_executor {
23 namespace port {
24
25 namespace internal {
26 // TODO(rspringer): Move to cc/implementation file.
27 // Not part of the public API.
28 std::string JoinPathImpl(std::initializer_list<absl::string_view> paths);
29 } // namespace internal
30
31 // Join multiple paths together.
32 // JoinPath unconditionally joins all paths together. For example:
33 //
34 // Arguments | JoinPath
35 // ---------------------------+---------------------
36 // '/foo', 'bar' | /foo/bar
37 // '/foo/', 'bar' | /foo/bar
38 // '/foo', '/bar' | /foo/bar
39 // '/foo', '/bar', '/baz' | /foo/bar/baz
40 //
41 // All paths will be treated as relative paths, regardless of whether or not
42 // they start with a leading '/'. That is, all paths will be concatenated
43 // together, with the appropriate path separator inserted in between.
44 // Arguments must be convertible to absl::string_view.
45 //
46 // Usage:
47 // string path = file::JoinPath("/var/log", dirname, filename);
48 // string path = file::JoinPath(FLAGS_test_srcdir, filename);
49 template <typename... T>
JoinPath(const T &...args)50 inline std::string JoinPath(const T&... args) {
51 return internal::JoinPathImpl({args...});
52 }
53
54 } // namespace port
55 } // namespace stream_executor
56
57 #endif // TENSORFLOW_STREAM_EXECUTOR_LIB_PATH_H_
58