Skip to content

Commit

Permalink
refactor(bits): move macros to config/macros.h
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP committed Mar 24, 2022
1 parent 6c2c874 commit fa0b45b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 63 deletions.
82 changes: 82 additions & 0 deletions src/core/include/units/bits/config/macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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.

#pragma once

#include <version>

#if __clang__
#define UNITS_COMP_CLANG __clang_major__
#elif __GNUC__
#define UNITS_COMP_GCC __GNUC__
#define UNITS_COMP_GCC_MINOR __GNUC_MINOR__
#elif _MSC_VER
#define UNITS_COMP_MSVC _MSC_VER
#endif

// Adapted from https://github.com/ericniebler/range-v3/blob/master/include/range/v3/detail/config.hpp#L185.
#define UNITS_PRAGMA(X) _Pragma(#X)
#if !UNITS_COMP_MSVC
#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(GCC diagnostic push)
#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(GCC diagnostic pop)
#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(GCC diagnostic ignored "-Wpragmas")
#define UNITS_DIAGNOSTIC_IGNORE(X) \
UNITS_DIAGNOSTIC_IGNORE_PRAGMAS \
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \
UNITS_PRAGMA(GCC diagnostic ignored X)
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces")
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend")
#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE("-Wshadow")
#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
#else
#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(warning(push))
#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(warning(pop))
#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : 4068))
#define UNITS_DIAGNOSTIC_IGNORE(X) UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : X))
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF UNITS_DIAGNOSTIC_IGNORE(4296)
#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA UNITS_DIAGNOSTIC_IGNORE(4244)
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND
#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE(4459)
#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE UNITS_DIAGNOSTIC_IGNORE(4702)
#endif

#if _LIBCPP_VERSION
#define UNITS_LIBCXX _LIBCPP_VERSION
#endif

#if UNITS_COMP_MSVC || UNITS_COMP_CLANG
#define TYPENAME typename
#else
#define TYPENAME
#endif

#ifdef UNITS_DOWNCAST_MODE
#if UNITS_DOWNCAST_MODE < 0 || UNITS_DOWNCAST_MODE > 2
#error "Invalid UNITS_DOWNCAST_MODE value"
#endif
#else
#define UNITS_DOWNCAST_MODE 1
#endif
8 changes: 0 additions & 8 deletions src/core/include/units/bits/external/downcasting.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@
#include <units/bits/external/hacks.h>
#include <type_traits>

#ifdef UNITS_DOWNCAST_MODE
#if UNITS_DOWNCAST_MODE < 0 || UNITS_DOWNCAST_MODE > 2
#error "Invalid UNITS_DOWNCAST_MODE value"
#endif
#else
#define UNITS_DOWNCAST_MODE 1
#endif

namespace units {

template<typename BaseType>
Expand Down
56 changes: 1 addition & 55 deletions src/core/include/units/bits/external/hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,7 @@

#pragma once

#include <version>

#if __clang__
#define UNITS_COMP_CLANG __clang_major__
#elif __GNUC__
#define UNITS_COMP_GCC __GNUC__
#define UNITS_COMP_GCC_MINOR __GNUC_MINOR__
#elif _MSC_VER
#define UNITS_COMP_MSVC _MSC_VER
#endif

// Adapted from https://github.com/ericniebler/range-v3/blob/master/include/range/v3/detail/config.hpp#L185.
#define UNITS_PRAGMA(X) _Pragma(#X)
#if !UNITS_COMP_MSVC
#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(GCC diagnostic push)
#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(GCC diagnostic pop)
#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(GCC diagnostic ignored "-Wpragmas")
#define UNITS_DIAGNOSTIC_IGNORE(X) \
UNITS_DIAGNOSTIC_IGNORE_PRAGMAS \
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \
UNITS_PRAGMA(GCC diagnostic ignored X)
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces")
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend")
#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE("-Wshadow")
#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
#else
#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(warning(push))
#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(warning(pop))
#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : 4068))
#define UNITS_DIAGNOSTIC_IGNORE(X) UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : X))
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF UNITS_DIAGNOSTIC_IGNORE(4296)
#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA UNITS_DIAGNOSTIC_IGNORE(4244)
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND
#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE(4459)
#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE UNITS_DIAGNOSTIC_IGNORE(4702)
#endif

#if _LIBCPP_VERSION
#define UNITS_LIBCXX _LIBCPP_VERSION
#endif
#include <units/bits/config/macros.h>

#if UNITS_LIBCXX

Expand All @@ -90,17 +47,6 @@
#include <compare>
#include <concepts>

#if UNITS_COMP_MSVC || UNITS_COMP_CLANG

#define TYPENAME typename

#else

#define TYPENAME

#endif


namespace std {

#if UNITS_COMP_GCC
Expand Down

0 comments on commit fa0b45b

Please sign in to comment.