SpECTRE Documentation Coverage Report
Current view: top level - Options - Comparator.hpp Hit Total Coverage
Commit: f23e75c235cae5144b8ac7ce01280be5b8cd2c8a Lines: 1 11 9.1 %
Date: 2024-09-07 06:21:00
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include "Utilities/ErrorHandling/Error.hpp"
       7             : 
       8             : /// \cond
       9             : namespace Options {
      10             : class Option;
      11             : template <typename T>
      12             : struct create_from_yaml;
      13             : }  // namespace Options
      14             : namespace PUP {
      15             : class er;
      16             : }  // namespace PUP
      17             : /// \endcond
      18             : 
      19             : namespace Options {
      20             : /// An option-creatable mathematical comparison.
      21           1 : class Comparator {
      22             :  public:
      23           0 :   enum class Comparison {
      24             :     EqualTo,
      25             :     NotEqualTo,
      26             :     LessThan,
      27             :     GreaterThan,
      28             :     LessThanOrEqualTo,
      29             :     GreaterThanOrEqualTo
      30             :   };
      31             : 
      32           0 :   Comparator() = default;
      33           0 :   Comparator(Comparison comparison);
      34             : 
      35             :   template <typename T1, typename T2>
      36           0 :   bool operator()(const T1& t1, const T2& t2) const {
      37             :     switch (comparison_) {
      38             :       case Comparison::EqualTo:
      39             :         return t1 == t2;
      40             :       case Comparison::NotEqualTo:
      41             :         return t1 != t2;
      42             :       case Comparison::LessThan:
      43             :         return t1 < t2;
      44             :       case Comparison::GreaterThan:
      45             :         return t1 > t2;
      46             :       case Comparison::LessThanOrEqualTo:
      47             :         return t1 <= t2;
      48             :       case Comparison::GreaterThanOrEqualTo:
      49             :         return t1 >= t2;
      50             :       default:
      51             :         ERROR("Invalid comparison");
      52             :     }
      53             :   }
      54             : 
      55             :   // NOLINTNEXTLINE(google-runtime-references)
      56           0 :   void pup(PUP::er& p);
      57             : 
      58             :  private:
      59           0 :   Comparison comparison_;
      60             : };
      61             : 
      62             : template <>
      63           0 : struct create_from_yaml<Comparator> {
      64             :   template <typename Metavariables>
      65           0 :   static Comparator create(const Option& options) {
      66             :     return create_impl(options);
      67             :   }
      68             : 
      69             :  private:
      70           0 :   static Comparator create_impl(const Option& options);
      71             : };
      72             : }  // namespace Options

Generated by: LCOV version 1.14