LCOV - code coverage report
Current view: top level - src/utils - MooseObjectName.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 41 42 97.6 %
Date: 2025-07-17 01:28:37 Functions: 9 9 100.0 %
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 "MooseObjectName.h"
      12             : #include "MooseError.h"
      13             : 
      14             : // STL includes
      15             : #include <iostream>
      16             : 
      17     8450045 : MooseObjectName::MooseObjectName(const std::string & tag,
      18             :                                  const std::string & name,
      19     8450045 :                                  const std::string & separator)
      20     8450045 :   : _tag(tag), _name(name), _combined(tag + name), _separator(separator)
      21             : {
      22     8450045 :   check();
      23     8450051 : }
      24             : 
      25     2890181 : MooseObjectName::MooseObjectName(std::string name) : _separator("::")
      26             : {
      27             :   // Tags may be separated by a :: or the last /
      28     2890181 :   std::size_t idx0 = name.find("::");
      29     2890181 :   std::size_t idx1 = name.rfind("/");
      30             : 
      31             :   // Case when :: is found
      32     2890181 :   if (idx0 != std::string::npos)
      33             :   {
      34     2887458 :     _tag = name.substr(0, idx0);
      35     2887458 :     _name = name.erase(0, idx0 + 2);
      36             :   }
      37             : 
      38             :   // Case when a / is found
      39        2723 :   else if (idx1 != std::string::npos)
      40             :   {
      41        2722 :     _tag = name.substr(0, idx1);
      42        2722 :     _name = name.erase(0, idx1 + 1);
      43        2722 :     _separator = "/";
      44             :   }
      45             : 
      46             :   // If you get here, just use the supplied name without a tag (this will produce an error in check)
      47             :   else
      48           1 :     _name = name;
      49             : 
      50     2890181 :   check();
      51     2890180 :   _combined = _tag + _name;
      52     2890184 : }
      53             : 
      54        3193 : MooseObjectName::MooseObjectName() : _separator("/") {}
      55             : 
      56    18850716 : MooseObjectName::MooseObjectName(const MooseObjectName & rhs)
      57    18850716 :   : _tag(rhs._tag), _name(rhs._name), _combined(rhs._combined), _separator(rhs._separator)
      58             : {
      59    18850716 : }
      60             : 
      61             : bool
      62     1657934 : MooseObjectName::operator==(const MooseObjectName & rhs) const
      63             : {
      64     2127669 :   if ((_name == rhs._name || _name == "*" || rhs._name == "*") &&
      65      469735 :       (_tag == rhs._tag || _tag == "*" || rhs._tag == "*"))
      66             :   {
      67      162591 :     return true;
      68             :   }
      69     1495343 :   return false;
      70             : }
      71             : 
      72             : bool
      73          12 : MooseObjectName::operator!=(const MooseObjectName & rhs) const
      74             : {
      75          12 :   return !(*this == rhs);
      76             : }
      77             : 
      78             : bool
      79    94852855 : MooseObjectName::operator<(const MooseObjectName & rhs) const
      80             : {
      81    94852855 :   return (_combined < rhs._combined);
      82             : }
      83             : 
      84             : std::ostream &
      85     4977152 : operator<<(std::ostream & stream, const MooseObjectName & obj)
      86             : {
      87     4977152 :   if (obj._tag.empty())
      88           0 :     return stream << obj._name;
      89             :   else
      90     4977152 :     return stream << obj._tag << obj._separator << obj._name;
      91             : }
      92             : 
      93             : void
      94    11340226 : MooseObjectName::check()
      95             : {
      96    11340226 :   if (_name.empty())
      97           1 :     mooseError("The supplied name cannot be empty, to allow for any name to be supplied use the "
      98             :                "'*' character.");
      99    11340225 :   if (_tag.empty())
     100           2 :     mooseError("The supplied tag cannot be empty, to allow for any tag to be supplied use the '*' "
     101             :                "character.");
     102    11340223 : }

Generated by: LCOV version 1.14