Internal change
PiperOrigin-RevId: 522524565
This commit is contained in:
parent
4e5f20f212
commit
bae14a83b2
|
@ -160,6 +160,7 @@ cc_test(
|
||||||
deps = [
|
deps = [
|
||||||
":port",
|
":port",
|
||||||
"//mediapipe/framework/port:gtest_main",
|
"//mediapipe/framework/port:gtest_main",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -713,12 +713,12 @@ class Graph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TaggedName(const TagIndexLocation& loc, const std::string& name) {
|
std::string TaggedName(const TagIndexLocation& loc, absl::string_view name) {
|
||||||
if (loc.tag.empty()) {
|
if (loc.tag.empty()) {
|
||||||
// ParseTagIndexName does not allow using explicit indices without tags,
|
// ParseTagIndexName does not allow using explicit indices without tags,
|
||||||
// while ParseTagIndex does.
|
// while ParseTagIndex does.
|
||||||
// TODO: decide whether we should just allow it.
|
// TODO: decide whether we should just allow it.
|
||||||
return name;
|
return std::string(name);
|
||||||
} else {
|
} else {
|
||||||
if (loc.count <= 1) {
|
if (loc.count <= 1) {
|
||||||
return absl::StrCat(loc.tag, ":", name);
|
return absl::StrCat(loc.tag, ":", name);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "absl/strings/str_cat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "mediapipe/framework/api2/const_str.h"
|
#include "mediapipe/framework/api2/const_str.h"
|
||||||
#include "mediapipe/framework/api2/packet.h"
|
#include "mediapipe/framework/api2/packet.h"
|
||||||
#include "mediapipe/framework/calculator_context.h"
|
#include "mediapipe/framework/calculator_context.h"
|
||||||
|
@ -36,6 +37,13 @@ namespace api2 {
|
||||||
// directly by node code.
|
// directly by node code.
|
||||||
class PortBase {
|
class PortBase {
|
||||||
public:
|
public:
|
||||||
|
constexpr PortBase(absl::string_view tag, TypeId type_id, bool optional,
|
||||||
|
bool multiple)
|
||||||
|
: tag_(tag.size(), tag.data()),
|
||||||
|
optional_(optional),
|
||||||
|
multiple_(multiple),
|
||||||
|
type_id_(type_id) {}
|
||||||
|
|
||||||
constexpr PortBase(std::size_t tag_size, const char* tag, TypeId type_id,
|
constexpr PortBase(std::size_t tag_size, const char* tag, TypeId type_id,
|
||||||
bool optional, bool multiple)
|
bool optional, bool multiple)
|
||||||
: tag_(tag_size, tag),
|
: tag_(tag_size, tag),
|
||||||
|
@ -123,7 +131,7 @@ auto GetCollection(CC* cc, const SideOutputBase& port)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Collection>
|
template <class Collection>
|
||||||
auto GetOrNull(Collection& collection, const std::string& tag, int index)
|
auto GetOrNull(Collection& collection, const absl::string_view& tag, int index)
|
||||||
-> decltype(&collection.Get(std::declval<CollectionItemId>())) {
|
-> decltype(&collection.Get(std::declval<CollectionItemId>())) {
|
||||||
CollectionItemId id = collection.GetId(tag, index);
|
CollectionItemId id = collection.GetId(tag, index);
|
||||||
return id.IsValid() ? &collection.Get(id) : nullptr;
|
return id.IsValid() ? &collection.Get(id) : nullptr;
|
||||||
|
@ -332,6 +340,9 @@ class PortCommon : public Base {
|
||||||
using Multiple = PortCommon<Base, ValueT, IsOptionalV, true>;
|
using Multiple = PortCommon<Base, ValueT, IsOptionalV, true>;
|
||||||
using SideFallback = SideFallbackT<Base, ValueT, IsOptionalV, IsMultipleV>;
|
using SideFallback = SideFallbackT<Base, ValueT, IsOptionalV, IsMultipleV>;
|
||||||
|
|
||||||
|
explicit constexpr PortCommon(absl::string_view tag)
|
||||||
|
: Base(tag, kTypeId<ValueT>, IsOptionalV, IsMultipleV) {}
|
||||||
|
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
explicit constexpr PortCommon(const char (&tag)[N])
|
explicit constexpr PortCommon(const char (&tag)[N])
|
||||||
: Base(N, tag, kTypeId<ValueT>, IsOptionalV, IsMultipleV) {}
|
: Base(N, tag, kTypeId<ValueT>, IsOptionalV, IsMultipleV) {}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
#include "mediapipe/framework/api2/port.h"
|
#include "mediapipe/framework/api2/port.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "mediapipe/framework/port/gtest.h"
|
#include "mediapipe/framework/port/gtest.h"
|
||||||
|
|
||||||
namespace mediapipe {
|
namespace mediapipe {
|
||||||
namespace api2 {
|
namespace api2 {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr absl::string_view kInputTag{"INPUT"};
|
||||||
|
constexpr absl::string_view kOutputTag{"OUTPUT"};
|
||||||
|
|
||||||
TEST(PortTest, IntInput) {
|
TEST(PortTest, IntInput) {
|
||||||
static constexpr auto port = Input<int>("FOO");
|
static constexpr auto port = Input<int>("FOO");
|
||||||
EXPECT_EQ(port.type_id(), kTypeId<int>);
|
EXPECT_EQ(port.type_id(), kTypeId<int>);
|
||||||
|
@ -40,6 +44,14 @@ TEST(PortTest, DeletedCopyConstructorInput) {
|
||||||
EXPECT_EQ(std::string(kSideOutputPort.Tag()), "SIDE_OUTPUT");
|
EXPECT_EQ(std::string(kSideOutputPort.Tag()), "SIDE_OUTPUT");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PortTest, DeletedCopyConstructorStringView) {
|
||||||
|
static constexpr Input<DeletedCopyType> kInputPort(kInputTag);
|
||||||
|
EXPECT_EQ(std::string(kInputPort.Tag()), kInputTag);
|
||||||
|
|
||||||
|
static constexpr Output<DeletedCopyType> kOutputPort(kOutputTag);
|
||||||
|
EXPECT_EQ(std::string(kOutputPort.Tag()), kOutputTag);
|
||||||
|
}
|
||||||
|
|
||||||
class AbstractBase {
|
class AbstractBase {
|
||||||
public:
|
public:
|
||||||
virtual ~AbstractBase() = default;
|
virtual ~AbstractBase() = default;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user