LCOV - code coverage report
Current view: top level - PTN_Engine/Utilities - DetectRepeated.h (source / functions) Hit Total Coverage
Test: filtered_coverage.info Lines: 12 12 100.0 %
Date: 2024-05-26 15:41:39 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This file is part of PTN Engine
       3             :  *
       4             :  * Copyright (c) 2018-2019 Eduardo ValgĂ´de
       5             :  *
       6             :  * Licensed under the Apache License, Version 2.0 (the "License");
       7             :  * you may not use this file except in compliance with the License.
       8             :  * You may obtain a copy of the License at
       9             :  *
      10             :  * http://www.apache.org/licenses/LICENSE-2.0
      11             :  *
      12             :  * Unless required by applicable law or agreed to in writing, software
      13             :  * distributed under the License is distributed on an "AS IS" BASIS,
      14             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15             :  * See the License for the specific language governing permissions and
      16             :  * limitations under the License.
      17             :  */
      18             : 
      19             : #include <algorithm>
      20             : #include <memory>
      21             : #include <vector>
      22             : 
      23             : namespace ptne::utility
      24             : {
      25             : 
      26             : template <typename T, class E>
      27         555 : void detectRepeated(std::vector<std::weak_ptr<T>> items)
      28             : {
      29         151 :         auto equals = [](const std::weak_ptr<T> &t, const std::weak_ptr<T> &u)
      30         151 :         { return !t.owner_before(u) && !u.owner_before(t); };
      31             : 
      32         555 :         std::ranges::sort(items, std::owner_less<std::weak_ptr<T>>());
      33             : 
      34         555 :         if (items.end() - std::unique(items.begin(), items.end(), equals) > 0)
      35             :         {
      36           3 :                 throw E();
      37             :         }
      38         552 : }
      39             : 
      40             : template <class T, class E>
      41           4 : void detectRepeatedNames(std::vector<T> items)
      42             : {
      43           4 :         std::ranges::sort(items);
      44           4 :         if (items.end() - std::unique(items.begin(), items.end()) > 0)
      45             :         {
      46           1 :                 throw E();
      47             :         }
      48           3 : }
      49             : 
      50             : } // namespace ptne::utility

Generated by: LCOV version 1.14