Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/actions/install-router-subpackage-windows/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Install DDS Router subpackages
description: Install and setup DDS Router subpackages for linking and building application in Windows
inputs:
cmake_extra_args:
description: 'Specifies cmake arguments different from default'
required: false
default: ' '
cmake_build_type:
description: 'Specifies the build type on single-configuration generators'
required: true
Expand All @@ -17,6 +21,7 @@ runs:
- run: >
cmake -DCMAKE_PREFIX_PATH='C:\Program Files\gtest;C:\Program Files\yamlcpp;C:\Program Files;${{ github.workspace }}\..\fastdds\install' `
-DCMAKE_CXX_FLAGS="/WX /EHsc" -DBUILD_TOOL_TESTS=ON -DBUILD_LIBRARY_TESTS=ON `
${{ inputs.cmake_extra_args }} `
-B build\${{ inputs.subpackage }} -A x64 -T host=x64 DDS-Router/${{ inputs.subpackage_dir }};
cmake --build build\${{ inputs.subpackage }} --config ${{ inputs.cmake_build_type }} --target install;

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ jobs:
subpackage: ddsrouter_cmake
subpackage_dir: ddsrouter_cmake

# This is needed for windows 2019 to use /Zc:preprocessor to use c++ std preprocessor for ENUMERATION_BUILDER
# due to a windows 2019 SDK non bug
- name: Set environment variables for Windows 2019 build
run: |
echo ("W2019_CMAKE_EXTRA_ARGS=-DCMAKE_SYSTEM_VERSION=10.0.19041.0") >> $env:GITHUB_ENV
if: contains( matrix.windows-version , '2019')

- name: Install ddsrouter_utils
uses: ./DDS-Router/.github/actions/install-router-subpackage-windows
with:
cmake_extra_args: ${{ env.W2019_CMAKE_EXTRA_ARGS }}
cmake_build_type: ${{ matrix.cmake-config }}
subpackage: ddsrouter_utils
subpackage_dir: ddsrouter_utils
Expand Down
3 changes: 3 additions & 0 deletions ddsrouter_cmake/cmake/cpp_common/configure_project_cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ macro(configure_project_cpp)
activate_code_coverage()
endif()

# Set custom C++ Flags
custom_cpp_flags()

# Finish macro
message(STATUS "C++ Project ${MODULE_NAME_LARGE} configured.")

Expand Down
28 changes: 28 additions & 0 deletions ddsrouter_cmake/cmake/cpp_common/cpp_flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# 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.

###############################################################################
# CMake Build Type
###############################################################################

# Set custom CMAKE_CXX_FLAGS
macro(custom_cpp_flags)

# Only for windows
if(MSVC OR MSVC_IDE)
# Set standard preprocessor
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:preprocessor")
endif()

endmacro()
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_HPP_
#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_HPP_

#include <ddsrouter_utils/macros.hpp>
#include <ddsrouter_utils/macros/macros.hpp>

#include <ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp>

Expand Down
2 changes: 1 addition & 1 deletion ddsrouter_utils/include/ddsrouter_utils/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Use FastDDS log
#include <fastdds/dds/log/Log.hpp>

#include <ddsrouter_utils/macros.hpp>
#include <ddsrouter_utils/macros/macros.hpp>

namespace eprosima {
namespace ddsrouter {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

/**
* @file macros.hpp
*
* This file contains constant values common for the whole project
*/

#ifndef _DDSROUTERUTILS_MACROS_CUSTOMENUMERATION_HPP_
#define _DDSROUTERUTILS_MACROS_CUSTOMENUMERATION_HPP_

#include <string>
#include <array>

#include <ddsrouter_utils/exception/InitializationException.hpp>
#include <ddsrouter_utils/macros/macros.hpp>
#include <ddsrouter_utils/macros/recursive_macros.hpp>

namespace eprosima {
namespace ddsrouter {
namespace utils {

/**
* @brief This macro creates a Custom Enumeration with auxiliary functions and variables.
*
* An enumeration built with ENUEMERATION_BUILDER has:
* - enum class with name \c enumeration_name and N values, one for each extra argument, and with that exact name.
* - array called \c nammes_<enumeration_name> with the names of each element of the enumeration
* as strings of the enum value.
* - \c to_string method to get the string associated with an enumeration value.
* - \c from_string_<enumeration_name> method that gives enumeration value from string name.
* - operator << for each enumeration value using to_string .
* - \c N_VALUES_<enumeration_name> unsigned int to get the number of elements in the enumeration.
*
* @arg enumeration_name it sets the enum class name and is used to name variables and methods.
* @arg extra_arguments each of the elements of the enum class. Their conversion to string would use this same name.
*
* @note empty custom enumerations are not allowed, even when empty enum class are.
*
* @example
* ENUMERATION_BUILDER(CustomEnum, el1, el2);
* CustomEnum my_value = CustomEnum::el1; // Set my_value as el1 = 0
* my_value = from_string_CustomEnum("el2"); // Set my_value as el2 = 1
* to_string(my_value); // = "el2"
*/
#define ENUMERATION_BUILDER(enumeration_name, ...) \
\
/* Forbid empty enumerations */ \
static_assert( COUNT_ARGUMENTS(__VA_ARGS__), "Empty Enumerations are not allowed."); \
\
/* Declare enumeration */ \
enum class enumeration_name {__VA_ARGS__ \
}; \
\
/* Initialize name arrays */ \
const std::array<std::string, COUNT_ARGUMENTS(__VA_ARGS__)> names_ ## enumeration_name = \
{ APPLY_MACRO_FOR_EACH(STRINGIFY_WITH_COMMA, __VA_ARGS__) }; \
\
/* To string method */ \
const std::string& to_string(const enumeration_name& e) \
{ return names_ ## enumeration_name[static_cast<int>(e)]; } \
\
/* From string */ \
enumeration_name from_string_ ## enumeration_name(const std::string& s) \
{ \
for (int i = 0; i < COUNT_ARGUMENTS(__VA_ARGS__); i++) \
if (names_ ## enumeration_name[i] == s)return static_cast<enumeration_name>(i); \
throw eprosima::ddsrouter::utils::InitializationException( \
STR_ENTRY << "Not correct name " << s << " for Enum " << STRINGIFY(enumeration_name) << "."); \
} \
\
/* Serialization operation */ \
std::ostream& operator <<(std::ostream& os, const enumeration_name& e) { os << to_string(e); return os; } \
\
/* Number of elements in enumeration */ \
constexpr const unsigned int N_VALUES_ ## enumeration_name = COUNT_ARGUMENTS(__VA_ARGS__);


} /* namespace utils */
} /* namespace ddsrouter */
} /* namespace eprosima */

#endif /* _DDSROUTERUTILS_MACROS_CUSTOMENUMERATION_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,58 @@
* This file contains constant values common for the whole project
*/

#ifndef _DDSROUTERUTILS_MACROS_HPP_
#define _DDSROUTERUTILS_MACROS_HPP_
#ifndef _DDSROUTERUTILS_MACROS_MACROS_HPP_
#define _DDSROUTERUTILS_MACROS_MACROS_HPP_

#include <type_traits>

namespace eprosima {
namespace ddsrouter {
namespace utils {

/////////////////////////
// FORMAT
/////////////////////////

/**
* @brief Get string of the argument passed to the macro
*
* @example
* STRINGIFY(value) = "value"
*/
#define STRINGIFY(x) #x

//! Same as \c STRINGIFY but adding a comma "," at the end
#define STRINGIFY_WITH_COMMA(x) #x,


/////////////////////////
// TYPES
/////////////////////////

/**
* @brief Force the specialization type of a template to be a subclass of a Class.
*
* @example
* FORCE_TEMPLATE_SUBCLASS(A, B) = static assert <=> B not inherit from A
*
* @param base parent class that \c derived must inherit.
* @param derived specialization class.
*/
#define FORCE_TEMPLATE_SUBCLASS(base, derived) \
static_assert(std::is_base_of<base, derived>::value, STRINGIFY(derived) " class not derived from " STRINGIFY(base))

// TODO: probably in the future is needed to create a utils method that transforms this name to a human reasonable name
/**
* @brief Get string of the name of the CPP Data Type of the argument
*
* @example
* STRINGIFY(int) = "j"
* STRINGIFY(string) = "NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE"
*/
#define TYPE_NAME(x) typeid(x).name()

} /* namespace utils */
} /* namespace ddsrouter */
} /* namespace eprosima */

#endif /* _DDSROUTERUTILS_MACROS_HPP_ */
#endif /* _DDSROUTERUTILS_MACROS_MACROS_HPP_ */
115 changes: 115 additions & 0 deletions ddsrouter_utils/include/ddsrouter_utils/macros/recursive_macros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

/**
* @file recursive_macros.hpp
*
* This file contains constant values common for the whole project
*/

#ifndef _DDSROUTERUTILS_MACROS_RECURSIVEMACROS_HPP_
#define _DDSROUTERUTILS_MACROS_RECURSIVEMACROS_HPP_

#include <ddsrouter_utils/macros/macros.hpp>

namespace eprosima {
namespace ddsrouter {
namespace utils {

/////////////////////////
// COUNT ARGUMENTS
/////////////////////////

/**
* @brief Get 11th macro.
*
* @note This macro is used in \c COUNT_ARGUMENT macro.
*/
#define _ELEVENTH_ARGUMENT(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, ...) \
a11

/**
* @brief Count number of arguments in a variadic macro with maximum 9 variables
*
* @note This is an auxiliary macro that encapsulates the funtionality of \c COUNT_ARGUMENTS so that macro
* could be changed to a higher value without breaking API.
*
* @note \c dummy value is required to non argument calls.
*/
#define _COUNT_ARGUMENTS__UP_TO_NINE(...) \
_ELEVENTH_ARGUMENT(dummy, ## __VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

/**
* @brief Count number of arguments in a variadic macro
*
* @warning This macro only allows up to 9 values.
*
* @note if more arguments required, change \c _ELEVENTH_ARGUMENT for a higher one.
*
* @example
* COUNT_ARGUMENTS(el1, el2, el3) = 3
*/
#define COUNT_ARGUMENTS(...) \
_COUNT_ARGUMENTS__UP_TO_NINE(__VA_ARGS__)


/////////////////////////
// FOR EACH
/////////////////////////

/**
* @brief These macros allow to create an iterative APPLY_MACRO_FOR_EACH loop over every argument.
*
* Each item of form \c _FE_N allow to evaluate the function \c ACTION for the next \c N arguments.
*/
#define _FE_1(ACTION, X) ACTION(X)
#define _FE_2(ACTION, X, ...) ACTION(X) _FE_1(ACTION, __VA_ARGS__)
#define _FE_3(ACTION, X, ...) ACTION(X) _FE_2(ACTION, __VA_ARGS__)
#define _FE_4(ACTION, X, ...) ACTION(X) _FE_3(ACTION, __VA_ARGS__)
#define _FE_5(ACTION, X, ...) ACTION(X) _FE_4(ACTION, __VA_ARGS__)
#define _FE_6(ACTION, X, ...) ACTION(X) _FE_5(ACTION, __VA_ARGS__)
#define _FE_7(ACTION, X, ...) ACTION(X) _FE_6(ACTION, __VA_ARGS__)
#define _FE_8(ACTION, X, ...) ACTION(X) _FE_7(ACTION, __VA_ARGS__)
#define _FE_9(ACTION, X, ...) ACTION(X) _FE_8(ACTION, __VA_ARGS__)
//... repeat as needed

/**
* @brief Get the 9th argument
*
* @note this is useful for \c APPLY_MACRO_FOR_EACH macro.
*/
#define _GET_NINTH_ARGUMENT(_1, _2, _3, _4, _5, _6, _7, _8, _9, NAME, ...) \
NAME

#define _APPLY_MACRO_FOR_EACH__UP_TO_NINE(action, ...) \
_GET_NINTH_ARGUMENT(__VA_ARGS__, _FE_9, _FE_8, _FE_7, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1)(action, __VA_ARGS__)

/**
* @brief Execute \c action (must be a macro) for every argument after it.
*
* @warning This macro only allows up to 9 values.
*
* @note if more arguments required, change \c _APPLY_MACRO_FOR_EACH__UP_TO_NINE for a higher one.
*
* @example
* APPLY_MACRO_FOR_EACH(print, el1, el2, el3) => print(el1); print(el2); print(el3);
*/
#define APPLY_MACRO_FOR_EACH(action, ...) \
_APPLY_MACRO_FOR_EACH__UP_TO_NINE(action, __VA_ARGS__)

} /* namespace utils */
} /* namespace ddsrouter */
} /* namespace eprosima */

#endif /* _DDSROUTERUTILS_MACROS_RECURSIVEMACROS_HPP_ */
2 changes: 1 addition & 1 deletion ddsrouter_utils/include/ddsrouter_utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <string>
#include <vector>

#include <ddsrouter_utils/macros.hpp>
#include <ddsrouter_utils/macros/macros.hpp>
#include <ddsrouter_utils/Formatter.hpp>
#include <ddsrouter_utils/library/library_dll.h>

Expand Down
1 change: 1 addition & 0 deletions ddsrouter_utils/test/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Add test subdirectories
add_subdirectory(event)
add_subdirectory(exception)
add_subdirectory(macros)
add_subdirectory(math)
add_subdirectory(memory)
add_subdirectory(return_code)
Expand Down
Loading