From 14c176015a797bbb14c048d9e1cf537932ffecd3 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 16 Mar 2015 20:18:36 +0300 Subject: [PATCH] GDTR find() overload for name only --- .../include/uavcan/node/global_data_type_registry.hpp | 9 +++++++++ libuavcan/src/node/uc_global_data_type_registry.cpp | 10 ++++++++++ libuavcan/test/node/global_data_type_registry.cpp | 3 +++ 3 files changed, 22 insertions(+) diff --git a/libuavcan/include/uavcan/node/global_data_type_registry.hpp b/libuavcan/include/uavcan/node/global_data_type_registry.hpp index 3fc788d0ce..7e27d92886 100644 --- a/libuavcan/include/uavcan/node/global_data_type_registry.hpp +++ b/libuavcan/include/uavcan/node/global_data_type_registry.hpp @@ -126,6 +126,15 @@ public: /** * Finds data type descriptor by full data type name, e.g. "uavcan.protocol.NodeStatus". + * Messages are searched first, then services. + * Returns null pointer if the data type with this name is not registered. + * @param name Full data type name + * @return Descriptor for this data type or null pointer if not found + */ + const DataTypeDescriptor* find(const char* name) const; + + /** + * Finds data type descriptor by full data type name, e.g. "uavcan.protocol.NodeStatus", and data type kind. * Returns null pointer if the data type with this name is not registered. * @param kind Data Type Kind - message or service * @param name Full data type name diff --git a/libuavcan/src/node/uc_global_data_type_registry.cpp b/libuavcan/src/node/uc_global_data_type_registry.cpp index 20fa8b03c9..aa96308d0d 100644 --- a/libuavcan/src/node/uc_global_data_type_registry.cpp +++ b/libuavcan/src/node/uc_global_data_type_registry.cpp @@ -141,6 +141,16 @@ void GlobalDataTypeRegistry::freeze() } } +const DataTypeDescriptor* GlobalDataTypeRegistry::find(const char* name) const +{ + const DataTypeDescriptor* desc = find(DataTypeKindMessage, name); + if (desc == NULL) + { + desc = find(DataTypeKindService, name); + } + return desc; +} + const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, const char* name) const { if (!name) diff --git a/libuavcan/test/node/global_data_type_registry.cpp b/libuavcan/test/node/global_data_type_registry.cpp index 63dc87e5f3..7edf41d2b2 100644 --- a/libuavcan/test/node/global_data_type_registry.cpp +++ b/libuavcan/test/node/global_data_type_registry.cpp @@ -171,6 +171,7 @@ TEST(GlobalDataTypeRegistry, Basic) */ const uavcan::DataTypeDescriptor* pdtd = NULL; ASSERT_FALSE(GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, "Nonexistent")); + ASSERT_FALSE(GlobalDataTypeRegistry::instance().find("Nonexistent")); ASSERT_FALSE(GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, 987)); // Asking for service, but this is a message: ASSERT_FALSE(GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindService, "my_namespace.DataTypeB")); @@ -178,12 +179,14 @@ TEST(GlobalDataTypeRegistry, Basic) ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, "my_namespace.DataTypeB"))); + ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find("my_namespace.DataTypeB"))); ASSERT_EQ(extractDescriptor(741), *pdtd); ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, 741))); ASSERT_EQ(extractDescriptor(741), *pdtd); ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, "my_namespace.DataTypeA"))); + ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find("my_namespace.DataTypeA"))); ASSERT_EQ(extractDescriptor(), *pdtd); ASSERT_TRUE((pdtd = GlobalDataTypeRegistry::instance().find(uavcan::DataTypeKindMessage, uavcan::DataTypeID(0)))); ASSERT_EQ(extractDescriptor(), *pdtd);