https://mooseframework.inl.gov
JSONFileReader.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 "JSONFileReader.h"
11 
12 #include "MooseUtils.h"
13 #include "json.h"
14 
16 
19 {
21  // Add parameters
22  params.addRequiredParam<FileName>("filename", "The path to the file including its name");
23  // we run this object once at the initialization by default
24  params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
25  params.addClassDescription("Loads a JSON file and makes it content available to consumers");
26  return params;
27 }
28 
30  : GeneralUserObject(parameters), _filename(getParam<FileName>("filename"))
31 {
32  read(_filename);
33 }
34 
35 void
36 JSONFileReader::read(const FileName & filename)
37 {
39  // Read the JSON database
40  std::ifstream jsondata(filename);
41  jsondata >> _root;
42 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
JSONFileReader(const InputParameters &parameters)
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
nlohmann::json _root
JSON data.
User object that reads a JSON file and makes its data available to other objects. ...
void read(const FileName &filename)
Read the JSON file and load it into _root.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:250
const FileName & _filename
Database filename.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
registerMooseObject("MooseApp", JSONFileReader)
static InputParameters validParams()
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28