https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
InputStream Class Referenceabstract

Helper class that hands out input streams to an underlying, managed stream of arbitrary type. More...

#include <InputStream.h>

Inheritance diagram for InputStream:
[legend]

Public Member Functions

virtual ~InputStream ()
 
virtual std::shared_ptr< std::istream > get () const =0
 Gets an input stream to the underlying stream. More...
 
bool inUse () const
 Whether or not anything is still using this stream. More...
 
virtual std::optional< std::filesystem::path > getFilename () const
 Gets the underlying filename, if any. More...
 

Protected Member Functions

void addSharedStream (const std::weak_ptr< std::istream > stream) const
 Internal method to be called by derived classes to add a shared stream to _shared_streams (so that it can be tracked). More...
 

Private Attributes

std::vector< std::weak_ptr< std::istream > > _shared_streams
 The streams that have been handed out by get() More...
 

Detailed Description

Helper class that hands out input streams to an underlying, managed stream of arbitrary type.

Definition at line 22 of file InputStream.h.

Constructor & Destructor Documentation

◆ ~InputStream()

InputStream::~InputStream ( )
virtual

Definition at line 14 of file InputStream.C.

15 {
16  if (inUse())
17  mooseError("Stream still in use");
18 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
bool inUse() const
Whether or not anything is still using this stream.
Definition: InputStream.C:35

Member Function Documentation

◆ addSharedStream()

void InputStream::addSharedStream ( const std::weak_ptr< std::istream >  stream) const
protected

Internal method to be called by derived classes to add a shared stream to _shared_streams (so that it can be tracked).

Should be called in the overridden get() by derived classes.

Definition at line 21 of file InputStream.C.

Referenced by FileInputStream::get(), and StringInputStream::get().

22 {
23  mooseAssert(!stream.expired(), "Stream is expired");
24 
25  for (auto & entry : _shared_streams)
26  if (entry.expired())
27  {
28  entry = stream;
29  return;
30  }
31  _shared_streams.push_back(stream);
32 }
std::vector< std::weak_ptr< std::istream > > _shared_streams
The streams that have been handed out by get()
Definition: InputStream.h:60

◆ get()

virtual std::shared_ptr<std::istream> InputStream::get ( ) const
pure virtual

Gets an input stream to the underlying stream.

This is returned as a shared_ptr so that this class can tell whether or not another object is still using the stream.

Implemented in StringInputStream, and FileInputStream.

Referenced by RestartableDataReader::deserializeValue(), and RestartableDataReader::readHeader().

◆ getFilename()

std::optional< std::filesystem::path > InputStream::getFilename ( ) const
virtual

Gets the underlying filename, if any.

Reimplemented in FileInputStream.

Definition at line 44 of file InputStream.C.

Referenced by RestartableDataReader::deserializeValue(), and RestartableDataReader::readHeader().

45 {
46  return {};
47 }

◆ inUse()

bool InputStream::inUse ( ) const

Whether or not anything is still using this stream.

This is checked by seeing whether or not the use count of any of the streams handed out by get() is > 1 (with the only use count being the one stored in _shared_streams)

Definition at line 35 of file InputStream.C.

Referenced by StringInputStream::release(), and ~InputStream().

36 {
37  for (auto & stream : _shared_streams)
38  if (!stream.expired())
39  return true;
40  return false;
41 }
std::vector< std::weak_ptr< std::istream > > _shared_streams
The streams that have been handed out by get()
Definition: InputStream.h:60

Member Data Documentation

◆ _shared_streams

std::vector<std::weak_ptr<std::istream> > InputStream::_shared_streams
mutableprivate

The streams that have been handed out by get()

Definition at line 60 of file InputStream.h.

Referenced by addSharedStream(), and inUse().


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