From e7b4f6a7ffb5e77cc851edb97710cb9f68cffea0 Mon Sep 17 00:00:00 2001 From: Dario Izzo Date: Wed, 23 Aug 2023 10:35:07 +0200 Subject: [PATCH 01/19] first tmp commit --- benchmark/convert_anomalies_benchmark.cpp | 4 +- include/kep3/core_astro/convert_anomalies.hpp | 31 ++--- .../kep3/core_astro/convert_julian_dates.hpp | 31 ++--- include/kep3/core_astro/kepler_equations.hpp | 31 ++--- include/kep3/detail/s11n.hpp | 44 ++----- include/kep3/detail/type_name.hpp | 65 ++++++++++ include/kep3/detail/type_traits.hpp | 94 ++++++++++++++ include/kep3/detail/visibility.hpp | 4 +- include/kep3/epoch.hpp | 31 ++--- include/kep3/planet.hpp | 119 ++++++++++++++++++ src/epoch.cpp | 31 ++--- src/type_name.cpp | 51 ++++++++ test/convert_anomalies_test.cpp | 4 +- test/epoch_test.cpp | 5 +- 14 files changed, 384 insertions(+), 161 deletions(-) create mode 100644 include/kep3/detail/type_name.hpp create mode 100644 include/kep3/detail/type_traits.hpp create mode 100644 include/kep3/planet.hpp create mode 100644 src/type_name.cpp diff --git a/benchmark/convert_anomalies_benchmark.cpp b/benchmark/convert_anomalies_benchmark.cpp index 99b4e869..da8b0137 100644 --- a/benchmark/convert_anomalies_benchmark.cpp +++ b/benchmark/convert_anomalies_benchmark.cpp @@ -1,6 +1,6 @@ -// Copyright 2020, 2021, 2022 Francesco Biscani (bluescarni@gmail.com), Dario Izzo (dario.izzo@gmail.com) +// Copyright 2023, 2024 Dario Izzo (dario.izzo@gmail.com), Francesco Biscani (bluescarni@gmail.com) // -// This file is part of the dsyre library. +// This file is part of the kep3 library. // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed diff --git a/include/kep3/core_astro/convert_anomalies.hpp b/include/kep3/core_astro/convert_anomalies.hpp index 6aff203c..00a5faa4 100644 --- a/include/kep3/core_astro/convert_anomalies.hpp +++ b/include/kep3/core_astro/convert_anomalies.hpp @@ -1,27 +1,10 @@ -/***************************************************************************** - * Copyright (C) 2023 The pykep development team, * - * Advanced Concepts Team (ACT), European Space Agency (ESA) * - * * - * https://gitter.im/esa/pykep * - * https://github.com/esa/pykep * - * * - * act@esa.int * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - *****************************************************************************/ +// Copyright 2023, 2024 Dario Izzo (dario.izzo@gmail.com), Francesco Biscani (bluescarni@gmail.com) +// +// This file is part of the kep3 library. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifndef kep3_CONVERT_ANOMALIES_H #define kep3_CONVERT_ANOMALIES_H diff --git a/include/kep3/core_astro/convert_julian_dates.hpp b/include/kep3/core_astro/convert_julian_dates.hpp index 8335b3e5..dd531c5e 100644 --- a/include/kep3/core_astro/convert_julian_dates.hpp +++ b/include/kep3/core_astro/convert_julian_dates.hpp @@ -1,27 +1,10 @@ -/***************************************************************************** - * Copyright (C) 2023 The pykep development team, * - * Advanced Concepts Team (ACT), European Space Agency (ESA) * - * * - * https://gitter.im/esa/pykep * - * https://github.com/esa/pykep * - * * - * act@esa.int * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - *****************************************************************************/ +// Copyright 2023, 2024 Dario Izzo (dario.izzo@gmail.com), Francesco Biscani (bluescarni@gmail.com) +// +// This file is part of the kep3 library. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifndef kep3_CONVERT_JULIAN_DATES_H #define kep3_CONVERT_JULIAN_DATES_H diff --git a/include/kep3/core_astro/kepler_equations.hpp b/include/kep3/core_astro/kepler_equations.hpp index 0df1c784..918412ae 100644 --- a/include/kep3/core_astro/kepler_equations.hpp +++ b/include/kep3/core_astro/kepler_equations.hpp @@ -1,27 +1,10 @@ -/***************************************************************************** - * Copyright (C) 2023 The pykep development team, * - * Advanced Concepts Team (ACT), European Space Agency (ESA) * - * * - * https://gitter.im/esa/pykep * - * https://github.com/esa/pykep * - * * - * act@esa.int * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - *****************************************************************************/ +// Copyright 2023, 2024 Dario Izzo (dario.izzo@gmail.com), Francesco Biscani (bluescarni@gmail.com) +// +// This file is part of the kep3 library. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifndef kep3_kep3LER_EQUATIONS_H #define kep3_kep3LER_EQUATIONS_H diff --git a/include/kep3/detail/s11n.hpp b/include/kep3/detail/s11n.hpp index 21153de5..2a714892 100644 --- a/include/kep3/detail/s11n.hpp +++ b/include/kep3/detail/s11n.hpp @@ -1,33 +1,13 @@ -/* Copyright 2017-2021 PaGMO development team +// Copyright 2023, 2024 Dario Izzo (dario.izzo@gmail.com), Francesco Biscani (bluescarni@gmail.com) +// +// This file is part of the kep3 library. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -This file is part of the PaGMO library. - -The PaGMO library is free software; you can redistribute it and/or modify -it under the terms of either: - - * the GNU Lesser General Public License as published by the Free - Software Foundation; either version 3 of the License, or (at your - option) any later version. - -or - - * the GNU General Public License as published by the Free Software - Foundation; either version 3 of the License, or (at your option) any - later version. - -or both in parallel, as here. - -The PaGMO library is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received copies of the GNU General Public License and the -GNU Lesser General Public License along with the PaGMO library. If not, -see https://www.gnu.org/licenses/. */ - -#ifndef KEP2_S11N_HPP -#define KEP2_S11N_HPP +#ifndef KEP3_S11N_HPP +#define KEP3_S11N_HPP #include #include @@ -55,7 +35,7 @@ see https://www.gnu.org/licenses/. */ #include #include -namespace pagmo +namespace kep3 { namespace detail @@ -82,7 +62,7 @@ struct tuple_s11n<0> { } // namespace detail -} // namespace pagmo +} // namespace kep3 namespace boost { @@ -94,7 +74,7 @@ namespace serialization template inline void serialize(Archive &ar, std::tuple &t, unsigned version) { - pagmo::detail::tuple_s11n::serialize(ar, t, version); + kep3::detail::tuple_s11n::serialize(ar, t, version); } // Implement serialization for the Mersenne twister engine. diff --git a/include/kep3/detail/type_name.hpp b/include/kep3/detail/type_name.hpp new file mode 100644 index 00000000..f2a70da2 --- /dev/null +++ b/include/kep3/detail/type_name.hpp @@ -0,0 +1,65 @@ +// Copyright 2023, 2024 Dario Izzo (dario.izzo@gmail.com), Francesco Biscani (bluescarni@gmail.com) +// +// This file is part of the kep3 library. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef kep3_DETAIL_TYPE_NAME_HPP +#define kep3_DETAIL_TYPE_NAME_HPP + +#include +#include +#include + +#include + +namespace kep3 +{ + +namespace detail +{ + +kep3_DLL_PUBLIC std::string demangle_from_typeid(const char *); + +// Determine the name of the type T at runtime. +template +inline std::string type_name() +{ + // Get the demangled name without cvref. + auto ret + = demangle_from_typeid(typeid(typename std::remove_cv::type>::type).name()); + + // Redecorate it with cv qualifiers. + constexpr unsigned flag = unsigned(std::is_const::type>::value) + + (unsigned(std::is_volatile::type>::value) << 1); + switch (flag) { + case 0u: + // NOTE: handle this explicitly to keep compiler warnings at bay. + break; + case 1u: + ret += " const"; + break; + case 2u: + ret += " volatile"; + break; + case 3u: + ret += " const volatile"; + } + + // Re-add the reference, if necessary. + if (std::is_lvalue_reference::value) { + ret += " &"; + } else if (std::is_rvalue_reference::value) { + ret += " &&"; + } + + return ret; +} + +} // namespace detail + +} // namespace kep3 + +#endif \ No newline at end of file diff --git a/include/kep3/detail/type_traits.hpp b/include/kep3/detail/type_traits.hpp new file mode 100644 index 00000000..5dcd7dfe --- /dev/null +++ b/include/kep3/detail/type_traits.hpp @@ -0,0 +1,94 @@ +// Copyright 2023, 2024 Dario Izzo (dario.izzo@gmail.com), Francesco Biscani (bluescarni@gmail.com) +// +// This file is part of the kep3 library. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef kep3_DETAIL_TYPE_TRAITS_HPP +#define kep3_DETAIL_TYPE_TRAITS_HPP + +#include +#include +#include +#include + + +namespace kep3 +{ + +namespace detail +{ + +template +using uncvref_t = std::remove_cv_t>; + +template +inline constexpr bool always_false_v = false; + +// http://en.cppreference.com/w/cpp/experimental/is_detected +template class Op, class... Args> +struct detector { + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> { + using value_t = std::true_type; + using type = Op; +}; + +// http://en.cppreference.com/w/cpp/experimental/nonesuch +struct nonesuch { + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const &) = delete; + nonesuch(nonesuch &&) noexcept = delete; + void operator=(nonesuch const &) = delete; + void operator=(nonesuch &&) noexcept = delete; +}; + +template