Skip to content

Commit b299d5b

Browse files
committed
Ported mrpt_containers
1 parent 60c41dc commit b299d5b

File tree

10 files changed

+216
-138
lines changed

10 files changed

+216
-138
lines changed

cmakemodules/script_libfyaml.cmake

-66
This file was deleted.

modules/mrpt_common/cmake/mrpt_cmake_functions.cmake

+12-6
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,13 @@ function(mrpt_set_target_build_options TARGETNAME HEADERS_ONLY_LIBRARY)
217217
endfunction()
218218

219219
# -----------------------------------------------------------------------------
220-
# mrpt_configure_library(target [dep1 dep2...])
220+
# mrpt_configure_library(target HEADERS_ONLY ADDITIONAL_EXPORTS [CMAKE_DEPS...])
221221
#
222222
# Define a consistent install behavior for cmake-based library project:
223223
# -----------------------------------------------------------------------------
224-
function(mrpt_configure_library TARGETNAME HEADERS_ONLY_LIBRARY)
224+
function(mrpt_configure_library TARGETNAME HEADERS_ONLY_LIBRARY ADDITIONAL_EXPORT_TARGETS CMAKE_DEPS)
225+
226+
message(STATUS "HEADERS_ONLY_LIBRARY: ${HEADERS_ONLY_LIBRARY}")
225227

226228
# Public hdrs interface:
227229
if (HEADERS_ONLY_LIBRARY)
@@ -230,6 +232,7 @@ function(mrpt_configure_library TARGETNAME HEADERS_ONLY_LIBRARY)
230232
$<INSTALL_INTERFACE:include>
231233
)
232234
else()
235+
message(STATUS "XXX: ${CMAKE_CURRENT_SOURCE_DIR}/include")
233236
target_include_directories(${TARGETNAME} PUBLIC
234237
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
235238
$<INSTALL_INTERFACE:include>
@@ -256,7 +259,8 @@ function(mrpt_configure_library TARGETNAME HEADERS_ONLY_LIBRARY)
256259

257260
# Install lib:
258261
if (NOT HEADERS_ONLY_LIBRARY)
259-
install(TARGETS ${TARGETNAME} EXPORT ${TARGETNAME}-targets
262+
install(TARGETS ${TARGETNAME} ${ADDITIONAL_EXPORT_TARGETS}
263+
EXPORT ${TARGETNAME}-targets
260264
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
261265
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
262266
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
@@ -306,7 +310,7 @@ function(mrpt_configure_library TARGETNAME HEADERS_ONLY_LIBRARY)
306310
#add_library(mrpt::${TARGETNAME} ALIAS ${TARGETNAME})
307311

308312
# And generate the -config.cmake file:
309-
set(ALL_DEPS_LIST ${ARGN}) # used in xxx-config.cmake.in
313+
set(ALL_DEPS_LIST "${CMAKE_DEPS}") # used in xxx-config.cmake.in
310314
set(MRPT_MODULE_NAME ${TARGETNAME})
311315
configure_file(
312316
"${_MRPTCOMMON_MODULE_BASE_DIR}/mrpt-xxx-config.cmake.in"
@@ -416,6 +420,7 @@ endfunction()
416420
# [PUBLIC_LINK_LIBRARIES lib1 lib2]
417421
# [PRIVATE_LINK_LIBRARIES lib3 lib4]
418422
# [CMAKE_DEPENDENCIES pkg1 pkg2]
423+
# [ADDITIONAL_EXPORT_TARGETS target1 target2]
419424
# )
420425
#
421426
# Defines a MRPT library. `CMAKE_DEPENDENCIES` enumerates those packages
@@ -424,7 +429,7 @@ endfunction()
424429
function(mrpt_add_library)
425430
set(options HEADERS_ONLY_LIBRARY)
426431
set(oneValueArgs TARGET)
427-
set(multiValueArgs SOURCES PUBLIC_LINK_LIBRARIES PRIVATE_LINK_LIBRARIES CMAKE_DEPENDENCIES)
432+
set(multiValueArgs SOURCES PUBLIC_LINK_LIBRARIES PRIVATE_LINK_LIBRARIES CMAKE_DEPENDENCIES ADDITIONAL_EXPORT_TARGETS)
428433
cmake_parse_arguments(MRPT_ADD_LIBRARY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
429434

430435
# Remove _LIN files when compiling under Windows, and _WIN files when compiling under Linux.
@@ -479,7 +484,8 @@ function(mrpt_add_library)
479484
endif()
480485

481486
# Define common flags:
482-
mrpt_configure_library(${MRPT_ADD_LIBRARY_TARGET} ${MRPT_ADD_LIBRARY_CMAKE_DEPENDENCIES} ${MRPT_ADD_LIBRARY_HEADERS_ONLY_LIBRARY})
487+
#mrpt_configure_library(target HEADERS_ONLY ADDITIONAL_EXPORTS [CMAKE_DEPS...])
488+
mrpt_configure_library(${MRPT_ADD_LIBRARY_TARGET} "${MRPT_ADD_LIBRARY_HEADERS_ONLY_LIBRARY}" "${MRPT_ADD_LIBRARY_ADDITIONAL_EXPORT_TARGETS}" "${MRPT_ADD_LIBRARY_CMAKE_DEPENDENCIES}")
483489

484490
# lib Dependencies:
485491
target_link_libraries(${MRPT_ADD_LIBRARY_TARGET}
+79-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,86 @@
1+
# ------------------------------------------------------------------------------
2+
# Mobile Robot Programming Toolkit (MRPT)
3+
#
4+
# Copyright (c) 2005-2025, Jose Luis Blanco-Claraco, contributors (see Git history)
5+
# All rights reserved.
6+
# Released under BSD-3 license. See LICENSE file
7+
# ------------------------------------------------------------------------------
18

2-
include(${MRPT_SOURCE_DIR}/cmakemodules/script_libfyaml.cmake REQUIRED) # Defines embedded version of libfyaml
9+
cmake_minimum_required(VERSION 3.16)
310

4-
#---------------------------------------------
5-
# Macro declared in "DeclareMRPTLib.cmake":
6-
#---------------------------------------------
7-
define_mrpt_lib(
8-
# Lib name
9-
containers
10-
# Dependencies
11-
mrpt-core
12-
mrpt-typemeta
13-
)
11+
# Tell CMake we'll use C++ for use in its tests/flags
12+
project(mrpt_containers LANGUAGES C CXX)
1413

15-
# extra dependencies required by unit tests in this module:
16-
set_property(GLOBAL PROPERTY mrpt_containers_UNIT_TEST_EXTRA_DEPS "mrpt-random;mrpt-poses;mrpt-io")
14+
# MRPT CMake scripts: "mrpt_xxx()"
15+
find_package(mrpt_common REQUIRED)
16+
find_package(mrpt_core REQUIRED)
17+
find_package(mrpt_typemeta REQUIRED)
1718

18-
if(BUILD_mrpt-containers)
19+
include(./cmake/find_libfyaml.cmake REQUIRED) # Defines embedded version of libfyaml
1920

20-
if (TARGET mrpt_libfyaml)
21-
target_link_libraries(containers PRIVATE mrpt_libfyaml)
22-
endif()
21+
# define lib:
22+
set(LIB_SRCS
23+
src/ts_hash_map_unittest.cpp
24+
src/vector_with_small_size_optimization_unittest.cpp
25+
src/poly_ptr_unittest.cpp
26+
src/containers-precomp.cpp
27+
src/ts_hash_map.cpp
28+
src/bimap_unittest.cpp
29+
src/CDynamicGrid_unittest.cpp
30+
src/circularbuffer_unittest.cpp
31+
src/yaml_unittest.cpp
32+
src/visit_each_unittest.cpp
33+
src/yaml.cpp
34+
src/CDynamicGrid.cpp
35+
src/find_closest_unittest.cpp
36+
)
2337

38+
set(LIB_PUBLIC_HDRS
39+
include/mrpt/containers/vector_with_small_size_optimization.h
40+
include/mrpt/containers/internal_yaml_fwrds.h
41+
include/mrpt/containers/deepcopy_ptr.h
42+
include/mrpt/containers/ts_hash_map.h
43+
include/mrpt/containers/CDynamicGrid3D.h
44+
include/mrpt/containers/CThreadSafeQueue.h
45+
include/mrpt/containers/deepcopy_poly_ptr.h
46+
include/mrpt/containers/bimap.h
47+
include/mrpt/containers/yaml_frwd.h
48+
include/mrpt/containers/traits_map.h
49+
include/mrpt/containers/ci_less.h
50+
include/mrpt/containers/NonCopiableData.h
51+
include/mrpt/containers/CommentPosition.h
52+
include/mrpt/containers/map_as_vector.h
53+
include/mrpt/containers/copy_container_typecasting.h
54+
include/mrpt/containers/ValueCommentPair.h
55+
include/mrpt/containers/stl_containers_utils.h
56+
include/mrpt/containers/MT_buffer.h
57+
include/mrpt/containers/YamlEmitOptions.h
58+
include/mrpt/containers/visit_each.h
59+
include/mrpt/containers/list_searchable.h
60+
include/mrpt/containers/ContainerReadOnlyProxyAccessor.h
61+
include/mrpt/containers/yaml.h
62+
include/mrpt/containers/PerThreadDataHolder.h
63+
include/mrpt/containers/printf_vector.h
64+
include/mrpt/containers/CDynamicGrid.h
65+
include/mrpt/containers/circular_buffer.h
66+
include/mrpt/containers/find_closest.h
67+
)
68+
69+
mrpt_add_library(
70+
TARGET ${PROJECT_NAME}
71+
SOURCES ${LIB_SRCS} ${LIB_PUBLIC_HDRS}
72+
PUBLIC_LINK_LIBRARIES
73+
mrpt::mrpt_core
74+
mrpt::mrpt_typemeta
75+
# PRIVATE_LINK_LIBRARIES
76+
CMAKE_DEPENDENCIES
77+
mrpt_core
78+
mrpt_typemeta
79+
)
80+
81+
if (TARGET mrpt_libfyaml)
82+
target_link_libraries(${PROJECT_NAME} PRIVATE mrpt_libfyaml)
83+
else()
84+
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${LIBFYAML_INCLUDES})
85+
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBFYAML_LIB})
2486
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ===================================================
2+
# libfyaml
3+
# ===================================================
4+
set(CMAKE_MRPT_HAS_LIBFYAML 0)
5+
set(CMAKE_MRPT_HAS_LIBFYAML_SYSTEM 0)
6+
7+
if (WIN32)
8+
# libfyaml does not support Windows (as of Aug 2020)
9+
set(initial_has_libfyaml OFF)
10+
else()
11+
set(initial_has_libfyaml ON)
12+
endif()
13+
OPTION(MRPT_HAS_LIBFYAML "Use libfyaml, from the system or built-in (for YAML & JSON parsing in mrpt::containers::yaml)" ${initial_has_libfyaml})
14+
unset(initial_has_libfyaml)
15+
16+
if(MRPT_HAS_LIBFYAML)
17+
set(CMAKE_MRPT_HAS_LIBFYAML 1)
18+
19+
# system version found?
20+
find_library(LIBFYAML_LIB NAMES fyaml libfyaml)
21+
find_path(LIBFYAML_INCLUDES NAMES libfyaml.h)
22+
if (LIBFYAML_LIB AND LIBFYAML_INCLUDES)
23+
set(CMAKE_MRPT_HAS_LIBFYAML_SYSTEM 1)
24+
if ($ENV{VERBOSE})
25+
message(STATUS "LIBFYAML_LIB : ${LIBFYAML_LIB}")
26+
message(STATUS "LIBFYAML_INCLUDES : ${LIBFYAML_INCLUDES}")
27+
endif()
28+
else()
29+
# Internal built-in:
30+
include(ExternalProject)
31+
32+
set(LIBFYAML_DIR ${MRPT_SOURCE_DIR}/3rdparty/libfyaml)
33+
set(LIBFYAML_BIN ${MRPT_BINARY_DIR}/3rdparty/libfyaml)
34+
set(LIBFYAML_INSTALL_DIR ${LIBFYAML_BIN}/install)
35+
set(LIBFYAML_INCLUDES ${LIBFYAML_DIR}/include)
36+
37+
set(LIBFYAML_LIB ${LIBFYAML_INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}fyaml${CMAKE_STATIC_LIBRARY_SUFFIX})
38+
39+
ExternalProject_Add(
40+
mrpt_liblibfyaml
41+
PREFIX ${LIBFYAML_BIN}
42+
SOURCE_DIR ${LIBFYAML_DIR}
43+
INSTALL_DIR "${LIBFYAML_INSTALL_DIR}"
44+
CMAKE_ARGS
45+
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
46+
-DBUILD_SHARED_LIBS:BOOL=OFF
47+
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
48+
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
49+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
50+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
51+
BUILD_BYPRODUCTS ${LIBFYAML_LIB}
52+
)
53+
endif()
54+
55+
if (NOT CMAKE_MRPT_HAS_LIBFYAML_SYSTEM)
56+
add_library(mrpt_libfyaml STATIC IMPORTED GLOBAL)
57+
add_dependencies(mrpt_libfyaml mrpt_liblibfyaml)
58+
set_target_properties(mrpt_libfyaml PROPERTIES IMPORTED_LOCATION ${LIBFYAML_LIB})
59+
set_target_properties(mrpt_libfyaml PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${LIBFYAML_INCLUDES})
60+
endif()
61+
62+
endif()

modules/mrpt_containers/include/mrpt/containers/CDynamicGrid.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
#include <string>
1717
#include <vector>
1818

19-
namespace mrpt
20-
{
21-
namespace containers
19+
namespace mrpt::containers
2220
{
2321
namespace internal
2422
{
2523
// Aux class.
2624
struct dynamic_grid_txt_saver
2725
{
26+
dynamic_grid_txt_saver() = default;
27+
virtual ~dynamic_grid_txt_saver() = default;
28+
2829
bool saveToTextFile(const std::string& fileName) const;
2930
virtual unsigned int getSizeX() const = 0;
3031
virtual unsigned int getSizeY() const = 0;
@@ -142,13 +143,13 @@ class CDynamicGrid
142143

143144
// Adjust sizes to adapt them to full sized cells according to the
144145
// resolution:
145-
if (fabs(new_x_min / m_resolution - round(new_x_min / m_resolution)) > 0.05f)
146+
if (fabs(new_x_min / m_resolution - round(new_x_min / m_resolution)) > 0.05)
146147
new_x_min = m_resolution * round(new_x_min / m_resolution);
147-
if (fabs(new_y_min / m_resolution - round(new_y_min / m_resolution)) > 0.05f)
148+
if (fabs(new_y_min / m_resolution - round(new_y_min / m_resolution)) > 0.05)
148149
new_y_min = m_resolution * round(new_y_min / m_resolution);
149-
if (fabs(new_x_max / m_resolution - round(new_x_max / m_resolution)) > 0.05f)
150+
if (fabs(new_x_max / m_resolution - round(new_x_max / m_resolution)) > 0.05)
150151
new_x_max = m_resolution * round(new_x_max / m_resolution);
151-
if (fabs(new_y_max / m_resolution - round(new_y_max / m_resolution)) > 0.05f)
152+
if (fabs(new_y_max / m_resolution - round(new_y_max / m_resolution)) > 0.05)
152153
new_y_max = m_resolution * round(new_y_max / m_resolution);
153154

154155
// Change the map size: Extensions at each side:
@@ -357,5 +358,4 @@ class CDynamicGrid
357358

358359
}; // end of CDynamicGrid<>
359360

360-
} // namespace containers
361-
} // namespace mrpt
361+
} // namespace mrpt::containers

modules/mrpt_containers/include/mrpt/containers/yaml.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ class yaml
226226
bool hasComment(CommentPosition pos) const
227227
{
228228
MRPT_START
229-
int posIndex = static_cast<int>(pos);
230-
ASSERT_GE_(posIndex, 0);
229+
unsigned int posIndex = static_cast<int>(pos);
231230
ASSERT_LT_(posIndex, static_cast<int>(CommentPosition::MAX));
232231
return comments[posIndex].has_value();
233232
MRPT_END
@@ -236,15 +235,19 @@ class yaml
236235
{
237236
MRPT_START
238237
for (const auto& c : comments)
239-
if (c.has_value()) return c.value();
238+
{
239+
if (c.has_value())
240+
{
241+
return c.value();
242+
}
243+
}
240244
THROW_EXCEPTION("Trying to access comment but this node has none.");
241245
MRPT_END
242246
}
243247
const std::string& comment(CommentPosition pos) const
244248
{
245249
MRPT_START
246-
int posIndex = static_cast<int>(pos);
247-
ASSERT_GE_(posIndex, 0);
250+
unsigned int posIndex = static_cast<int>(pos);
248251
ASSERT_LT_(posIndex, static_cast<int>(CommentPosition::MAX));
249252
ASSERTMSG_(
250253
comments[posIndex].has_value(), "Trying to access comment but this node has none.");
@@ -767,7 +770,7 @@ class yaml
767770
{
768771
YamlEmitOptions eo;
769772

770-
int indent = 0;
773+
unsigned int indent = 0;
771774
bool needsNL = false;
772775
bool needsSpace = false;
773776
bool shortFormat = false;
@@ -777,7 +780,7 @@ class yaml
777780
static bool internalPrintNodeAsYAML(
778781
const node_t& p, std::ostream& o, const InternalPrintState& ps);
779782

780-
static void internalPrintDebugStructure(const node_t& p, std::ostream& o, int indent);
783+
static void internalPrintDebugStructure(const node_t& p, std::ostream& o, unsigned int indent);
781784

782785
template <typename T>
783786
void internalPushBack(const T& v);

0 commit comments

Comments
 (0)