LCOV - code coverage report
Current view: top level - include/restart - RestartableDataMap.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 8 8 100.0 %
Date: 2025-07-17 01:28:37 Functions: 7 7 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             : #pragma once
      11             : 
      12             : #include "RestartableData.h"
      13             : 
      14             : #include "UniqueStorage.h"
      15             : 
      16             : // C++ includes
      17             : #include <memory>
      18             : #include <vector>
      19             : #include <unordered_map>
      20             : 
      21             : /**
      22             :  * Storage for restartable data that is ordered based on insertion order.
      23             :  *
      24             :  * The intent here is to be able to load declared restartable data in the
      25             :  * order that it is instantiated.
      26             :  */
      27             : class RestartableDataMap
      28             : {
      29             : public:
      30             :   /**
      31             :    * Protected storage for restartable data.
      32             :    */
      33             :   class Data : public UniqueStorage<RestartableDataValue>
      34             :   {
      35             :   public:
      36             :     class WriteKey
      37             :     {
      38             :       friend class RestartableDataMap;
      39     2336388 :       WriteKey() {}
      40             :       WriteKey(const WriteKey &) {}
      41             :     };
      42             : 
      43     2336388 :     RestartableDataValue & addPointer(std::unique_ptr<RestartableDataValue> && ptr, const WriteKey)
      44             :     {
      45     2336388 :       return UniqueStorage<RestartableDataValue>::addPointer(std::move(ptr));
      46             :     }
      47             :   };
      48             : 
      49             :   RestartableDataMap();
      50             : 
      51             :   /**
      52             :    * Adds the restartable data \p data to the map
      53             :    */
      54             :   RestartableDataValue & addData(std::unique_ptr<RestartableDataValue> data);
      55             : 
      56             :   /**
      57             :    * @returns Whether or not data with the name \p name is added
      58             :    */
      59             :   bool hasData(const std::string & name) const;
      60             : 
      61             :   /**
      62             :    * Tries to find data with the name \p name; returns nullptr if not found
      63             :    */
      64             :   ///@{
      65             :   const RestartableDataValue * findData(const std::string & name) const;
      66             :   RestartableDataValue * findData(const std::string & name);
      67             :   ///@}
      68             : 
      69             :   /**
      70             :    * @returns The data with the name \p name
      71             :    */
      72             :   RestartableDataValue & data(const std::string & name);
      73             : 
      74             :   /**
      75             :    * Begin and end iterators to the data
      76             :    */
      77             :   ///@{
      78      144707 :   auto begin() { return _data.begin(); }
      79      144707 :   auto end() { return _data.end(); }
      80       61106 :   auto begin() const { return _data.begin(); }
      81       61106 :   auto end() const { return _data.end(); }
      82             :   ///@}
      83             : 
      84             :   /**
      85             :    * @returns The size of registered data
      86             :    */
      87       55008 :   auto size() const { return _data.size(); }
      88             :   /**
      89             :    * @returns Whether or not there is no registered data
      90             :    */
      91             :   auto empty() const { return _data.empty(); }
      92             : 
      93             : private:
      94             :   /// The registered data
      95             :   RestartableDataMap::Data _data;
      96             :   /// Mapping from data name -> index in \p _data for quick indexing
      97             :   std::unordered_map<std::string, std::size_t> _name_to_data_index;
      98             : };

Generated by: LCOV version 1.14