Skip to content

Commit 182d8c6

Browse files
author
Felix Exner
authored
Merge pull request #23 from UniversalRobots/no_boost
Remove boost dependency
2 parents 22df3c8 + 36f1974 commit 182d8c6

File tree

8 files changed

+95
-70
lines changed

8 files changed

+95
-70
lines changed

.github/workflows/industrial-ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ jobs:
1818
strategy:
1919
matrix:
2020
env:
21-
- ROS_DISTRO: kinetic
22-
ROS_REPO: main
23-
IMMEDIATE_TEST_OUTPUT: true
2421
- ROS_DISTRO: melodic
2522
ROS_REPO: main
2623
IMMEDIATE_TEST_OUTPUT: true

CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
88
set(CMAKE_BUILD_TYPE RelWithDebInfo)
99
endif()
1010

11-
find_package(Boost REQUIRED)
12-
1311

1412
##
1513
## Check C++11 support / enable global pedantic and Wall
1614
##
17-
include(DefineCXX11CompilerFlag)
18-
DEFINE_CXX_11_COMPILER_FLAG(CXX11_FLAG)
15+
include(DefineCXX17CompilerFlag)
16+
DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG)
1917
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
2018

2119
add_library(urcl SHARED
@@ -44,11 +42,10 @@ add_library(urcl SHARED
4442
)
4543
add_library(ur_client_library::urcl ALIAS urcl)
4644
target_compile_options(urcl PRIVATE -Wall -Wextra -Wno-unused-parameter)
47-
target_compile_options(urcl PUBLIC ${CXX11_FLAG})
45+
target_compile_options(urcl PUBLIC ${CXX17_FLAG})
4846
target_include_directories( urcl PUBLIC
4947
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
5048
$<INSTALL_INTERFACE:include>
51-
${Boost_INCLUDE_DIRS}
5249
)
5350

5451
find_package(Threads REQUIRED)
@@ -82,8 +79,6 @@ else()
8279
endif()
8380

8481

85-
target_link_libraries(urcl INTERFACE ${Boost_Libraries})
86-
8782
add_subdirectory(examples)
8883

8984
include(GNUInstallDirs)

examples/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ project(ur_driver_examples)
66
##
77
## Check C++11 support / enable global pedantic and Wall
88
##
9-
include(DefineCXX11CompilerFlag)
10-
DEFINE_CXX_11_COMPILER_FLAG(CXX11_FLAG)
9+
include(DefineCXX17CompilerFlag)
10+
DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG)
1111
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
1212

1313
add_executable(driver_example
1414
full_driver.cpp)
15-
target_compile_options(driver_example PUBLIC ${CXX11_FLAG})
15+
target_compile_options(driver_example PUBLIC ${CXX17_FLAG})
1616
target_link_libraries(driver_example ur_client_library::urcl)
1717

1818
add_executable(primary_pipeline_example
1919
primary_pipeline.cpp)
20-
target_compile_options(primary_pipeline_example PUBLIC ${CXX11_FLAG})
20+
target_compile_options(primary_pipeline_example PUBLIC ${CXX17_FLAG})
2121
target_link_libraries(primary_pipeline_example ur_client_library::urcl)
2222

2323
add_executable(rtde_client_example
2424
rtde_client.cpp)
25-
target_compile_options(rtde_client_example PUBLIC ${CXX11_FLAG})
25+
target_compile_options(rtde_client_example PUBLIC ${CXX17_FLAG})
2626
target_link_libraries(rtde_client_example ur_client_library::urcl)

include/ur_client_library/rtde/data_package.h

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
#define UR_CLIENT_LIBRARY_DATA_PACKAGE_H_INCLUDED
3030

3131
#include <unordered_map>
32+
#include <variant>
3233
#include <vector>
3334

3435
#include "ur_client_library/types.h"
3536
#include "ur_client_library/rtde/rtde_package.h"
36-
#include <boost/variant.hpp>
3737

3838
namespace urcl
3939
{
@@ -59,8 +59,8 @@ enum class RUNTIME_STATE : uint32_t
5959
class DataPackage : public RTDEPackage
6060
{
6161
public:
62-
using _rtde_type_variant = boost::variant<bool, uint8_t, uint32_t, uint64_t, int32_t, double, vector3d_t, vector6d_t,
63-
vector6int32_t, vector6uint32_t, std::string>;
62+
using _rtde_type_variant = std::variant<bool, uint8_t, uint32_t, uint64_t, int32_t, double, vector3d_t, vector6d_t,
63+
vector6int32_t, vector6uint32_t, std::string>;
6464

6565
DataPackage() = delete;
6666

@@ -116,7 +116,6 @@ class DataPackage : public RTDEPackage
116116
*
117117
* \param name The string identifier for the data field as used in the documentation.
118118
* \param val Target variable. Make sure, it's the correct type.
119-
* \exception boost::bad_get if the type under given \p name does not match the template type T.
120119
*
121120
* \returns True on success, false if the field cannot be found inside the package.
122121
*/
@@ -125,7 +124,7 @@ class DataPackage : public RTDEPackage
125124
{
126125
if (data_.find(name) != data_.end())
127126
{
128-
val = boost::strict_get<T>(data_[name]);
127+
val = std::get<T>(data_[name]);
129128
}
130129
else
131130
{
@@ -141,7 +140,6 @@ class DataPackage : public RTDEPackage
141140
*
142141
* \param name The string identifier for the data field as used in the documentation.
143142
* \param val Target variable. Make sure, it's the correct type.
144-
* \exception boost::bad_get if the type under given \p name does not match the template type T.
145143
*
146144
* \returns True on success, false if the field cannot be found inside the package.
147145
*/
@@ -152,7 +150,7 @@ class DataPackage : public RTDEPackage
152150

153151
if (data_.find(name) != data_.end())
154152
{
155-
val = std::bitset<N>(boost::strict_get<T>(data_[name]));
153+
val = std::bitset<N>(std::get<T>(data_[name]));
156154
}
157155
else
158156
{
@@ -201,41 +199,6 @@ class DataPackage : public RTDEPackage
201199
uint8_t recipe_id_;
202200
std::unordered_map<std::string, _rtde_type_variant> data_;
203201
std::vector<std::string> recipe_;
204-
205-
struct ParseVisitor : public boost::static_visitor<>
206-
{
207-
template <typename T>
208-
void operator()(T& d, comm::BinParser& bp) const
209-
{
210-
bp.parse(d);
211-
}
212-
};
213-
struct StringVisitor : public boost::static_visitor<std::string>
214-
{
215-
template <typename T>
216-
std::string operator()(T& d) const
217-
{
218-
std::stringstream ss;
219-
ss << d;
220-
return ss.str();
221-
}
222-
};
223-
struct SizeVisitor : public boost::static_visitor<uint16_t>
224-
{
225-
template <typename T>
226-
uint16_t operator()(T& d) const
227-
{
228-
return sizeof(d);
229-
}
230-
};
231-
struct SerializeVisitor : public boost::static_visitor<size_t>
232-
{
233-
template <typename T>
234-
size_t operator()(T& d, uint8_t* buffer) const
235-
{
236-
return comm::PackageSerializer::serialize(buffer, d);
237-
}
238-
};
239202
};
240203

241204
} // namespace rtde_interface

package.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
<buildtool_depend>cmake</buildtool_depend>
2222

23-
<build_depend>boost</build_depend>
2423
<depend>libconsole-bridge-dev</depend>
2524

2625
<export>

src/rtde/data_package.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ bool rtde_interface::DataPackage::parseWith(comm::BinParser& bp)
574574
if (g_type_list.find(item) != g_type_list.end())
575575
{
576576
_rtde_type_variant entry = g_type_list[item];
577-
auto bound_visitor = std::bind(ParseVisitor(), std::placeholders::_1, bp);
578-
boost::apply_visitor(bound_visitor, entry);
577+
std::visit([&bp](auto&& arg) { bp.parse(arg); }, entry);
579578
data_[item] = entry;
580579
}
581580
else
@@ -592,7 +591,8 @@ std::string rtde_interface::DataPackage::toString() const
592591
for (auto& item : data_)
593592
{
594593
ss << item.first << ": ";
595-
ss << boost::apply_visitor(StringVisitor{}, item.second) << std::endl;
594+
std::visit([&ss](auto&& arg) { ss << arg; }, item.second);
595+
ss << std::endl;
596596
}
597597
return ss.str();
598598
}
@@ -603,15 +603,16 @@ size_t rtde_interface::DataPackage::serializePackage(uint8_t* buffer)
603603

604604
for (auto& item : data_)
605605
{
606-
payload_size += boost::apply_visitor(SizeVisitor{}, item.second);
606+
payload_size += std::visit([](auto&& arg) -> uint16_t { return sizeof(arg); }, item.second);
607607
}
608608
size_t size = 0;
609609
size += PackageHeader::serializeHeader(buffer, PackageType::RTDE_DATA_PACKAGE, payload_size);
610610
size += comm::PackageSerializer::serialize(buffer + size, recipe_id_);
611611
for (auto& item : recipe_)
612612
{
613-
auto bound_visitor = std::bind(SerializeVisitor(), std::placeholders::_1, buffer + size);
614-
size += boost::apply_visitor(bound_visitor, data_[item]);
613+
size += std::visit(
614+
[&buffer, &size](auto&& arg) -> size_t { return comm::PackageSerializer::serialize(buffer + size, arg); },
615+
data_[item]);
615616
}
616617

617618
return size;

tests/CMakeLists.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ if (NOT TARGET ur_client_library::urcl)
2222
endif()
2323

2424
# Check C++11 support
25-
include(DefineCXX11CompilerFlag)
26-
DEFINE_CXX_11_COMPILER_FLAG(CXX11_FLAG)
25+
include(DefineCXX17CompilerFlag)
26+
DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG)
2727

2828

2929
# Build Tests
3030
if (INTEGRATION_TESTS)
3131
# Integration tests require a robot reachable at 192.168.56.101. Therefore, they have to be
3232
# activated separately.
3333
add_executable(rtde_tests test_rtde_client.cpp)
34-
target_compile_options(rtde_tests PRIVATE ${CXX11_FLAG})
34+
target_compile_options(rtde_tests PRIVATE ${CXX17_FLAG})
3535
target_include_directories(rtde_tests PRIVATE ${GTEST_INCLUDE_DIRS})
3636
target_link_libraries(rtde_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
3737
gtest_add_tests(TARGET rtde_tests
@@ -42,14 +42,21 @@ else()
4242
endif()
4343

4444
add_executable(primary_parser_tests test_primary_parser.cpp)
45-
target_compile_options(primary_parser_tests PRIVATE ${CXX11_FLAG})
45+
target_compile_options(primary_parser_tests PRIVATE ${CXX17_FLAG})
4646
target_include_directories(primary_parser_tests PRIVATE ${GTEST_INCLUDE_DIRS})
4747
target_link_libraries(primary_parser_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
4848
gtest_add_tests(TARGET primary_parser_tests
4949
)
5050

51+
add_executable(rtde_data_package test_rtde_data_package.cpp)
52+
target_compile_options(rtde_data_package PRIVATE ${CXX17_FLAG})
53+
target_include_directories(rtde_data_package PRIVATE ${GTEST_INCLUDE_DIRS})
54+
target_link_libraries(rtde_data_package PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
55+
gtest_add_tests(TARGET rtde_data_package
56+
)
57+
5158
add_executable(rtde_parser_tests test_rtde_parser.cpp)
52-
target_compile_options(rtde_parser_tests PRIVATE ${CXX11_FLAG})
59+
target_compile_options(rtde_parser_tests PRIVATE ${CXX17_FLAG})
5360
target_include_directories(rtde_parser_tests PRIVATE ${GTEST_INCLUDE_DIRS})
5461
target_link_libraries(rtde_parser_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
5562
gtest_add_tests(TARGET rtde_parser_tests

tests/test_rtde_data_package.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2+
3+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
4+
// Copyright 2020 FZI Forschungszentrum Informatik
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// -- END LICENSE BLOCK ------------------------------------------------
18+
19+
//----------------------------------------------------------------------
20+
/*!\file
21+
*
22+
* \author Felix Exner [email protected]
23+
* \date 2020-09-11
24+
*
25+
*/
26+
//----------------------------------------------------------------------
27+
28+
#include <gtest/gtest.h>
29+
30+
#include <ur_client_library/rtde/data_package.h>
31+
32+
using namespace urcl;
33+
34+
TEST(rtde_data_package, serialize_pkg)
35+
{
36+
std::vector<std::string> recipe{ "speed_slider_mask" };
37+
rtde_interface::DataPackage package(recipe);
38+
package.initEmpty();
39+
40+
uint32_t value = 1;
41+
package.setData("speed_slider_mask", value);
42+
43+
uint8_t buffer[4096];
44+
package.setRecipeID(1);
45+
size_t size = package.serializePackage(buffer);
46+
47+
EXPECT_EQ(size, 8);
48+
49+
uint8_t expected[] = { 0x0, 0x08, 0x55, 0x01, 0x00, 0x00, 0x00, 0x01 };
50+
std::cout << "Serialized buffer: " << std::endl;
51+
for (size_t i = 0; i < size; ++i)
52+
{
53+
EXPECT_EQ(buffer[i], expected[i]);
54+
}
55+
std::cout << std::endl;
56+
}
57+
58+
int main(int argc, char* argv[])
59+
{
60+
::testing::InitGoogleTest(&argc, argv);
61+
62+
return RUN_ALL_TESTS();
63+
}

0 commit comments

Comments
 (0)