-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add WString support Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com> * fix type of string literal Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com> * check wstring_to_u16_string function Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com> * fix style Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com> * fix dll linkage warnings Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
- Loading branch information
1 parent
94555d8
commit de8aa3f
Showing
8 changed files
with
294 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
rosidl_typesupport_fastrtps_c/include/rosidl_typesupport_fastrtps_c/wstring_conversion.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2019 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. | ||
|
||
#ifndef ROSIDL_TYPESUPPORT_FASTRTPS_C__WSTRING_CONVERSION_HPP_ | ||
#define ROSIDL_TYPESUPPORT_FASTRTPS_C__WSTRING_CONVERSION_HPP_ | ||
|
||
#include <string> | ||
|
||
#include "rosidl_generator_c/u16string.h" | ||
#include "rosidl_typesupport_fastrtps_c/visibility_control.h" | ||
|
||
namespace rosidl_typesupport_fastrtps_c | ||
{ | ||
|
||
ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC | ||
void u16string_to_wstring( | ||
const rosidl_generator_c__U16String & u16str, std::wstring & wstr); | ||
|
||
ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC | ||
bool wstring_to_u16string( | ||
const std::wstring & wstr, rosidl_generator_c__U16String & u16str); | ||
|
||
} // namespace rosidl_typesupport_fastrtps_c | ||
|
||
#endif // ROSIDL_TYPESUPPORT_FASTRTPS_C__WSTRING_CONVERSION_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2019 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 <rosidl_typesupport_fastrtps_c/wstring_conversion.hpp> | ||
|
||
#include "rosidl_generator_c/u16string_functions.h" | ||
|
||
namespace rosidl_typesupport_fastrtps_c | ||
{ | ||
|
||
void u16string_to_wstring(const rosidl_generator_c__U16String & u16str, std::wstring & wstr) | ||
{ | ||
wstr.resize(u16str.size); | ||
for (size_t i = 0; i < u16str.size; ++i) { | ||
wstr[i] = static_cast<wchar_t>(u16str.data[i]); | ||
} | ||
} | ||
|
||
bool wstring_to_u16string(const std::wstring & wstr, rosidl_generator_c__U16String & u16str) | ||
{ | ||
bool succeeded = rosidl_generator_c__U16String__resize(&u16str, wstr.size()); | ||
if (!succeeded) { | ||
return false; | ||
} | ||
for (size_t i = 0; i < wstr.size(); ++i) { | ||
u16str.data[i] = static_cast<char16_t>(wstr[i]); | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace rosidl_typesupport_fastrtps_c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...l_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/wstring_conversion.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2019 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. | ||
|
||
#ifndef ROSIDL_TYPESUPPORT_FASTRTPS_CPP__WSTRING_CONVERSION_HPP_ | ||
#define ROSIDL_TYPESUPPORT_FASTRTPS_CPP__WSTRING_CONVERSION_HPP_ | ||
|
||
#include <rosidl_typesupport_fastrtps_cpp/visibility_control.h> | ||
|
||
#include <string> | ||
|
||
namespace rosidl_typesupport_fastrtps_cpp | ||
{ | ||
|
||
ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC | ||
void u16string_to_wstring(const std::u16string & u16str, std::wstring & wstr); | ||
|
||
ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC | ||
bool wstring_to_u16string(const std::wstring & wstr, std::u16string & u16str); | ||
|
||
} // namespace rosidl_typesupport_fastrtps_cpp | ||
|
||
#endif // ROSIDL_TYPESUPPORT_FASTRTPS_CPP__WSTRING_CONVERSION_HPP_ |
Oops, something went wrong.
@dirk-thomas This might need parenthesis to be
2 * (@(type_.maximum_size) + 1)
becauseNULL
at the end is an extra code point instead of just 1 byte. same in a few other places