LCOV - code coverage report
Current view: top level - include/utils - StreamArguments.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fef103 Lines: 11 11 100.0 %
Date: 2025-09-03 20:01:23 Functions: 797 1966 40.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include <tuple>
      13             : #include <sstream>
      14             : #include <string>
      15             : 
      16             : /***
      17             :  * Streams all of the given arguments into the given stream
      18             :  */
      19             : template <class StreamType>
      20             : void
      21        2147 : streamArguments(StreamType &)
      22             : {
      23        2147 : }
      24             : 
      25             : // Recursive parameter pack expansion
      26             : template <class StreamType, typename T, typename... Args>
      27             : void
      28        5363 : streamArguments(StreamType & ss, T && val, Args &&... args)
      29             : {
      30        5363 :   ss << val;
      31        5363 :   streamArguments(ss, std::forward<Args>(args)...);
      32        5363 : }
      33             : 
      34             : // Base case for Tuple expansion recursive method
      35             : template <std::size_t I = 0, class StreamType, typename... Args>
      36             : inline typename std::enable_if<I == sizeof...(Args), void>::type
      37             : streamArguments(StreamType & /*ss*/, std::tuple<Args...> /*args*/)
      38             : {
      39             : }
      40             : 
      41             : // Recursive method for tuple expansion
      42             : // clang-format off
      43             : template <std::size_t I = 0, class StreamType, typename... Args>
      44             : inline typename std::enable_if<I < sizeof...(Args), void>::type
      45             : streamArguments(StreamType & ss, std::tuple<Args...> args)
      46             : {
      47             :   ss << std::get<I>(args);
      48             :   streamArguments<I + 1, StreamType, Args...>(ss, args);
      49             : }
      50             : 
      51             : /***
      52             :  * Streams all of the given arguments into a string
      53             :  */
      54             : template <typename... Args>
      55             : std::string
      56        1671 : argumentsToString(Args &&... args)
      57             : {
      58        1671 :   std::ostringstream ss;
      59        1671 :   streamArguments(ss, std::forward<Args>(args)...);
      60        3342 :   return ss.str();
      61        1671 : }
      62             : 
      63             : // clang-format on

Generated by: LCOV version 1.14