diff --git a/mediapipe/framework/api2/builder.h b/mediapipe/framework/api2/builder.h index da09acc8..ee9796e4 100644 --- a/mediapipe/framework/api2/builder.h +++ b/mediapipe/framework/api2/builder.h @@ -425,7 +425,10 @@ using GenericNode = Node; template class Node : public NodeBase { public: - Node() : NodeBase(std::string(Calc::kCalculatorName)) {} + Node() + : NodeBase( + FunctionRegistry::GetLookupName(Calc::kCalculatorName)) {} + // Overrides the built-in calculator type string with the provided argument. // Can be used to create nodes from pure interfaces. // TODO: only use this for pure interfaces @@ -546,6 +549,7 @@ class Graph { // Creates a node of a specific type. Should be used for pure interfaces, // which do not have a built-in type string. + // `type` is a calculator type-name with dot-separated namespaces. template Node& AddNode(absl::string_view type) { auto node = @@ -557,6 +561,7 @@ class Graph { // Creates a generic node, with no compile-time checking of inputs and // outputs. This can be used for calculators whose contract is not visible. + // `type` is a calculator type-name with dot-separated namespaces. GenericNode& AddNode(absl::string_view type) { auto node = std::make_unique(std::string(type.data(), type.size())); diff --git a/mediapipe/framework/deps/registration.h b/mediapipe/framework/deps/registration.h index cc8ba03f..7965539b 100644 --- a/mediapipe/framework/deps/registration.h +++ b/mediapipe/framework/deps/registration.h @@ -301,6 +301,18 @@ class FunctionRegistry { return cxx_name; } + // Returns a type name with '.' separated namespaces. + static std::string GetLookupName(const absl::string_view cxx_type_name) { + constexpr absl::string_view kCxxSep = "::"; + constexpr absl::string_view kNameSep = "."; + std::vector names = + absl::StrSplit(cxx_type_name, kCxxSep); + if (names[0].empty()) { + names.erase(names.begin()); + } + return absl::StrJoin(names, kNameSep); + } + private: mutable absl::Mutex lock_; absl::flat_hash_map functions_ ABSL_GUARDED_BY(lock_);