https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
33}
34
35void
36JSONFileReader::read(const FileName & filename)
37{
39 // Read the JSON database
40 std::ifstream jsondata(filename);
41 jsondata >> _root;
42}
registerMooseObject("MooseApp", JSONFileReader)
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
A MultiMooseEnum object to hold "execute_on" flags.
static InputParameters validParams()
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...
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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.
const FileName & _filename
Database filename.
static InputParameters validParams()
JSONFileReader(const InputParameters &parameters)
nlohmann::json _root
JSON data.
bool checkFileReadable(const std::string &filename, bool check_line_endings, bool throw_on_unreadable, bool check_for_git_lfs_pointer)
Definition MooseUtils.C:265