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 "JSONFileReader.h" 11 : 12 : #include "MooseUtils.h" 13 : #include "json.h" 14 : 15 : registerMooseObject("MooseApp", JSONFileReader); 16 : 17 : InputParameters 18 14293 : JSONFileReader::validParams() 19 : { 20 14293 : InputParameters params = GeneralUserObject::validParams(); 21 : // Add parameters 22 14293 : params.addRequiredParam<FileName>("filename", "The path to the file including its name"); 23 : // we run this object once at the initialization by default 24 14293 : params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; 25 14293 : params.addClassDescription("Loads a JSON file and makes it content available to consumers"); 26 14293 : return params; 27 0 : } 28 : 29 14 : JSONFileReader::JSONFileReader(const InputParameters & parameters) 30 14 : : GeneralUserObject(parameters), _filename(getParam<FileName>("filename")) 31 : { 32 14 : read(_filename); 33 14 : } 34 : 35 : void 36 25 : JSONFileReader::read(const FileName & filename) 37 : { 38 25 : MooseUtils::checkFileReadable(filename); 39 : // Read the JSON database 40 25 : std::ifstream jsondata(filename); 41 25 : jsondata >> _root; 42 25 : }