Line data Source code
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 "FileInputStream.h" 11 : 12 : #include "MooseError.h" 13 : 14 : #include <fstream> 15 : 16 13078 : FileInputStream::FileInputStream(const std::string & filename) : InputStream(), _filename(filename) 17 : { 18 13078 : } 19 : 20 : std::shared_ptr<std::istream> 21 133584 : FileInputStream::get() const 22 : { 23 133584 : std::shared_ptr<std::istream> stream = std::make_unique<std::ifstream>(); 24 133584 : addSharedStream(stream); 25 : 26 133584 : auto & in = *static_cast<std::ifstream *>(stream.get()); 27 133584 : in.open(_filename.c_str(), std::ios::in | std::ios::binary); 28 133584 : if (in.fail()) 29 0 : mooseError("Unable to open file ", std::filesystem::absolute(_filename)); 30 : 31 133584 : return stream; 32 0 : } 33 : 34 : std::optional<std::filesystem::path> 35 14 : FileInputStream::getFilename() const 36 : { 37 14 : return _filename; 38 : }