https://mooseframework.inl.gov
Loading...
Searching...
No Matches
RestartableData.C
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#include "RestartableData.h"
11
12RestartableDataValue::RestartableDataValue(const std::string & name, void * const context)
13 : _name(name), _context(context), _declared(false), _loaded(false), _stored(false)
14{
15}
16
17void
19{
20 mooseAssert(!_declared, "Already declared");
21 _declared = true;
22}
23
24void
25RestartableDataValue::store(std::ostream & stream)
26{
27 storeInternal(stream);
28 _stored = true;
29}
30
31void
32RestartableDataValue::load(std::istream & stream)
33{
34 loadInternal(stream);
35 _loaded = true;
36}
37
38void
39RestartableDataValue::store(nlohmann::json & json, const StoreJSONParams & params) const
40{
41 if (params.value)
42 {
43 if (hasStoreJSON())
44 storeJSONValue(json["value"]);
45 else
46 mooseError("Failed to output restartable data '",
47 name(),
48 "' as JSON because a to_json method is not implemented for the type '",
49 type(),
50 "'");
51 }
52 if (params.type)
53 json["type"] = type();
54 if (params.name)
55 json["name"] = name();
56 if (params.declared)
57 json["declared"] = declared();
58 if (params.loaded)
59 json["loaded"] = loaded();
60 if (params.stored)
61 json["stored"] = stored();
62 if (params.has_context)
63 json["has_context"] = hasContext();
64}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Helper that protects access to setDeclared() to only MooseApp.
void store(std::ostream &stream)
Stores the value into the stream stream and sets it as stored.
virtual void loadInternal(std::istream &stream)=0
Internal method that loads the value from the stream stream in the specialized class.
bool stored() const
Whether or not this data has been loaded.
virtual void storeJSONValue(nlohmann::json &json) const =0
Internal method for storing the underlying JSON value.
bool declared() const
Whether or not this data has been declared.
const std::string & name() const
The full (unique) name of this particular piece of data.
RestartableDataValue(const std::string &name, void *const context)
Constructor.
void setDeclared(const SetDeclaredKey)
Sets that this restartable value has been declared.
void load(std::istream &stream)
Loads the value from the stream stream and sets it as loaded.
virtual std::string type() const =0
String identifying the type of parameter stored.
virtual bool hasStoreJSON() const =0
bool _stored
Whether or not this has value has been stored.
bool _declared
Whether or not this data has been declared (true) or only retreived (false)
bool loaded() const
Whether or not this data has been loaded.
virtual void storeInternal(std::ostream &stream)=0
Internal method that stores the value into the stream stream in the specialized class.
bool _loaded
Whether or not this has value has been loaded.
Struct that represents parameters for how to store the JSON value via store.