LCOV - code coverage report
Current view: top level - include/utils - MooseEnumItem.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 12 13 92.3 %
Date: 2025-07-17 01:28:37 Functions: 11 12 91.7 %
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             : // STL includes
      13             : #include <string>
      14             : 
      15             : /**
      16             :  * Class for containing MooseEnum item information.
      17             :  */
      18             : class MooseEnumItem
      19             : {
      20             : public:
      21             :   static const int INVALID_ID;
      22             :   MooseEnumItem();
      23             :   MooseEnumItem(const std::string & name, const int & id = INVALID_ID);
      24  2006398336 :   ~MooseEnumItem() = default;
      25             :   MooseEnumItem(const MooseEnumItem & other);
      26    34127878 :   MooseEnumItem(MooseEnumItem && /*other*/) = default;
      27             :   MooseEnumItem & operator=(const MooseEnumItem & other);
      28     3260904 :   MooseEnumItem & operator=(MooseEnumItem && /*other*/) = default;
      29             : 
      30             :   ///@{
      31             :   /**
      32             :    * Return the numeric, name, or raw name.
      33             :    */
      34  6589091759 :   const int & id() const { return _id; }
      35  2063249374 :   const std::string & name() const { return _name; }
      36    14093055 :   const std::string & rawName() const { return _raw_name; }
      37             :   ///@}
      38             : 
      39             :   ///@{
      40             :   /**
      41             :    * Operator to allow this class to be used directly as a string for int.
      42             :    */
      43    67589268 :   operator int() const { return _id; }
      44      216773 :   operator std::string() const { return _name; }
      45             :   ///@}
      46             : 
      47             :   ///@{
      48             :   /**
      49             :    * Comparison operators.
      50             :    *
      51             :    * The comparison operators using the char * and string are case sensitive.
      52             :    */
      53             :   bool operator==(const char * value) const;
      54             :   bool operator!=(const char * value) const;
      55             : 
      56             :   bool operator==(const std::string & value) const;
      57             :   bool operator!=(const std::string & value) const;
      58             : 
      59       34925 :   bool operator==(int value) const { return _id == value; }
      60           1 :   bool operator!=(int value) const { return _id != value; }
      61             : 
      62           0 :   bool operator==(unsigned short value) const { return _id == value; }
      63             :   bool operator!=(unsigned short value) const { return _id != value; }
      64             : 
      65             :   bool operator==(const MooseEnumItem &) const;
      66             :   bool operator!=(const MooseEnumItem &) const;
      67             :   ///@}
      68             : 
      69             :   /**
      70             :    * Less than operator. This is required for this class to work in maps and sets.
      71             :    */
      72  1645772002 :   bool operator<(const MooseEnumItem & other) const
      73             :   {
      74  1645772002 :     return _id != other._id ? _id < other._id : _name < other._name;
      75             :   }
      76             : 
      77             :   /**
      78             :    * ostream operator for string printing.
      79             :    */
      80             :   friend std::ostream & operator<<(std::ostream & out, const MooseEnumItem & item);
      81             : 
      82             :   /**
      83             :    * Method to change the ID of the item, but only if it is an INVALID_ID. An error is produced
      84             :    * if the ID is valid and this method is called.
      85             :    *
      86             :    * This is needed to allow ExecFlagType objects to be created without an ID being provided, the
      87             :    * ID is assigned when ExecFlagEnum::addAvailableFlags is called.
      88             :    */
      89             :   void setID(const int & id);
      90             : 
      91             : private:
      92             :   /// The name as provided in constructor
      93             :   std::string _raw_name;
      94             : 
      95             :   /// Upper case name
      96             :   std::string _name;
      97             : 
      98             :   /// The numeric value for item
      99             :   int _id;
     100             : };

Generated by: LCOV version 1.14