https://mooseframework.inl.gov
Loading...
Searching...
No Matches
StringInputStream.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 "StringInputStream.h"
11
12#include "MooseError.h"
13
14StringInputStream::StringInputStream(std::unique_ptr<std::stringstream> stream)
15 : InputStream(), _stream(std::move(stream))
16{
17}
18
19std::shared_ptr<std::istream>
21{
22 mooseAssert(_stream, "Not valid");
23
24 std::shared_ptr<std::istream> stream = std::make_unique<std::istream>(_stream->rdbuf());
25 addSharedStream(stream);
26 return stream;
27}
28
29std::unique_ptr<std::stringstream>
31{
32 if (inUse())
33 mooseError("StringInputStream::release(): Cannot release; still in use");
34 return std::move(_stream);
35}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Helper class that hands out input streams to an underlying, managed stream of arbitrary type.
Definition InputStream.h:23
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
bool inUse() const
Whether or not anything is still using this stream.
Definition InputStream.C:35
std::unique_ptr< std::stringstream > _stream
The underlying stringstream.
virtual std::shared_ptr< std::istream > get() const override final
Gets an input stream to the underlying stream.
StringInputStream(std::unique_ptr< std::stringstream > stream)
std::unique_ptr< std::stringstream > release()
Releases the owned stringstream.