Use parameter packs with io::JoinPath to allow passing more arguments.

Change: 132929686
This commit is contained in:
Jonathan Hseu 2016-09-12 14:55:33 -08:00 committed by TensorFlower Gardener
parent 8875324afc
commit d5d16aa43b
4 changed files with 15 additions and 7 deletions

View File

@ -70,8 +70,8 @@ void AddAssetsTensorsToInputs(const StringPiece export_dir,
return; return;
} }
for (auto& asset : asset_files) { for (auto& asset : asset_files) {
Tensor assets_file_tensor = CreateStringTensor(io::JoinPath( Tensor assets_file_tensor = CreateStringTensor(
io::JoinPath(export_dir, kAssetsDirectory), asset.filename())); io::JoinPath(export_dir, kAssetsDirectory, asset.filename()));
inputs->push_back( inputs->push_back(
{asset.tensor_binding().tensor_name(), assets_file_tensor}); {asset.tensor_binding().tensor_name(), assets_file_tensor});
} }

View File

@ -18,11 +18,11 @@ limitations under the License.
namespace tensorflow { namespace tensorflow {
namespace io { namespace io {
namespace internal {
string JoinPath(StringPiece part1, StringPiece part2) { string JoinPathImpl(std::initializer_list<StringPiece> paths) {
string result; string result;
StringPiece paths[2] = {part1, part2};
for (StringPiece path : paths) { for (StringPiece path : paths) {
if (path.empty()) continue; if (path.empty()) continue;
@ -49,8 +49,6 @@ string JoinPath(StringPiece part1, StringPiece part2) {
return result; return result;
} }
namespace internal {
// Return the parts of the path, split on the final "/". If there is no // 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 // "/" 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 // is the input. If the only "/" in the path is the first character, it is

View File

@ -22,9 +22,13 @@ limitations under the License.
namespace tensorflow { namespace tensorflow {
class StringPiece; class StringPiece;
namespace io { namespace io {
namespace internal {
string JoinPathImpl(std::initializer_list<StringPiece> paths);
}
// Utility routines for processing filenames // Utility routines for processing filenames
#ifndef SWIG // variadic templates
// Join multiple paths together, without introducing unnecessary path // Join multiple paths together, without introducing unnecessary path
// separators. // separators.
// For example: // For example:
@ -38,7 +42,12 @@ namespace io {
// Usage: // Usage:
// string path = io::JoinPath("/mydir", filename); // string path = io::JoinPath("/mydir", filename);
// string path = io::JoinPath(FLAGS_test_srcdir, 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. // Return true if path is absolute.
bool IsAbsolutePath(StringPiece path); bool IsAbsolutePath(StringPiece path);

View File

@ -31,6 +31,7 @@ TEST(PathTest, JoinPath) {
EXPECT_EQ("/foo/bar/baz/blah/blink/biz", EXPECT_EQ("/foo/bar/baz/blah/blink/biz",
JoinPath("/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) { TEST(PathTest, IsAbsolutePath) {