https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
const T & get () const
 
T & set ()
 
void reset ()
 Resets (destructs) the underlying data.
 
virtual std::string type () const override final
 String identifying the type of parameter stored.
 
virtual const std::type_info & typeId () const override final
 The type ID of the underlying data.
 
virtual bool hasStoreJSON () const override final
 
const std::string & name () const
 The full (unique) name of this particular piece of data.
 
void * context ()
 A context pointer for helping with load / store.
 
bool hasContext () const
 
bool declared () const
 Whether or not this data has been declared.
 
void setDeclared (const SetDeclaredKey)
 Sets that this restartable value has been declared.
 
bool loaded () const
 Whether or not this data has been loaded.
 
void setNotLoaded (const SetNotLoadedKey)
 Sets that this restartable value has been loaded.
 
bool stored () const
 Whether or not this data has been loaded.
 
void setNotStored (const SetNotStoredKey)
 Sets that this restartable value has been loaded.
 
void store (std::ostream &stream)
 Stores the value into the stream stream and sets it as stored.
 
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)
 
void load (std::istream &stream)
 Loads the value from the stream stream and sets it as loaded.
 

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.
 

Protected Member Functions

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

Protected Attributes

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

Private Attributes

std::unique_ptr< T > _value
 Stored value.
 
bool _declared
 Whether or not this data has been declared (true) or only retreived (false)
 
bool _loaded
 Whether or not this has value has been loaded.
 
bool _stored
 Whether or not this has value has been stored.
 

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 }
Abstract definition of a RestartableData value.
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.
std::unique_ptr< T > _value
Stored value.

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.

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

Referenced by RestartableDataValue::store().

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

Referenced by MeshMetaDataInterface::getMeshProperty().

◆ hasContext()

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

Definition at line 70 of file RestartableData.h.

70{ return _context != nullptr; }

Referenced by RestartableDataValue::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}
virtual void loadInternal(std::istream &stream)=0
Internal method that loads the value from the stream stream in the specialized class.
bool _loaded
Whether or not this has value has been loaded.

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

98{ return _loaded; }

Referenced by RestartableDataValue::store().

◆ 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 loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition DataIO.h:1081

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

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

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

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

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

289{
290 mooseAssert(_value, "Not valid");
291 return *_value;
292}

Referenced by MeshGenerator::declareMeshProperty(), and MeshGenerator::setMeshProperty().

◆ setDeclared()

void RestartableDataValue::setDeclared ( const SetDeclaredKey  )
inherited

Sets that this restartable value has been declared.

Definition at line 18 of file RestartableData.C.

19{
20 mooseAssert(!_declared, "Already declared");
21 _declared = true;
22}

Referenced by MooseApp::registerRestartableData().

◆ 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; }

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

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

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

121{ return _stored; }

Referenced by RestartableDataValue::store().

◆ 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 storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition DataIO.h:989

◆ 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.
const T & get() const

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

◆ _declared

bool RestartableDataValue::_declared
privateinherited

Whether or not this data has been declared (true) or only retreived (false)

Definition at line 201 of file RestartableData.h.

Referenced by RestartableDataValue::declared(), and RestartableDataValue::setDeclared().

◆ _loaded

bool RestartableDataValue::_loaded
privateinherited

Whether or not this has value has been loaded.

Definition at line 204 of file RestartableData.h.

Referenced by RestartableDataValue::load(), RestartableDataValue::loaded(), and RestartableDataValue::setNotLoaded().

◆ _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().

◆ _stored

bool RestartableDataValue::_stored
privateinherited

Whether or not this has value has been stored.

Definition at line 207 of file RestartableData.h.

Referenced by RestartableDataValue::setNotStored(), RestartableDataValue::store(), and RestartableDataValue::stored().

◆ _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>
staticconstexpr

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

Definition at line 219 of file RestartableData.h.

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


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