GCC Code Coverage Report


Directory: gridformat/
File: gridformat/common/path.hpp
Date: 2025-03-26 17:08:15
Exec Total Coverage
Lines: 15 16 93.8%
Functions: 4 4 100.0%
Branches: 11 28 39.3%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2 // SPDX-License-Identifier: MIT
3 /*!
4 * \file
5 * \ingroup Common
6 * \brief Helper functions for operations on paths.
7 */
8 #ifndef GRIDFORMAT_COMMON_PATH_HPP_
9 #define GRIDFORMAT_COMMON_PATH_HPP_
10
11 #include <ranges>
12 #include <iterator>
13 #include <string_view>
14 #include <filesystem>
15 #include <algorithm>
16
17 namespace GridFormat::Path {
18
19 /*!
20 * \ingroup Common
21 * \brief Return a range over the elements of a path.
22 */
23 229627 std::ranges::range auto elements_of(std::string_view path, char delimiter = '/') {
24
1/2
✓ Branch 1 taken 229627 times.
✗ Branch 2 not taken.
229627 return std::views::split(path, delimiter)
25
1/2
✓ Branch 1 taken 229627 times.
✗ Branch 2 not taken.
459254 | std::views::transform([] (const std::ranges::range auto& element) {
26 401115 std::string name;
27
2/4
✓ Branch 1 taken 401115 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 401115 times.
✗ Branch 5 not taken.
401115 std::ranges::copy(element, std::back_inserter(name));
28 401115 return name;
29
1/2
✓ Branch 1 taken 229627 times.
✗ Branch 2 not taken.
459254 });
30 }
31
32 //! Return true if the given path exists.
33 1940 bool exists(const std::filesystem::path& path) {
34 1940 return std::filesystem::exists(path);
35 }
36
37 //! Return true if the given path is a file.
38 1939 bool is_file(const std::filesystem::path& path) {
39
2/2
✓ Branch 1 taken 1938 times.
✓ Branch 2 taken 1 times.
1939 if (std::filesystem::is_regular_file(path))
40 1938 return true;
41 3 if (std::filesystem::is_symlink(path)
42
4/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
1 && std::filesystem::is_regular_file(std::filesystem::read_symlink(path)))
43 return true;
44 1 return false;
45 }
46
47 } // end namespace GridFormat::Path
48
49 #endif // GRIDFORMAT_COMMON_PATH_HPP_
50