Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function for getting a types fully qualified name #514

Merged
merged 3 commits into from Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions rosidl_generator_cpp/CMakeLists.txt
Expand Up @@ -92,6 +92,16 @@ if(BUILD_TESTING)
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}
)
endif()
ament_add_gtest(test_fully_qualified_name test/test_fully_qualified_name.cpp)
if(TARGET test_fully_qualified_name)
add_dependencies(test_fully_qualified_name ${PROJECT_NAME})
ament_target_dependencies(test_fully_qualified_name
rosidl_runtime_cpp
rosidl_runtime_c)
target_include_directories(test_fully_qualified_name PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}
)
endif()
ament_add_gtest(test_traits test/test_traits.cpp)
if(TARGET test_traits)
add_dependencies(test_traits ${PROJECT_NAME})
Expand Down
7 changes: 7 additions & 0 deletions rosidl_generator_cpp/resource/msg__traits.hpp.em
Expand Up @@ -11,6 +11,7 @@ from rosidl_parser.definition import AbstractSequence
from rosidl_parser.definition import UnboundedSequence

message_typename = '::'.join(message.structure.namespaced_type.namespaced_name())
message_fully_qualified_name = '/'.join(message.structure.namespaced_type.namespaced_name())
}@
@
@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Expand Down Expand Up @@ -66,6 +67,12 @@ inline const char * data_type<@(message_typename)>()
return "@(message_typename)";
}

template<>
inline const char * fully_qualified_name<@(message_typename)>()
{
return "@(message_fully_qualified_name)";
}

@{
fixed_template_string = 'true'
fixed_template_strings = set()
Expand Down
7 changes: 7 additions & 0 deletions rosidl_generator_cpp/resource/srv__traits.hpp.em
Expand Up @@ -15,6 +15,7 @@ TEMPLATE(

@{
service_typename = '::'.join(service.namespaced_type.namespaced_name())
service_fully_qualified_name = '/'.join(service.namespaced_type.namespaced_name())
}@
@
namespace rosidl_generator_traits
Expand All @@ -26,6 +27,12 @@ inline const char * data_type<@(service_typename)>()
return "@(service_typename)";
}

template<>
inline const char * fully_qualified_name<@(service_typename)>()
{
return "@(service_fully_qualified_name)";
}

template<>
struct has_fixed_size<@(service_typename)>
: std::integral_constant<
Expand Down
37 changes: 37 additions & 0 deletions rosidl_generator_cpp/test/test_fully_qualified_name.cpp
@@ -0,0 +1,37 @@
// Copyright 2020 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>
#include "rosidl_generator_cpp/msg/empty.hpp"
#include "rosidl_generator_cpp/msg/strings.hpp"
#include "rosidl_generator_cpp/srv/basic_types.hpp"
#include "rosidl_generator_cpp/srv/empty.hpp"

TEST(Test_rosidl_generator_traits, check_msg_fully_qualified_name) {
ASSERT_STREQ(
"rosidl_generator_cpp/msg/Strings",
rosidl_generator_traits::fully_qualified_name<rosidl_generator_cpp::msg::Strings>());
ASSERT_STREQ(
"rosidl_generator_cpp/msg/Empty",
rosidl_generator_traits::fully_qualified_name<rosidl_generator_cpp::msg::Empty>());
}

TEST(Test_rosidl_generator_traits, check_srv_fully_qualified_name) {
ASSERT_STREQ(
"rosidl_generator_cpp/srv/BasicTypes",
rosidl_generator_traits::fully_qualified_name<rosidl_generator_cpp::srv::BasicTypes>());
ASSERT_STREQ(
"rosidl_generator_cpp/srv/Empty",
rosidl_generator_traits::fully_qualified_name<rosidl_generator_cpp::srv::Empty>());
}
3 changes: 3 additions & 0 deletions rosidl_runtime_cpp/include/rosidl_runtime_cpp/traits.hpp
Expand Up @@ -23,6 +23,9 @@ namespace rosidl_generator_traits
template<typename T>
inline const char * data_type();

template<typename T>
inline const char * fully_qualified_name();

template<typename T>
struct has_fixed_size : std::false_type {};

Expand Down