https://mooseframework.inl.gov
RestartableDataMap.h
Go to the documentation of this file.
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 
28 {
29 public:
33  class Data : public UniqueStorage<RestartableDataValue>
34  {
35  public:
36  class WriteKey
37  {
38  friend class RestartableDataMap;
39  WriteKey() {}
40  WriteKey(const WriteKey &) {}
41  };
42 
43  RestartableDataValue & addPointer(std::unique_ptr<RestartableDataValue> && ptr, const WriteKey)
44  {
46  }
47  };
48 
50 
54  RestartableDataValue & addData(std::unique_ptr<RestartableDataValue> data);
55 
59  bool hasData(const std::string & name) const;
60 
64  const RestartableDataValue * findData(const std::string & name) const;
66  RestartableDataValue * findData(const std::string & name);
68 
72  RestartableDataValue & data(const std::string & name);
73 
77  auto begin() { return _data.begin(); }
79  auto end() { return _data.end(); }
80  auto begin() const { return _data.begin(); }
81  auto end() const { return _data.end(); }
83 
87  auto size() const { return _data.size(); }
91  auto empty() const { return _data.empty(); }
92 
93 private:
97  std::unordered_map<std::string, std::size_t> _name_to_data_index;
98 };
auto begin()
Begin and end iterators to the data.
Protected storage for restartable data.
RestartableDataMap::Data _data
The registered data.
Storage container that stores a vector of unique pointers of T, but represents most of the public fac...
Definition: UniqueStorage.h:18
const RestartableDataValue * findData(const std::string &name) const
Tries to find data with the name name; returns nullptr if not found.
RestartableDataValue & addData(std::unique_ptr< RestartableDataValue > data)
Adds the restartable data data to the map.
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)
Storage for restartable data that is ordered based on insertion order.
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.
bool empty() const
iterator end()
Definition: UniqueStorage.h:83
RestartableDataValue & addPointer(std::unique_ptr< RestartableDataValue > &&ptr, const WriteKey)
Abstract definition of a RestartableData value.
T & addPointer(std::unique_ptr< T > &&ptr)
Adds the given object in ptr to the storage.