https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
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.
 
RestartableDataValuefindData (const std::string &name)
 
auto begin ()
 Begin and end iterators to the data.
 
auto end ()
 
auto begin () const
 
auto end () const
 

Private Attributes

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

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.

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}
RestartableDataValue & addPointer(std::unique_ptr< RestartableDataValue > &&ptr, const WriteKey)
std::unordered_map< std::string, std::size_t > _name_to_data_index
Mapping from data name -> index in _data for quick indexing.
RestartableDataValue & data(const std::string &name)
bool hasData(const std::string &name) const
RestartableDataMap::Data _data
The registered data.
const std::string & name() const
The full (unique) name of this particular piece of data.
std::size_t size() const
std::string name(const ElemQuality q)

Referenced by RestartableDataReader::restoreData().

◆ 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(); }
iterator begin()
Begin and end iterators to the underlying data.

◆ begin() [2/2]

auto RestartableDataMap::begin ( ) const
inline

Definition at line 80 of file RestartableDataMap.h.

80{ return _data.begin(); }

◆ data()

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

Definition at line 65 of file RestartableDataMap.C.

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:311
const RestartableDataValue * findData(const std::string &name) const
Tries to find data with the name name; returns nullptr if not found.

Referenced by addData(), and findData().

◆ 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(); }
bool empty() const

◆ end() [1/2]

auto RestartableDataMap::end ( )
inline

Definition at line 79 of file RestartableDataMap.h.

79{ return _data.end(); }
iterator end()

◆ end() [2/2]

auto RestartableDataMap::end ( ) const
inline

Definition at line 81 of file RestartableDataMap.h.

81{ return _data.end(); }

◆ findData() [1/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}
Storage for restartable data that is ordered based on insertion order.
Abstract definition of a RestartableData value.

◆ findData() [2/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.

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}

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

◆ 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.

75{
76 return findData(name) != nullptr;
77}

Referenced by addData().

◆ size()

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

Definition at line 87 of file RestartableDataMap.h.

87{ return _data.size(); }

Member Data Documentation

◆ _data

RestartableDataMap::Data RestartableDataMap::_data
private

The registered data.

Definition at line 95 of file RestartableDataMap.h.

Referenced by addData(), begin(), begin(), empty(), end(), 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: