GCC Code Coverage Report


Directory: gridformat/
File: gridformat/common/detail/crtp.hpp
Date: 2024-11-10 16:24:00
Exec Total Coverage
Lines: 8 8 100.0%
Functions: 541 715 75.7%
Branches: 0 0 -%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2 // SPDX-License-Identifier: MIT
3 #ifndef GRIDFORMAT_COMMON_DETAIL_CRTP_HPP_
4 #define GRIDFORMAT_COMMON_DETAIL_CRTP_HPP_
5 #ifndef DOXYGEN
6
7 namespace GridFormat::Detail {
8
9 template<typename Impl, typename Base>
10 1231697 Impl& cast_to_impl_ref(Base* base_ptr) {
11 1231697 return static_cast<Impl&>(*base_ptr);
12 }
13
14 template<typename Impl, typename Base>
15 4915874 Impl* cast_to_impl_ptr(Base* base_ptr) {
16 4915874 return static_cast<Impl*>(base_ptr);
17 }
18
19 template<typename Impl>
20 class CRTPBase {
21 protected:
22 1231687 Impl& _impl() { return cast_to_impl_ref<Impl>(this); }
23 1231687 Impl* _pimpl() { return cast_to_impl_ptr<Impl>(this); }
24
25 5 const Impl& _impl() const { return cast_to_impl_ref<const Impl>(this); }
26 2247150 const Impl* _pimpl() const { return cast_to_impl_ptr<const Impl>(this); }
27 };
28
29 } // end namespace GridFormat::Detail
30
31 #endif // DOXYGEN
32 #endif // GRIDFORMAT_COMMON_DETAIL_CRTP_HPP_
33