LCOV - code coverage report
Current view: top level - src - map_utils.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 11 12 91.7 %
Date: 2024-12-21 08:56:24 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  This program is free software: you can redistribute it and/or modify
       5             :  *  it under the terms of the GNU General Public License as published by
       6             :  *  the Free Software Foundation, either version 3 of the License, or
       7             :  *  (at your option) any later version.
       8             :  *
       9             :  *  This program is distributed in the hope that it will be useful,
      10             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12             :  *  GNU General Public License for more details.
      13             :  *
      14             :  *  You should have received a copy of the GNU General Public License
      15             :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16             :  */
      17             : #pragma once
      18             : 
      19             : #include <vector>
      20             : #include <iterator>
      21             : #include <algorithm>
      22             : #include <tuple>
      23             : 
      24             : namespace jami {
      25             : namespace map_utils {
      26             : 
      27             : ///< Return the N-th type of a tuple type used as the Container compliant value type
      28             : template<typename C, std::size_t N>
      29             : using type_element =
      30             :     typename std::remove_cv<typename std::tuple_element<N, typename C::value_type>::type>::type;
      31             : 
      32             : ///< Extract in a std::vector object each N-th values of tuples contained in a Container compliant
      33             : ///< object \a container.
      34             : template<std::size_t N, typename C>
      35             : inline std::vector<type_element<C, N>>
      36           2 : extractElements(const C& container)
      37             : {
      38           2 :     std::vector<type_element<C, N>> result;
      39           2 :     if (container.size() > 0) {
      40           2 :         result.resize(container.size());
      41           2 :         auto iter = std::begin(container);
      42          17 :         std::generate(std::begin(result), std::end(result), [&] { return std::get<N>(*iter++); });
      43             :     }
      44           2 :     return result;
      45           0 : }
      46             : 
      47             : template<typename M>
      48             : inline auto
      49           1 : extractKeys(const M& map) -> decltype(extractElements<0>(map))
      50             : {
      51           1 :     return extractElements<0>(map);
      52             : }
      53             : 
      54             : template<typename M>
      55             : inline auto
      56           1 : extractValues(const M& map) -> decltype(extractElements<1>(map))
      57             : {
      58           1 :     return extractElements<1>(map);
      59             : }
      60             : 
      61             : } // namespace map_utils
      62             : } // namespace jami

Generated by: LCOV version 1.14