LCOV - code coverage report
Current view: top level - core - rename.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 9 100.0 %
Date: 2024-04-28 01:25:40 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: BSD-3-Clause
       2             : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
       3             : /// @file
       4             : /// @author Simon Heybrock
       5             : #pragma once
       6             : 
       7             : #include <vector>
       8             : 
       9             : #include "scipp-core_export.h"
      10             : #include "scipp/core/except.h"
      11             : #include "scipp/units/dim.h"
      12             : 
      13             : namespace scipp::core {
      14             : 
      15             : namespace detail {
      16             : template <class T>
      17        2850 : [[nodiscard]] T rename_dims(const T &obj,
      18             :                             const std::vector<std::pair<Dim, Dim>> &names,
      19             :                             const bool fail_on_unknown) {
      20        2850 :   auto out(obj);
      21        6453 :   for (const auto &[from, to] : names)
      22        3605 :     if (out.contains(from))
      23        3275 :       out.replace_key(from, to);
      24         330 :     else if (fail_on_unknown)
      25           1 :       throw except::DimensionError(
      26             :           "Cannot rename dimension " + to_string(from) +
      27             :           " since it is not contained in the input dimensions " +
      28             :           to_string(obj) + ".");
      29        2848 :   return out;
      30           2 : }
      31             : } // namespace detail
      32             : 
      33             : } // namespace scipp::core

Generated by: LCOV version 1.14