Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
RestartableData< T > Class Template Reference

Concrete definition of a parameter value for a specified type. More...

#include <RestartableData.h>

Inheritance diagram for RestartableData< T >:
[legend]

Public Member Functions

template<typename... Params>
 RestartableData (const std::string &name, void *const context, Params &&... args)
 Constructor. More...
 
const T & get () const
 
T & set ()
 
void reset ()
 Resets (destructs) the underlying data. More...
 
virtual std::string type () const override final
 String identifying the type of parameter stored. More...
 
virtual const std::type_info & typeId () const override final
 The type ID of the underlying data. More...
 
virtual bool hasStoreJSON () const override final
 
const std::string & name () const
 The full (unique) name of this particular piece of data. More...
 
voidcontext ()
 A context pointer for helping with load / store. More...
 
bool hasContext () const
 
bool declared () const
 Whether or not this data has been declared. More...
 
void setDeclared (const SetDeclaredKey)
 Sets that this restartable value has been declared. More...
 
bool loaded () const
 Whether or not this data has been loaded. More...
 
void setNotLoaded (const SetNotLoadedKey)
 Sets that this restartable value has been loaded. More...
 
bool stored () const
 Whether or not this data has been loaded. More...
 
void setNotStored (const SetNotStoredKey)
 Sets that this restartable value has been loaded. More...
 
void store (std::ostream &stream)
 Stores the value into the stream stream and sets it as stored. More...
 
void store (nlohmann::json &json, const StoreJSONParams &params=StoreJSONParams{}) const
 Stores this restartable data in the JSON entry json, with the options set by params (optional; defaults to just the type and underlying value) More...
 
void load (std::istream &stream)
 Loads the value from the stream stream and sets it as loaded. More...
 

Static Public Attributes

static constexpr bool has_store_json = std::is_constructible_v<nlohmann::json, T>
 Whether or not this type has a JSON store method implemented. More...
 

Protected Member Functions

virtual void storeInternal (std::ostream &stream) override
 Store the RestartableData into a binary stream. More...
 
virtual void loadInternal (std::istream &stream) override
 Load the RestartableData from a binary stream. More...
 
virtual void storeJSONValue (nlohmann::json &json) const override final
 Internal method for storing the underlying JSON value. More...
 

Protected Attributes

const std::string _name
 The full (unique) name of this particular piece of data. More...
 
void *const _context
 A context pointer for helping with load and store. More...
 

Private Attributes

std::unique_ptr< T > _value
 Stored value. More...
 

Detailed Description

template<typename T>
class RestartableData< T >

Concrete definition of a parameter value for a specified type.

Definition at line 215 of file RestartableData.h.

Constructor & Destructor Documentation

◆ RestartableData()

template<typename T>
template<typename... Params>
RestartableData< T >::RestartableData ( const std::string &  name,
void *const  context,
Params &&...  args 
)
inline

Constructor.

Parameters
nameThe full (unique) name for this piece of data.
context'typeless' pointer to user-specific data.
argForwarded arguments that are passed to the constructor of the data.

Definition at line 228 of file RestartableData.h.

230  _value(std::make_unique<T>(std::forward<Params>(args)...))
231  {
232  }
std::unique_ptr< T > _value
Stored value.
RestartableDataValue(const std::string &name, void *const context)
Constructor.
void * context()
A context pointer for helping with load / store.
const std::string & name() const
The full (unique) name of this particular piece of data.

Member Function Documentation

◆ context()

void* RestartableDataValue::context ( )
inlineinherited

A context pointer for helping with load / store.

Definition at line 65 of file RestartableData.h.

65 { return _context; }
void *const _context
A context pointer for helping with load and store.

◆ declared()

bool RestartableDataValue::declared ( ) const
inlineinherited

Whether or not this data has been declared.

Definition at line 85 of file RestartableData.h.

Referenced by RestartableDataValue::store().

85 { return _declared; }
bool _declared
Whether or not this data has been declared (true) or only retreived (false)

◆ get()

template<typename T >
const T & RestartableData< T >::get ( ) const
inline
Returns
a read-only reference to the parameter value.

Definition at line 280 of file RestartableData.h.

281 {
282  mooseAssert(_value, "Not valid");
283  return *_value;
284 }
std::unique_ptr< T > _value
Stored value.

◆ hasContext()

bool RestartableDataValue::hasContext ( ) const
inlineinherited
Returns
Whether or not the data has context set.

Definition at line 70 of file RestartableData.h.

Referenced by RestartableDataValue::store().

70 { return _context != nullptr; }
void *const _context
A context pointer for helping with load and store.

◆ hasStoreJSON()

template<typename T>
virtual bool RestartableData< T >::hasStoreJSON ( ) const
inlinefinaloverridevirtual
Returns
Whether or not this value supports storing JSON via store

Implements RestartableDataValue.

Definition at line 256 of file RestartableData.h.

256 { return has_store_json; }
static constexpr bool has_store_json
Whether or not this type has a JSON store method implemented.

◆ load()

void RestartableDataValue::load ( std::istream &  stream)
inherited

Loads the value from the stream stream and sets it as loaded.

Definition at line 32 of file RestartableData.C.

33 {
34  loadInternal(stream);
35  _loaded = true;
36 }
bool _loaded
Whether or not this has value has been loaded.
virtual void loadInternal(std::istream &stream)=0
Internal method that loads the value from the stream stream in the specialized class.

◆ loaded()

bool RestartableDataValue::loaded ( ) const
inlineinherited

Whether or not this data has been loaded.

This is typically reset on a call to RestartableDataReader::restore()

Definition at line 98 of file RestartableData.h.

Referenced by RestartableDataValue::store().

98 { return _loaded; }
bool _loaded
Whether or not this has value has been loaded.

◆ loadInternal()

template<typename T >
void RestartableData< T >::loadInternal ( std::istream &  stream)
inlineoverrideprotectedvirtual

Load the RestartableData from a binary stream.

Implements RestartableDataValue.

Reimplemented in ReporterState< T >, and ReporterState< std::vector< T > >.

Definition at line 318 of file RestartableData.h.

319 {
320  loadHelper(stream, set(), _context);
321 }
void *const _context
A context pointer for helping with load and store.
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:985

◆ name()

const std::string& RestartableDataValue::name ( ) const
inlineinherited

The full (unique) name of this particular piece of data.

Definition at line 60 of file RestartableData.h.

Referenced by RestartableDataMap::addData(), RestartableDataMap::findData(), and RestartableDataValue::store().

60 { return _name; }
const std::string _name
The full (unique) name of this particular piece of data.

◆ reset()

template<typename T >
void RestartableData< T >::reset ( )
inline

Resets (destructs) the underlying data.

Definition at line 296 of file RestartableData.h.

297 {
298  mooseAssert(_value, "Not valid"); // shouldn't really call this twice
299  _value.reset();
300 }
std::unique_ptr< T > _value
Stored value.

◆ set()

template<typename T >
T & RestartableData< T >::set ( )
inline
Returns
a writable reference to the parameter value.

Definition at line 288 of file RestartableData.h.

Referenced by MeshGenerator::setMeshProperty().

289 {
290  mooseAssert(_value, "Not valid");
291  return *_value;
292 }
std::unique_ptr< T > _value
Stored value.

◆ setDeclared()

void RestartableDataValue::setDeclared ( const SetDeclaredKey  )
inherited

Sets that this restartable value has been declared.

Definition at line 18 of file RestartableData.C.

Referenced by MooseApp::registerRestartableData().

19 {
20  mooseAssert(!_declared, "Already declared");
21  _declared = true;
22 }
bool _declared
Whether or not this data has been declared (true) or only retreived (false)

◆ setNotLoaded()

void RestartableDataValue::setNotLoaded ( const SetNotLoadedKey  )
inlineinherited

Sets that this restartable value has been loaded.

Definition at line 113 of file RestartableData.h.

113 { _loaded = false; }
bool _loaded
Whether or not this has value has been loaded.

◆ setNotStored()

void RestartableDataValue::setNotStored ( const SetNotStoredKey  )
inlineinherited

Sets that this restartable value has been loaded.

Definition at line 136 of file RestartableData.h.

136 { _stored = false; }
bool _stored
Whether or not this has value has been stored.

◆ store() [1/2]

void RestartableDataValue::store ( std::ostream &  stream)
inherited

Stores the value into the stream stream and sets it as stored.

Definition at line 25 of file RestartableData.C.

26 {
27  storeInternal(stream);
28  _stored = true;
29 }
virtual void storeInternal(std::ostream &stream)=0
Internal method that stores the value into the stream stream in the specialized class.
bool _stored
Whether or not this has value has been stored.

◆ store() [2/2]

void RestartableDataValue::store ( nlohmann::json &  json,
const StoreJSONParams params = StoreJSONParams{} 
) const
inherited

Stores this restartable data in the JSON entry json, with the options set by params (optional; defaults to just the type and underlying value)

If the underlying type is not supported for JSON output (if hasStoreJSON() == false), and the parameters have the value output as enabled, this will error.

Definition at line 39 of file RestartableData.C.

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 }
bool stored() const
Whether or not this data has been loaded.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
virtual bool hasStoreJSON() const =0
bool hasContext() const
virtual void storeJSONValue(nlohmann::json &json) const =0
Internal method for storing the underlying JSON value.
virtual std::string type() const =0
String identifying the type of parameter stored.
bool loaded() const
Whether or not this data has been loaded.
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.

◆ stored()

bool RestartableDataValue::stored ( ) const
inlineinherited

Whether or not this data has been loaded.

This is typically reset on a call to RestartableDataWriter::write()

Definition at line 121 of file RestartableData.h.

Referenced by RestartableDataValue::store().

121 { return _stored; }
bool _stored
Whether or not this has value has been stored.

◆ storeInternal()

template<typename T >
void RestartableData< T >::storeInternal ( std::ostream &  stream)
inlineoverrideprotectedvirtual

Store the RestartableData into a binary stream.

Implements RestartableDataValue.

Reimplemented in ReporterState< T >, and ReporterState< std::vector< T > >.

Definition at line 311 of file RestartableData.h.

312 {
313  storeHelper(stream, set(), _context);
314 }
void *const _context
A context pointer for helping with load and store.
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:893

◆ storeJSONValue()

template<typename T >
void RestartableData< T >::storeJSONValue ( nlohmann::json &  json) const
inlinefinaloverrideprotectedvirtual

Internal method for storing the underlying JSON value.

Implements RestartableDataValue.

Definition at line 325 of file RestartableData.h.

326 {
328  nlohmann::to_json(json, get());
329  else
330  mooseAssert(false, "Should not be called");
331 }
Concrete definition of a parameter value for a specified type.
void to_json(nlohmann::json &json, const Moose::LibtorchArtificialNeuralNet *const &network)

◆ type()

template<typename T >
std::string RestartableData< T >::type ( ) const
inlinefinaloverridevirtual

String identifying the type of parameter stored.

Implements RestartableDataValue.

Definition at line 304 of file RestartableData.h.

305 {
306  return MooseUtils::prettyCppType<T>();
307 }

◆ typeId()

template<typename T>
virtual const std::type_info& RestartableData< T >::typeId ( ) const
inlinefinaloverridevirtual

The type ID of the underlying data.

Implements RestartableDataValue.

Definition at line 254 of file RestartableData.h.

254 { return typeid(T); }

Member Data Documentation

◆ _context

void* const RestartableDataValue::_context
protectedinherited

A context pointer for helping with load and store.

Definition at line 197 of file RestartableData.h.

Referenced by RestartableDataValue::context(), and RestartableDataValue::hasContext().

◆ _name

const std::string RestartableDataValue::_name
protectedinherited

The full (unique) name of this particular piece of data.

Definition at line 194 of file RestartableData.h.

Referenced by RestartableDataValue::name().

◆ _value

template<typename T>
std::unique_ptr<T> RestartableData< T >::_value
private

Stored value.

Definition at line 273 of file RestartableData.h.

◆ has_store_json

template<typename T>
constexpr bool RestartableData< T >::has_store_json = std::is_constructible_v<nlohmann::json, T>
static

Whether or not this type has a JSON store method implemented.

Definition at line 219 of file RestartableData.h.

Referenced by RestartableData< std::list< T > >::hasStoreJSON().


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