LCOV - code coverage report
Current view: top level - src/materials - MaterialPropertyRegistry.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31653 (2d163b) with base 0cc44f Lines: 20 22 90.9 %
Date: 2025-11-04 20:38:02 Functions: 4 4 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             : #include "MaterialPropertyRegistry.h"
      11             : 
      12             : #include "MooseError.h"
      13             : 
      14             : unsigned int
      15      134263 : MaterialPropertyRegistry::addOrGetID(const std::string & name,
      16             :                                      const MaterialPropertyRegistry::WriteKey)
      17             : {
      18      134263 :   const auto it = _name_to_id.find(name);
      19      134263 :   if (it != _name_to_id.end())
      20      113709 :     return it->second;
      21             : 
      22       20554 :   const auto id = _id_to_name.size();
      23       20554 :   _name_to_id.emplace(name, id);
      24       20554 :   _id_to_name.push_back(name);
      25       20554 :   return id;
      26             : }
      27             : 
      28             : unsigned int
      29      198209 : MaterialPropertyRegistry::getID(const std::string & name) const
      30             : {
      31      198209 :   const auto id = queryID(name);
      32      198209 :   if (!id)
      33           0 :     mooseError("MaterialPropertyRegistry: Property '" + name + "' is not declared");
      34      396418 :   return *id;
      35             : }
      36             : 
      37             : std::optional<unsigned int>
      38      198603 : MaterialPropertyRegistry::queryID(const std::string & name) const
      39             : {
      40      198603 :   const auto it = _name_to_id.find(name);
      41      198603 :   if (it == _name_to_id.end())
      42          24 :     return {};
      43      198579 :   return it->second;
      44             : }
      45             : 
      46             : const std::string &
      47        2452 : MaterialPropertyRegistry::getName(const unsigned int id) const
      48             : {
      49        2452 :   if (!hasProperty(id))
      50           0 :     mooseError("MaterialPropertyRegistry: Property with ID ", id, " is not declared");
      51        2452 :   return _id_to_name[id];
      52             : }

Generated by: LCOV version 1.14