LCOV - code coverage report
Current view: top level - tests/integration/harness/gkfs.io - reflection.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 4 100.0 %
Date: 2024-04-23 00:09:24 Functions: 30 30 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
       3             :   Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany
       4             : 
       5             :   This software was partially supported by the
       6             :   EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
       7             : 
       8             :   This software was partially supported by the
       9             :   ADA-FS project under the SPPEXA project funded by the DFG.
      10             : 
      11             :   This file is part of GekkoFS.
      12             : 
      13             :   GekkoFS is free software: you can redistribute it and/or modify
      14             :   it under the terms of the GNU General Public License as published by
      15             :   the Free Software Foundation, either version 3 of the License, or
      16             :   (at your option) any later version.
      17             : 
      18             :   GekkoFS is distributed in the hope that it will be useful,
      19             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      20             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      21             :   GNU General Public License for more details.
      22             : 
      23             :   You should have received a copy of the GNU General Public License
      24             :   along with GekkoFS.  If not, see <https://www.gnu.org/licenses/>.
      25             : 
      26             :   SPDX-License-Identifier: GPL-3.0-or-later
      27             : */
      28             : 
      29             : #ifndef GKFS_IO_REFLECTION_HPP
      30             : #define GKFS_IO_REFLECTION_HPP
      31             : 
      32             : #include <nlohmann/json.hpp>
      33             : #include <fmt/format.h>
      34             : #include <boost/preprocessor.hpp>
      35             : 
      36             : extern "C" {
      37             : #include <dirent.h> // required by DIR*
      38             : }
      39             : 
      40             : namespace refl {
      41             : namespace detail {
      42             : 
      43             : template <typename Class, typename T>
      44             : struct property_impl {
      45             :     constexpr property_impl(T Class::*aMember, const char* aType,
      46             :                             const char* aName)
      47             :         : member{aMember}, type{aType}, name{aName} {}
      48             : 
      49             :     using Type = T;
      50             : 
      51             :     T Class::*member;
      52             :     const char* type;
      53             :     const char* name;
      54             : };
      55             : 
      56             : } // namespace detail
      57             : 
      58             : template <typename Class, typename T>
      59             : constexpr auto
      60             : property(T Class::*member, const char* type, const char* name) {
      61             :     return detail::property_impl<Class, T>{member, type, name};
      62             : }
      63             : 
      64             : template <typename T, T... S, typename F>
      65             : constexpr void
      66         268 : for_sequence(std::integer_sequence<T, S...>, F&& f) {
      67             :     using unpack_t = int[];
      68         612 :     (void) unpack_t{
      69         268 :             (static_cast<void>(f(std::integral_constant<T, S>{})), 0)..., 0};
      70         268 : }
      71             : 
      72             : } // namespace refl
      73             : 
      74             : 
      75             : /* private helper macros, do not call directly */
      76             : #define _REFL_STRUCT_NAME(t)         BOOST_PP_TUPLE_ELEM(0, t)
      77             : #define _REFL_STRUCT_MEMBER_COUNT(t) BOOST_PP_TUPLE_ELEM(1, t)
      78             : #define _REFL_MEMBER_TYPE(t)         BOOST_PP_TUPLE_ELEM(0, t)
      79             : #define _REFL_MEMBER_NAME(t)         BOOST_PP_TUPLE_ELEM(1, t)
      80             : 
      81             : #define _REFL_GEN_FIELD(r, data, index, elem)                                  \
      82             :     refl::property(                                                            \
      83             :             &_REFL_STRUCT_NAME(data)::_REFL_MEMBER_NAME(elem),                 \
      84             :             BOOST_PP_STRINGIZE(_REFL_MEMBER_TYPE(elem)),                       \
      85             :                                BOOST_PP_STRINGIZE(_REFL_MEMBER_NAME(elem)))    \
      86             :                     BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(                      \
      87             :                             index,                                             \
      88             :                             BOOST_PP_DEC(_REFL_STRUCT_MEMBER_COUNT(data))))
      89             : 
      90             : /* public interface */
      91             : #define REFL_DECL_MEMBER(type, name) (type, name)
      92             : 
      93             : #define REFL_DECL_STRUCT(struct_name, ...)                                     \
      94             :     constexpr static auto properties =                                         \
      95             :             std::make_tuple(BOOST_PP_SEQ_FOR_EACH_I(                           \
      96             :                     _REFL_GEN_FIELD,                                           \
      97             :                     (struct_name, BOOST_PP_VARIADIC_SIZE(__VA_ARGS__)),        \
      98             :                     BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))));                    \
      99             :     static_assert(true, "")
     100             : 
     101             : #endif // GKFS_IO_REFLECTION_HPP

Generated by: LCOV version 1.16