www.mooseframework.org
RestartableData.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef RESTARTABLEDATA_H
16 #define RESTARTABLEDATA_H
17 
18 // MOOSE includes
19 #include "DataIO.h"
20 
21 // C++ includes
22 #include <vector>
23 
24 // Forward declarations
26 
31 {
32 public:
38  RestartableDataValue(std::string name, void * context) : _name(name), _context(context) {}
39 
43  virtual ~RestartableDataValue() = default;
44 
49  virtual std::string type() = 0;
50 
54  std::string name() { return _name; }
55 
59  void * context() { return _context; }
60 
61  virtual void swap(RestartableDataValue * rhs) = 0;
62 
63  // save/restore in a file
64  virtual void store(std::ostream & stream) = 0;
65  virtual void load(std::istream & stream) = 0;
66 
67 protected:
69  std::string _name;
70 
72  void * _context;
73 };
74 
79 template <typename T>
81 {
82 public:
88  RestartableData(std::string name, void * context) : RestartableDataValue(name, context)
89  {
90  _value_ptr = new T;
91  }
92 
93  virtual ~RestartableData() { delete _value_ptr; }
94 
98  T & get() { return *_value_ptr; }
99 
103  T & set() { return *_value_ptr; }
104 
108  virtual std::string type() override;
109 
113  virtual void swap(RestartableDataValue * rhs) override;
114 
118  virtual void store(std::ostream & stream) override;
119 
123  virtual void load(std::istream & stream) override;
124 
125 private:
128 };
129 
130 // ------------------------------------------------------------
131 // RestartableData<> class inline methods
132 template <typename T>
133 inline std::string
135 {
136  return typeid(T).name();
137 }
138 
139 template <typename T>
140 inline void
142 {
143  mooseAssert(rhs != NULL, "Assigning NULL?");
144  // _value.swap(cast_ptr<RestartableData<T>*>(rhs)->_value);
145 }
146 
147 template <typename T>
148 inline void
149 RestartableData<T>::store(std::ostream & stream)
150 {
151  T & tmp = *_value_ptr;
152  storeHelper(stream, tmp, _context);
153 }
154 
155 template <typename T>
156 inline void
157 RestartableData<T>::load(std::istream & stream)
158 {
159  loadHelper(stream, *_value_ptr, _context);
160 }
161 
165 class RestartableDatas : public std::vector<std::map<std::string, RestartableDataValue *>>
166 {
167 public:
168  RestartableDatas(size_type n) : std::vector<std::map<std::string, RestartableDataValue *>>(n) {}
169 
171  {
172  for (std::vector<std::map<std::string, RestartableDataValue *>>::iterator i = begin();
173  i != end();
174  ++i)
175  for (std::map<std::string, RestartableDataValue *>::iterator j = (*i).begin();
176  j != (*i).end();
177  ++j)
178  delete j->second;
179  }
180 };
181 #endif
RestartableDataValue(std::string name, void *context)
Constructor.
void * _context
A context pointer for helping with load and store.
virtual std::string type() override
String identifying the type of parameter stored.
virtual void load(std::istream &stream) override
Load the RestartableData from a binary stream.
virtual ~RestartableData()
RestartableDatas(size_type n)
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:528
Container for storing material properties.
virtual void store(std::ostream &stream) override
Store the RestartableData into a binary stream.
RestartableData(std::string name, void *context)
Constructor.
std::string _name
The full (unique) name of this particular piece of data.
PetscInt n
Concrete definition of a parameter value for a specified type.
virtual void swap(RestartableDataValue *rhs) override
Swap.
virtual std::string type()=0
String identifying the type of parameter stored.
virtual void store(std::ostream &stream)=0
void * context()
A context pointer for helping with load / store.
virtual void load(std::istream &stream)=0
virtual void swap(RestartableDataValue *rhs)=0
T * _value_ptr
Stored value.
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:592
Abstract definition of a RestartableData value.
std::string name()
The full (unique) name of this particular piece of data.
virtual ~RestartableDataValue()=default
Destructor.
virtual ~RestartableDatas()