Internal change

PiperOrigin-RevId: 522206591
This commit is contained in:
Hadon Nash 2023-04-05 18:13:07 -07:00 committed by Copybara-Service
parent f67007d077
commit 7fe87936e5
2 changed files with 18 additions and 1 deletions

View File

@ -425,7 +425,10 @@ using GenericNode = Node<internal::Generic>;
template <class Calc>
class Node : public NodeBase {
public:
Node() : NodeBase(std::string(Calc::kCalculatorName)) {}
Node()
: NodeBase(
FunctionRegistry<NodeBase>::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 <class Calc>
Node<Calc>& 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<GenericNode>(std::string(type.data(), type.size()));

View File

@ -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<absl::string_view> 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<std::string, Function> functions_ ABSL_GUARDED_BY(lock_);