https://mooseframework.inl.gov
InputStream.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 "InputStream.h"
11 
12 #include "MooseError.h"
13 
15 {
16  if (inUse())
17  mooseError("Stream still in use");
18 }
19 
20 void
21 InputStream::addSharedStream(std::weak_ptr<std::istream> stream) const
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 }
33 
34 bool
36 {
37  for (auto & stream : _shared_streams)
38  if (!stream.expired())
39  return true;
40  return false;
41 }
42 
43 std::optional<std::filesystem::path>
45 {
46  return {};
47 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
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...
Definition: InputStream.C:21
std::vector< std::weak_ptr< std::istream > > _shared_streams
The streams that have been handed out by get()
Definition: InputStream.h:60
virtual ~InputStream()
Definition: InputStream.C:14
bool inUse() const
Whether or not anything is still using this stream.
Definition: InputStream.C:35
virtual std::optional< std::filesystem::path > getFilename() const
Gets the underlying filename, if any.
Definition: InputStream.C:44