refactor: core-fmt and core-ostream modules merged with core

This commit is contained in:
Mateusz Pusz
2024-01-06 08:51:01 +01:00
parent 614d82dece
commit fb8552b1d9
28 changed files with 80 additions and 198 deletions

View File

@ -15,7 +15,7 @@
along with this program. If not, see http://www.gnu.org/licenses./
*/
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <iostream>
#ifdef MP_UNITS_MODULES
import mp_units;

View File

@ -15,7 +15,7 @@
along with this program. If not, see http://www.gnu.org/licenses./
*/
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <iostream>
#include <type_traits>
#ifdef MP_UNITS_MODULES

View File

@ -24,7 +24,7 @@
#include <iostream>
#include <map>
#ifdef MP_UNITS_MODULES
import mp_units.core_io;
import mp_units.core;
#else
#include <mp-units/ostream.h>
#include <mp-units/quantity.h>

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <iostream>
#include <string_view>
#ifdef MP_UNITS_MODULES

View File

@ -21,7 +21,7 @@
// SOFTWARE.
#include "glide_computer_lib.h"
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <array>
#include <exception>
#include <iostream>

View File

@ -25,7 +25,7 @@
// !!! renders correctly in the documentation "Examples" section. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <iostream>
#ifdef MP_UNITS_MODULES
import mp_units;

View File

@ -23,7 +23,7 @@
#pragma once
#include "ranged_representation.h"
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <compare>
#include <limits>
#include <numbers>

View File

@ -23,7 +23,7 @@
#pragma once
#include <gsl/gsl-lite.hpp>
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <ostream>
#include <utility>
#ifdef MP_UNITS_MODULES

View File

@ -22,7 +22,7 @@
#pragma once
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <tuple>
#ifdef MP_UNITS_MODULES
import mp_units;

View File

@ -25,7 +25,7 @@
// !!! renders correctly in the documentation "Examples" section. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <iostream>
#ifdef MP_UNITS_MODULES
import mp_units;

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <iostream>
#include <tuple>
#ifdef MP_UNITS_MODULES

View File

@ -20,7 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <cassert>
#include <chrono>

View File

@ -21,7 +21,7 @@
// SOFTWARE.
#include "geographic.h"
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <cassert>
#include <iostream>
#ifdef MP_UNITS_MODULES

View File

@ -47,13 +47,11 @@ if(${projectPrefix}AS_SYSTEM_HEADERS)
endif()
add_subdirectory(core)
add_subdirectory(core-fmt)
add_subdirectory(core-io)
add_subdirectory(systems)
# project-wide wrapper
add_units_module(
mp-units DEPENDENCIES mp-units::core mp-units::core-io mp-units::core-fmt mp-units::systems
mp-units DEPENDENCIES mp-units::core mp-units::systems
MODULE_INTERFACE_UNIT mp-units.cpp
)

View File

@ -1,43 +0,0 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.19)
option(${projectPrefix}USE_LIBFMT "Enables usage of libfmt instead of the one from 'std'" ON)
message(STATUS "${projectPrefix}USE_LIBFMT: ${${projectPrefix}USE_LIBFMT}")
add_units_module(
core-fmt
DEPENDENCIES mp-units::core
HEADERS include/mp-units/bits/fmt.h include/mp-units/compat_fmt_macros.h include/mp-units/format.h
MODULE_INTERFACE_UNIT mp-units-core-fmt.cpp
)
target_compile_definitions(
mp-units-core-fmt ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}USE_LIBFMT=$<BOOL:${${projectPrefix}USE_LIBFMT}>
)
if(${projectPrefix}USE_LIBFMT)
if(NOT TARGET fmt::fmt)
find_package(fmt CONFIG REQUIRED)
endif()
target_link_libraries(mp-units-core-fmt ${${projectPrefix}TARGET_SCOPE} fmt::fmt)
endif()

View File

@ -1,79 +0,0 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// Formatting library for C++ - the core API for char/UTF-8
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
#pragma once
#include <mp-units/bits/external/hacks.h>
#ifndef MP_UNITS_USE_LIBFMT
#define MP_UNITS_USE_LIBFMT 1
#endif
#if MP_UNITS_USE_LIBFMT
MP_UNITS_DIAGNOSTIC_PUSH
MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW
#include <fmt/format.h>
MP_UNITS_DIAGNOSTIC_POP
#define MP_UNITS_STD_FMT fmt
#define MP_UNITS_FMT_LOCALE(loc) (loc).template get<std::locale>()
#define MP_UNITS_FMT_TO_ARG_ID(arg) static_cast<int>(arg)
#define MP_UNITS_FMT_FROM_ARG_ID(arg) static_cast<size_t>(arg)
// This re-uses code from fmt;
#if FMT_EXCEPTIONS
#if FMT_MSC_VERSION || defined(__NVCC__)
#define MP_UNITS_THROW(x) ::fmt::detail::do_throw(x)
#else
#define MP_UNITS_THROW(x) throw x
#endif
#else
#define MP_UNITS_THROW(x) \
do { \
FMT_ASSERT(false, (x).what()); \
} while (false)
#endif
#else
#ifndef __cpp_lib_format
#error "std::formatting facility not supported"
#endif
#include <format>
#define MP_UNITS_STD_FMT std
#define MP_UNITS_FMT_LOCALE(loc) loc
#define MP_UNITS_FMT_TO_ARG_ID(arg) arg
#define MP_UNITS_FMT_FROM_ARG_ID(arg) arg
#define MP_UNITS_THROW(arg) throw arg
#endif

View File

@ -1,13 +0,0 @@
module;
#include <mp-units/bits/core_gmf.h>
#include <mp-units/compat_fmt_macros.h>
export module mp_units.core_fmt;
export import mp_units.core;
export
{
#include <mp-units/format.h>
}

View File

@ -1,30 +0,0 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.19)
add_units_module(
core-io
DEPENDENCIES mp-units::core
HEADERS include/mp-units/ostream.h
MODULE_INTERFACE_UNIT mp-units-core-io.cpp
)

View File

@ -1,13 +0,0 @@
module;
#include <mp-units/bits/core_gmf.h>
#include <sstream>
export module mp_units.core_io;
export import mp_units.core;
export
{
#include <mp-units/ostream.h>
}

View File

@ -42,6 +42,7 @@ add_units_module(
include/mp-units/bits/core_gmf.h
include/mp-units/bits/dimension_concepts.h
include/mp-units/bits/expression_template.h
include/mp-units/bits/fmt.h
include/mp-units/bits/get_associated_quantity.h
include/mp-units/bits/get_common_base.h
include/mp-units/bits/magnitude.h
@ -63,7 +64,9 @@ add_units_module(
include/mp-units/core.h
include/mp-units/customization_points.h
include/mp-units/dimension.h
include/mp-units/format.h
include/mp-units/math.h
include/mp-units/ostream.h
include/mp-units/quantity.h
include/mp-units/quantity_point.h
include/mp-units/quantity_spec.h
@ -74,6 +77,17 @@ add_units_module(
MODULE_INTERFACE_UNIT mp-units-core.cpp
)
target_compile_definitions(
mp-units-core ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}USE_LIBFMT=$<BOOL:${${projectPrefix}USE_LIBFMT}>
)
if(${projectPrefix}USE_LIBFMT)
if(NOT TARGET fmt::fmt)
find_package(fmt CONFIG REQUIRED)
endif()
target_link_libraries(mp-units-core ${${projectPrefix}TARGET_SCOPE} fmt::fmt)
endif()
if(${projectPrefix}BUILD_CXX_MODULES)
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18)

View File

@ -99,3 +99,50 @@
#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X
#endif
#ifndef MP_UNITS_USE_LIBFMT
#define MP_UNITS_USE_LIBFMT 1
#endif
#if MP_UNITS_USE_LIBFMT
MP_UNITS_DIAGNOSTIC_PUSH
MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW
#include <fmt/format.h>
MP_UNITS_DIAGNOSTIC_POP
#define MP_UNITS_STD_FMT fmt
#define MP_UNITS_FMT_LOCALE(loc) (loc).template get<std::locale>()
#define MP_UNITS_FMT_TO_ARG_ID(arg) static_cast<int>(arg)
#define MP_UNITS_FMT_FROM_ARG_ID(arg) static_cast<size_t>(arg)
// This re-uses code from fmt;
#if FMT_EXCEPTIONS
#if FMT_MSC_VERSION || defined(__NVCC__)
#define MP_UNITS_THROW(x) ::fmt::detail::do_throw(x)
#else
#define MP_UNITS_THROW(x) throw x
#endif
#else
#define MP_UNITS_THROW(x) \
do { \
FMT_ASSERT(false, (x).what()); \
} while (false)
#endif
#else
#ifndef __cpp_lib_format
#error "std::formatting facility not supported"
#endif
#include <format>
#define MP_UNITS_STD_FMT std
#define MP_UNITS_FMT_LOCALE(loc) loc
#define MP_UNITS_FMT_TO_ARG_ID(arg) arg
#define MP_UNITS_FMT_FROM_ARG_ID(arg) arg
#define MP_UNITS_THROW(arg) throw arg
#endif

View File

@ -30,7 +30,7 @@
#pragma once
#include <gsl/gsl-lite.hpp>
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/bits/external/hacks.h>
#include <concepts>
#include <limits>
#include <string_view>

View File

@ -27,7 +27,9 @@
#include <mp-units/concepts.h>
#include <mp-units/customization_points.h>
#include <mp-units/dimension.h>
#include <mp-units/format.h>
#include <mp-units/math.h>
#include <mp-units/ostream.h>
#include <mp-units/quantity.h>
#include <mp-units/quantity_point.h>
#include <mp-units/quantity_spec.h>

View File

@ -21,7 +21,7 @@
// SOFTWARE.
#include <catch2/matchers/catch_matchers_templated.hpp>
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <algorithm>
#ifdef MP_UNITS_MODULES
import mp_units;

View File

@ -22,7 +22,7 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_exception.hpp>
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <iomanip>
#include <limits>
#include <locale>

View File

@ -21,7 +21,7 @@
// SOFTWARE.
#include <catch2/catch_test_macros.hpp>
#include <mp-units/compat_fmt_macros.h>
#include <mp-units/compat_macros.h>
#include <cmath>
#include <matrix>
#ifdef MP_UNITS_MODULES