LCOV - code coverage report
Current view: top level - src/utils - MooseEnumItem.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 34 42 81.0 %
Date: 2025-07-17 01:28:37 Functions: 10 12 83.3 %
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             : // MOOSE includes
      11             : #include "MooseEnumItem.h"
      12             : #include "MooseUtils.h"
      13             : 
      14       57816 : MooseEnumItem::MooseEnumItem() : _raw_name("INVALID"), _name("INVALID"), _id(INVALID_ID) {}
      15             : 
      16   248079018 : MooseEnumItem::MooseEnumItem(const std::string & name, const int & id)
      17   248079018 :   : _raw_name(MooseUtils::trim(name)), _name(MooseUtils::toUpper(_raw_name)), _id(id)
      18             : {
      19   248079018 : }
      20             : 
      21  1733793590 : MooseEnumItem::MooseEnumItem(const MooseEnumItem & other)
      22  1733793590 :   : _raw_name(other._raw_name), _name(other._name), _id(other._id)
      23             : {
      24  1733793590 : }
      25             : 
      26             : MooseEnumItem &
      27    90002175 : MooseEnumItem::operator=(const MooseEnumItem & other)
      28             : {
      29    90002175 :   _raw_name = other._raw_name;
      30    90002175 :   _name = other._name;
      31    90002175 :   _id = other._id;
      32    90002175 :   return *this;
      33             : }
      34             : 
      35             : bool
      36      787009 : MooseEnumItem::operator==(const char * value) const
      37             : {
      38      787009 :   std::string name(MooseUtils::toUpper(value));
      39     1574018 :   return _name == name;
      40      787009 : }
      41             : 
      42             : bool
      43           0 : MooseEnumItem::operator!=(const char * value) const
      44             : {
      45           0 :   std::string name(MooseUtils::toUpper(value));
      46           0 :   return _name != name;
      47           0 : }
      48             : 
      49             : bool
      50   162511295 : MooseEnumItem::operator==(const std::string & value) const
      51             : {
      52   162511295 :   std::string name(MooseUtils::toUpper(value));
      53   325022590 :   return _name == name;
      54   162511295 : }
      55             : 
      56             : bool
      57           0 : MooseEnumItem::operator!=(const std::string & value) const
      58             : {
      59           0 :   std::string name(MooseUtils::toUpper(value));
      60           0 :   return _name != name;
      61           0 : }
      62             : 
      63             : bool
      64   264751613 : MooseEnumItem::operator==(const MooseEnumItem & item) const
      65             : {
      66   264751613 :   return _id == item.id() && _name == MooseUtils::toUpper(item.name());
      67             : }
      68             : 
      69             : bool
      70    12234253 : MooseEnumItem::operator!=(const MooseEnumItem & item) const
      71             : {
      72    12234253 :   return _id != item.id() && _name != MooseUtils::toUpper(item.name());
      73             : }
      74             : 
      75             : std::ostream &
      76     6535872 : operator<<(std::ostream & out, const MooseEnumItem & item)
      77             : {
      78     6535872 :   out << item.rawName();
      79     6535872 :   return out;
      80             : }
      81             : 
      82             : void
      83           2 : MooseEnumItem::setID(const int & id)
      84             : {
      85           2 :   if (_id != INVALID_ID)
      86           1 :     mooseError("The ID of a MooseEnumItem can not be changed if it is valid, the item ",
      87           1 :                _name,
      88             :                " has a valid id of ",
      89           1 :                _id,
      90             :                ".");
      91           1 :   _id = id;
      92           1 : }
      93             : 
      94             : const int MooseEnumItem::INVALID_ID = std::numeric_limits<int>::min();

Generated by: LCOV version 1.14