https://mooseframework.inl.gov
Classes | Public Member Functions | Private Attributes | List of all members
RestartableDataMap Class Reference

Storage for restartable data that is ordered based on insertion order. More...

#include <RestartableDataMap.h>

Classes

class  Data
 Protected storage for restartable data. More...
 

Public Member Functions

 RestartableDataMap ()
 
RestartableDataValueaddData (std::unique_ptr< RestartableDataValue > data)
 Adds the restartable data data to the map. More...
 
bool hasData (const std::string &name) const
 
RestartableDataValuedata (const std::string &name)
 
auto size () const
 
auto empty () const
 
const RestartableDataValuefindData (const std::string &name) const
 Tries to find data with the name name; returns nullptr if not found. More...
 
RestartableDataValuefindData (const std::string &name)
 
auto begin ()
 Begin and end iterators to the data. More...
 
auto end ()
 
auto begin () const
 
auto end () const
 

Private Attributes

RestartableDataMap::Data _data
 The registered data. More...
 
std::unordered_map< std::string, std::size_t > _name_to_data_index
 Mapping from data name -> index in _data for quick indexing. More...
 

Detailed Description

Storage for restartable data that is ordered based on insertion order.

The intent here is to be able to load declared restartable data in the order that it is instantiated.

Definition at line 27 of file RestartableDataMap.h.

Constructor & Destructor Documentation

◆ RestartableDataMap()

RestartableDataMap::RestartableDataMap ( )

Definition at line 14 of file RestartableDataMap.C.

14 {}

Member Function Documentation

◆ addData()

RestartableDataValue & RestartableDataMap::addData ( std::unique_ptr< RestartableDataValue data)

Adds the restartable data data to the map.

Definition at line 17 of file RestartableDataMap.C.

Referenced by RestartableDataReader::restoreData().

18 {
19  mooseAssert(data, "Not set");
20  mooseAssert(!hasData(data->name()), "Name is already added");
21 
22  const auto & name = data->name();
23  auto & inserted_data = _data.addPointer(std::move(data), {});
24  _name_to_data_index.emplace(name, _data.size() - 1);
25 
26  mooseAssert(hasData(name), "Doesn't have data");
27 
28  return inserted_data;
29 }
std::string name(const ElemQuality q)
RestartableDataMap::Data _data
The registered data.
std::size_t size() const
RestartableDataValue & data(const std::string &name)
bool hasData(const std::string &name) const
std::unordered_map< std::string, std::size_t > _name_to_data_index
Mapping from data name -> index in _data for quick indexing.
RestartableDataValue & addPointer(std::unique_ptr< RestartableDataValue > &&ptr, const WriteKey)
const std::string & name() const
The full (unique) name of this particular piece of data.

◆ begin() [1/2]

auto RestartableDataMap::begin ( )
inline

Begin and end iterators to the data.

Definition at line 78 of file RestartableDataMap.h.

78 { return _data.begin(); }
RestartableDataMap::Data _data
The registered data.
iterator begin()
Begin and end iterators to the underlying data.
Definition: UniqueStorage.h:82

◆ begin() [2/2]

auto RestartableDataMap::begin ( ) const
inline

Definition at line 80 of file RestartableDataMap.h.

80 { return _data.begin(); }
RestartableDataMap::Data _data
The registered data.
iterator begin()
Begin and end iterators to the underlying data.
Definition: UniqueStorage.h:82

◆ data()

RestartableDataValue & RestartableDataMap::data ( const std::string &  name)
Returns
The data with the name name

Definition at line 65 of file RestartableDataMap.C.

Referenced by addData(), and findData().

66 {
67  auto find_data = findData(name);
68  if (!find_data)
69  mooseError("Restartable data with the name ", name, " is not registered");
70  return *find_data;
71 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const RestartableDataValue * findData(const std::string &name) const
Tries to find data with the name name; returns nullptr if not found.

◆ empty()

auto RestartableDataMap::empty ( ) const
inline
Returns
Whether or not there is no registered data

Definition at line 91 of file RestartableDataMap.h.

91 { return _data.empty(); }
RestartableDataMap::Data _data
The registered data.
bool empty() const

◆ end() [1/2]

auto RestartableDataMap::end ( )
inline

Definition at line 79 of file RestartableDataMap.h.

79 { return _data.end(); }
RestartableDataMap::Data _data
The registered data.
iterator end()
Definition: UniqueStorage.h:83

◆ end() [2/2]

auto RestartableDataMap::end ( ) const
inline

Definition at line 81 of file RestartableDataMap.h.

81 { return _data.end(); }
RestartableDataMap::Data _data
The registered data.
iterator end()
Definition: UniqueStorage.h:83

◆ findData() [1/2]

const RestartableDataValue * RestartableDataMap::findData ( const std::string &  name) const

Tries to find data with the name name; returns nullptr if not found.

Definition at line 32 of file RestartableDataMap.C.

Referenced by data(), findData(), and hasData().

33 {
34  auto find_index = _name_to_data_index.find(name);
35 
36 #ifndef NDEBUG
37  auto find_it = std::find_if(
38  _data.begin(), _data.end(), [&name](const auto & data) { return data.name() == name; });
39 #endif
40 
41  if (find_index == _name_to_data_index.end())
42  {
43  mooseAssert(find_it == _data.end(), "Inconsistent map");
44  return nullptr;
45  }
46 
47  const auto index = find_index->second;
48  mooseAssert(index == (std::size_t)std::distance(_data.begin(), find_it), "Inconsistent map");
49  mooseAssert(_data.size() > index, "Invalid index");
50 
51  auto & data = _data[index];
52  mooseAssert(data.name() == name, "Inconsistent name");
53 
54  return &data;
55 }
std::string name(const ElemQuality q)
RestartableDataMap::Data _data
The registered data.
iterator begin()
Begin and end iterators to the underlying data.
Definition: UniqueStorage.h:82
std::size_t size() const
RestartableDataValue & data(const std::string &name)
std::unordered_map< std::string, std::size_t > _name_to_data_index
Mapping from data name -> index in _data for quick indexing.
iterator end()
Definition: UniqueStorage.h:83
const std::string & name() const
The full (unique) name of this particular piece of data.

◆ findData() [2/2]

RestartableDataValue * RestartableDataMap::findData ( const std::string &  name)

Definition at line 58 of file RestartableDataMap.C.

59 {
60  return const_cast<RestartableDataValue *>(
61  const_cast<const RestartableDataMap *>(this)->findData(name));
62 }
const RestartableDataValue * findData(const std::string &name) const
Tries to find data with the name name; returns nullptr if not found.
Storage for restartable data that is ordered based on insertion order.
Abstract definition of a RestartableData value.

◆ hasData()

bool RestartableDataMap::hasData ( const std::string &  name) const
Returns
Whether or not data with the name name is added

Definition at line 74 of file RestartableDataMap.C.

Referenced by addData().

75 {
76  return findData(name) != nullptr;
77 }
const RestartableDataValue * findData(const std::string &name) const
Tries to find data with the name name; returns nullptr if not found.

◆ size()

auto RestartableDataMap::size ( ) const
inline
Returns
The size of registered data

Definition at line 87 of file RestartableDataMap.h.

Referenced by RestartableDataWriter::write().

87 { return _data.size(); }
RestartableDataMap::Data _data
The registered data.
std::size_t size() const

Member Data Documentation

◆ _data

RestartableDataMap::Data RestartableDataMap::_data
private

The registered data.

Definition at line 95 of file RestartableDataMap.h.

Referenced by addData(), begin(), empty(), end(), findData(), and size().

◆ _name_to_data_index

std::unordered_map<std::string, std::size_t> RestartableDataMap::_name_to_data_index
private

Mapping from data name -> index in _data for quick indexing.

Definition at line 97 of file RestartableDataMap.h.

Referenced by addData(), and findData().


The documentation for this class was generated from the following files: