From 619d4712330fecf2080cdb7990c9b015309d672e Mon Sep 17 00:00:00 2001 From: Thomas Hahn Date: Tue, 16 Apr 2024 14:25:49 -0400 Subject: [PATCH] Split object.hpp into multiple header files --- c++/h5/complex.hpp | 59 +++++++++++++++++++++++++++++++++++++++++++ c++/h5/h5.hpp | 7 +++-- c++/h5/object.cpp | 1 + c++/h5/object.hpp | 45 --------------------------------- c++/h5/scalar.hpp | 1 + c++/h5/stl/array.hpp | 1 + c++/h5/stl/string.cpp | 3 ++- c++/h5/stl/vector.hpp | 4 ++- c++/h5/utils.hpp | 46 +++++++++++++++++++++++++++++++++ 9 files changed, 118 insertions(+), 49 deletions(-) create mode 100644 c++/h5/complex.hpp create mode 100644 c++/h5/utils.hpp diff --git a/c++/h5/complex.hpp b/c++/h5/complex.hpp new file mode 100644 index 0000000..384d2ec --- /dev/null +++ b/c++/h5/complex.hpp @@ -0,0 +1,59 @@ +// Copyright (c) 2019-2022 Simons Foundation +// +// 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.txt +// +// 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. +// +// Authors: Olivier Parcollet, Nils Wentzell + +/** + * @file + * @brief Provides a compound type and type traits for complex numbers. + */ + +#ifndef LIBH5_COMPLEX_HPP +#define LIBH5_COMPLEX_HPP + +#include +#include + +namespace h5 { + + /** + * @brief A complex compound type consisting of two doubles to represent a complex number. + * @details This type can be used to read/write complex numbers from/to HDF5 files. + */ + struct dcplx_t { + /// Real part. + double r; + + /// Imaginary part. + double i; + }; + + // Type trait to check if a type is std::complex. + template + struct _is_complex : std::false_type {}; + + // Specialization of h5::_is_complex for std::complex. + template + struct _is_complex> : std::true_type {}; + + /** + * @brief Boolean type trait set to true for std::complex types. + * @tparam T Type to check. + */ + template + constexpr bool is_complex_v = _is_complex::value; + +} // namespace h5 + +#endif // LIBH5_COMPLEX_HPP diff --git a/c++/h5/h5.hpp b/c++/h5/h5.hpp index 4336e5d..a266a6b 100644 --- a/c++/h5/h5.hpp +++ b/c++/h5/h5.hpp @@ -24,9 +24,13 @@ #include +#include "./array_interface.hpp" +#include "./complex.hpp" #include "./file.hpp" -#include "./group.hpp" #include "./format.hpp" +#include "./generic.hpp" +#include "./group.hpp" +#include "./object.hpp" #include "./scalar.hpp" #include "./stl/string.hpp" #include "./stl/array.hpp" @@ -36,7 +40,6 @@ #include "./stl/tuple.hpp" #include "./stl/optional.hpp" #include "./stl/variant.hpp" -#include "./generic.hpp" // Define this so cpp2py modules know whether hdf5 was included #define H5_INTERFACE_INCLUDED diff --git a/c++/h5/object.cpp b/c++/h5/object.cpp index 4385fdb..0dd93d8 100644 --- a/c++/h5/object.cpp +++ b/c++/h5/object.cpp @@ -14,6 +14,7 @@ // // Authors: Olivier Parcollet, Nils Wentzell +#include "./complex.hpp" #include "./macros.hpp" #include "./object.hpp" diff --git a/c++/h5/object.hpp b/c++/h5/object.hpp index 9222fc4..3e9fad5 100644 --- a/c++/h5/object.hpp +++ b/c++/h5/object.hpp @@ -22,12 +22,8 @@ #ifndef LIBH5_OBJECT_HPP #define LIBH5_OBJECT_HPP -#include #include -#include -#include #include -#include #include namespace h5 { @@ -56,47 +52,6 @@ namespace h5 { /// Vector of h5::hsize_t used throughout the h5 library. using v_t = std::vector; - /** - * @brief A complex compound type consisting of two doubles to represent a complex number. - * @details This type can be used to read/write complex numbers from/to HDF5 files. - */ - struct dcplx_t { - /// Real part. - double r; - - /// Imaginary part. - double i; - }; - - // Type trait to check if a type is std::complex. - template - struct _is_complex : std::false_type {}; - - // Specialization of h5::_is_complex for std::complex. - template - struct _is_complex> : std::true_type {}; - - /** - * @brief Boolean type trait set to true for std::complex types. - * @tparam T Type to check. - */ - template - constexpr bool is_complex_v = _is_complex::value; - - /** - * @brief Create a std::runtime_error with an error message constructed from the given arguments. - * - * @tparam Ts Types of the arguments. - * @param ts Arguments streamed into the error message string. - * @return std::runtime_error. - */ - template - [[nodiscard]] std::runtime_error make_runtime_error(Ts const &...ts) { - std::stringstream ss; - (ss << ... << ts); - return std::runtime_error{ss.str()}; - } - /** * @brief A generic handle for HDF5 objects. * diff --git a/c++/h5/scalar.hpp b/c++/h5/scalar.hpp index 5424af2..0a5788d 100644 --- a/c++/h5/scalar.hpp +++ b/c++/h5/scalar.hpp @@ -23,6 +23,7 @@ #define LIBH5_SCALAR_HPP #include "./array_interface.hpp" +#include "./complex.hpp" #include "./group.hpp" #include "./macros.hpp" #include "./object.hpp" diff --git a/c++/h5/stl/array.hpp b/c++/h5/stl/array.hpp index 148610a..95bacb6 100644 --- a/c++/h5/stl/array.hpp +++ b/c++/h5/stl/array.hpp @@ -23,6 +23,7 @@ #define LIBH5_STL_ARRAY_HPP #include "../array_interface.hpp" +#include "../complex.hpp" #include "../macros.hpp" #include diff --git a/c++/h5/stl/string.cpp b/c++/h5/stl/string.cpp index 9d59a39..e5ab1e3 100644 --- a/c++/h5/stl/string.cpp +++ b/c++/h5/stl/string.cpp @@ -14,8 +14,9 @@ // // Authors: Olivier Parcollet, Nils Wentzell -#include "../macros.hpp" #include "./string.hpp" +#include "../macros.hpp" +#include "../utils.hpp" #include #include diff --git a/c++/h5/stl/vector.hpp b/c++/h5/stl/vector.hpp index 6dd1044..d505641 100644 --- a/c++/h5/stl/vector.hpp +++ b/c++/h5/stl/vector.hpp @@ -22,10 +22,12 @@ #ifndef LIBH5_STL_VECTOR_HPP #define LIBH5_STL_VECTOR_HPP +#include "./string.hpp" +#include "../complex.hpp" #include "../format.hpp" #include "../group.hpp" #include "../scalar.hpp" -#include "./string.hpp" +#include "../utils.hpp" #include #include diff --git a/c++/h5/utils.hpp b/c++/h5/utils.hpp new file mode 100644 index 0000000..84bec60 --- /dev/null +++ b/c++/h5/utils.hpp @@ -0,0 +1,46 @@ +// Copyright (c) 2019-2022 Simons Foundation +// +// 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.txt +// +// 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. +// +// Authors: Olivier Parcollet, Nils Wentzell + +/** + * @file + * @brief Provides some utility functions for h5. + */ + +#ifndef LIBH5_UTILS_HPP +#define LIBH5_UTILS_HPP + +#include +#include + +namespace h5 { + + /** + * @brief Create a std::runtime_error with an error message constructed from the given arguments. + * + * @tparam Ts Types of the arguments. + * @param ts Arguments streamed into the error message string. + * @return std::runtime_error. + */ + template + [[nodiscard]] std::runtime_error make_runtime_error(Ts const &...ts) { + std::stringstream ss; + (ss << ... << ts); + return std::runtime_error{ss.str()}; + } + +} // namespace h5 + +#endif // LIBH5_UTILS_HPP