Use parameter packs with io::JoinPath to allow passing more arguments.
Change: 132929686
This commit is contained in:
parent
8875324afc
commit
d5d16aa43b
@ -70,8 +70,8 @@ void AddAssetsTensorsToInputs(const StringPiece export_dir,
|
||||
return;
|
||||
}
|
||||
for (auto& asset : asset_files) {
|
||||
Tensor assets_file_tensor = CreateStringTensor(io::JoinPath(
|
||||
io::JoinPath(export_dir, kAssetsDirectory), asset.filename()));
|
||||
Tensor assets_file_tensor = CreateStringTensor(
|
||||
io::JoinPath(export_dir, kAssetsDirectory, asset.filename()));
|
||||
inputs->push_back(
|
||||
{asset.tensor_binding().tensor_name(), assets_file_tensor});
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ limitations under the License.
|
||||
|
||||
namespace tensorflow {
|
||||
namespace io {
|
||||
namespace internal {
|
||||
|
||||
string JoinPath(StringPiece part1, StringPiece part2) {
|
||||
string JoinPathImpl(std::initializer_list<StringPiece> paths) {
|
||||
string result;
|
||||
|
||||
StringPiece paths[2] = {part1, part2};
|
||||
for (StringPiece path : paths) {
|
||||
if (path.empty()) continue;
|
||||
|
||||
@ -49,8 +49,6 @@ string JoinPath(StringPiece part1, StringPiece part2) {
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
// 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
|
||||
|
@ -22,9 +22,13 @@ limitations under the License.
|
||||
namespace tensorflow {
|
||||
class StringPiece;
|
||||
namespace io {
|
||||
namespace internal {
|
||||
string JoinPathImpl(std::initializer_list<StringPiece> paths);
|
||||
}
|
||||
|
||||
// Utility routines for processing filenames
|
||||
|
||||
#ifndef SWIG // variadic templates
|
||||
// Join multiple paths together, without introducing unnecessary path
|
||||
// separators.
|
||||
// For example:
|
||||
@ -38,7 +42,12 @@ namespace io {
|
||||
// Usage:
|
||||
// string path = io::JoinPath("/mydir", filename);
|
||||
// string path = io::JoinPath(FLAGS_test_srcdir, filename);
|
||||
string JoinPath(StringPiece part1, StringPiece part2);
|
||||
// string path = io::JoinPath("/full", "path", "to", "filename);
|
||||
template <typename... T>
|
||||
string JoinPath(const T&... args) {
|
||||
return internal::JoinPathImpl({args...});
|
||||
}
|
||||
#endif /* SWIG */
|
||||
|
||||
// Return true if path is absolute.
|
||||
bool IsAbsolutePath(StringPiece path);
|
||||
|
@ -31,6 +31,7 @@ TEST(PathTest, JoinPath) {
|
||||
|
||||
EXPECT_EQ("/foo/bar/baz/blah/blink/biz",
|
||||
JoinPath("/foo/bar/baz/", "/blah/blink/biz"));
|
||||
EXPECT_EQ("/foo/bar/baz/blah", JoinPath("/foo", "bar", "baz", "blah"));
|
||||
}
|
||||
|
||||
TEST(PathTest, IsAbsolutePath) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user