Skip to content

Commit

Permalink
Merge remote-tracking branch 'remote2/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 15, 2023
2 parents 0f1c1f1 + 34ba2a0 commit e3b10c3
Show file tree
Hide file tree
Showing 21 changed files with 907 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/module-mola-yaml.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _mola-yaml:

====================
Module: mola-yaml
====================

YAML helper C++ library common to all MOLA modules, released under BSD-3-Clause.

This module implements the YAML extensions explained in: :ref:`yaml_slam_cfg_file`.
83 changes: 83 additions & 0 deletions mola_yaml/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Language: Cpp
BasedOnStyle: Google
# ---
#AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak # Values: Align, DontAlign, AlwaysBreak
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
#AlignEscapedNewlinesLeft: true
#AlignOperands: false
AlignTrailingComments: false # Should be off, causes many dummy problems!!
#AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
#AllowShortCaseLabelsOnASingleLine: false
#AllowShortFunctionsOnASingleLine: Empty
#AllowShortIfStatementsOnASingleLine: false
#AllowShortLoopsOnASingleLine: false
#AlwaysBreakAfterDefinitionReturnType: None
#AlwaysBreakAfterReturnType: None
#AlwaysBreakBeforeMultilineStrings: true
#AlwaysBreakTemplateDeclarations: true
#BinPackArguments: false
#BinPackParameters: false
#BraceWrapping:
#AfterClass: false
#AfterControlStatement: false
#AfterEnum: false
#AfterFunction: false
#AfterNamespace: false
#AfterObjCDeclaration: false
#AfterStruct: false
#AfterUnion: false
#BeforeCatch: false
#BeforeElse: true
#IndentBraces: false
#BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
#BreakBeforeTernaryOperators: true
#BreakConstructorInitializersBeforeComma: false
ColumnLimit: 80
#CommentPragmas: ''
#ConstructorInitializerAllOnOneLineOrOnePerLine: true
#ConstructorInitializerIndentWidth: 4
#ContinuationIndentWidth: 4
#Cpp11BracedListStyle: true
#DerivePointerAlignment: false
#DisableFormat: false
#ExperimentalAutoDetectBinPacking: false
##FixNamespaceComments: true # Not applicable in 3.8
#ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
#IncludeCategories:
#- Regex: '.*'
#Priority: 1
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: true
#KeepEmptyLinesAtTheStartOfBlocks: true
#MacroBlockBegin: ''
#MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
#PenaltyBreakBeforeFirstCallParameter: 19
#PenaltyBreakComment: 300
#PenaltyBreakFirstLessLess: 120
#PenaltyBreakString: 1000
#PenaltyExcessCharacter: 1000000
#PenaltyReturnTypeOnItsOwnLine: 200
DerivePointerAlignment: false
#PointerAlignment: Left
ReflowComments: true # Should be true, otherwise clang-format doesn't touch comments
SortIncludes: true
#SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
#SpaceBeforeParens: ControlStatements
#SpaceInEmptyParentheses: false
#SpacesBeforeTrailingComments: 2
#SpacesInAngles: false
#SpacesInContainerLiterals: true
#SpacesInCStyleCastParentheses: false
#SpacesInParentheses: false
#SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never # Available options are Never, Always, ForIndentation
15 changes: 15 additions & 0 deletions mola_yaml/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package mola_yaml
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0.2.2 (2023-09-08)
------------------
* Fix package name in docs
* Contributors: Jose Luis Blanco-Claraco

0.2.1 (2023-09-02)
------------------

0.2.0 (2023-08-24)
------------------
* First public release as ROS 2 package.
46 changes: 46 additions & 0 deletions mola_yaml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ------------------------------------------------------------------------------
# A Modular Optimization framework for Localization and mApping
# (MOLA)
#
# Copyright (C) 2018-2023, Jose Luis Blanco-Claraco, contributors (AUTHORS.md)
# All rights reserved.
# Released under GNU GPL v3. See LICENSE file
# ------------------------------------------------------------------------------

# Minimum CMake vesion: limited by CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
cmake_minimum_required(VERSION 3.4)

# Tell CMake we'll use C++ for use in its tests/flags
project(mola_yaml LANGUAGES CXX)

# MOLA CMake scripts: "mola_xxx()"
find_package(mola_common REQUIRED)

# find dependencies:
find_package(MRPT 2.1.0 REQUIRED COMPONENTS containers system)

# define lib:
file(GLOB_RECURSE LIB_SRCS src/*.cpp src/*.h)
file(GLOB_RECURSE LIB_PUBLIC_HDRS include/*.h)

# Use C++17 filesystem lib:
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(Filesystem REQUIRED)

mola_add_library(
TARGET ${PROJECT_NAME}
SOURCES ${LIB_SRCS} ${LIB_PUBLIC_HDRS}
PUBLIC_LINK_LIBRARIES
mrpt::containers
PRIVATE_LINK_LIBRARIES
mrpt::system
CXX::Filesystem # the C++>=17 std lib
CMAKE_DEPENDENCIES
mrpt-containers
mrpt-system
)

# -----------------------
# define tests:
enable_testing()
add_subdirectory(tests)
29 changes: 29 additions & 0 deletions mola_yaml/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2021, The MOLA SLAM framework
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 changes: 11 additions & 0 deletions mola_yaml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# mola_yaml
YAML helper library common to MOLA modules. A C++ library to parse YAML files with extended syntax allowing variable replacing, recursive `include`s of other YAML files, etc.

## Build and install
Refer to the [root MOLA repository](https://github.com/MOLAorg/mola).

## Docs and examples
See this package page [in the documentation](https://docs.mola-slam.org/latest/modules.html).

## License
This package is released under the BSD-3 license.
75 changes: 75 additions & 0 deletions mola_yaml/cmake/FindFilesystem.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This is from https://github.com/vector-of-bool/pitchfork/blob/develop/cmake/FindFilesystem.cmake

include(CMakePushCheckState)
include(CheckIncludeFileCXX)
include(CheckCXXSourceCompiles)

cmake_push_check_state(RESET)

# this seems not to affect check_cxx_source_compiles()...
set(CMAKE_CXX_STANDARD 17)

if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
set(CMAKE_REQUIRED_LINK_OPTIONS -std=c++17)
set(CMAKE_REQUIRED_FLAGS -std=c++17)
endif()

set(have_fs FALSE)

check_include_file_cxx("filesystem" HAVE_STD_FILESYSTEM)
check_include_file_cxx("experimental/filesystem" HAVE_STD_EXPERIMENTAL_FILESYSTEM)

if(HAVE_STD_FILESYSTEM)
set(have_fs TRUE)
set(header filesystem)
set(namespace std::filesystem)
elseif(HAVE_STD_EXPERIMENTAL_FILESYSTEM)
set(have_fs TRUE)
set(header experimental/filesystem)
set(namespace std::experimental::filesystem)
endif()

string(CONFIGURE [[
#include <@header@>

int main() {
auto cwd = @namespace@::current_path();
return cwd.string().size();
}
]] code @ONLY)

check_cxx_source_compiles("${code}" CAN_COMPILE_FS_WITHOUT_LINK)

if(NOT CAN_COMPILE_FS_WITHOUT_LINK)
set(CMAKE_REQUIRED_LIBRARIES -lstdc++fs)
check_cxx_source_compiles("${code}" CAN_COMPILE_FS_WITH_LINK)
endif()

cmake_pop_check_state()

if(have_fs)
add_library(CXX::Filesystem INTERFACE IMPORTED)
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
target_compile_definitions(CXX::Filesystem INTERFACE STD_FS_IS_EXPERIMENTAL=$<NOT:$<BOOL:${HAVE_STD_FILESYSTEM}>>)
else()
set_property(TARGET CXX::Filesystem APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS STD_FS_IS_EXPERIMENTAL=$<NOT:$<BOOL:${HAVE_STD_FILESYSTEM}>>)
endif()

if(CAN_COMPILE_FS_WITHOUT_LINK)
# Nothing to add...
elseif(CAN_COMPILE_FS_WITH_LINK)
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
target_link_libraries(CXX::Filesystem INTERFACE -lstdc++fs)
else()
set_property(TARGET CXX::Filesystem APPEND PROPERTY INTERFACE_LINK_LIBRARIES stdc++fs)
endif()
else()
message(WARNING "Failed to link a filesystem library, although we found the headers...?")
endif()
set(Filesystem_FOUND TRUE CACHE BOOL "" FORCE)
else()
set(Filesystem_FOUND FALSE CACHE BOOL "" FORCE)
if(Filesystem_FIND_REQUIRED)
message(FATAL_ERROR "No C++ support for std::filesystem")
endif()
endif()
26 changes: 26 additions & 0 deletions mola_yaml/include/mola_yaml/macro_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* -------------------------------------------------------------------------
* A Modular Optimization framework for Localization and mApping (MOLA)
* Copyright (C) 2018-2023 Jose Luis Blanco, University of Almeria
* See LICENSE for license information.
* ------------------------------------------------------------------------- */
/**
* @file macro_helpers.h
* @brief C preprocessor helpers
* @author Jose Luis Blanco Claraco
* @date Jan 11, 2019
*/
#pragma once

// The following is taken from a great answer here:
// https://stackoverflow.com/a/26408195/1631514

// get number of arguments with MOLA_NARG
#define MOLA_NARG(...) MOLA_NARG_I_(__VA_ARGS__, MOLA_RSEQ_N())
#define MOLA_NARG_I_(...) MOLA_ARG_N(__VA_ARGS__)
#define MOLA_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
#define MOLA_RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0

// general definition for any function name
#define MOLA_VFUNC_(name, n) name##n
#define MOLA_VFUNC(name, n) MOLA_VFUNC_(name, n)
#define VFUNC(func, ...) MOLA_VFUNC(func, MOLA_NARG(__VA_ARGS__))(__VA_ARGS__)
Loading

0 comments on commit e3b10c3

Please sign in to comment.