www.mooseframework.org
MooseObject.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef MOOSEOBJECT_H
16 #define MOOSEOBJECT_H
17 
18 // MOOSE includes
19 #include "InputParameters.h"
20 #include "ConsoleStreamInterface.h"
21 
22 #include "libmesh/parallel_object.h"
23 
24 class MooseApp;
25 class MooseObject;
26 
27 template <>
29 
30 // needed to avoid #include cycle with MooseApp and MooseObject
31 [[noreturn]] void callMooseErrorRaw(std::string & msg, MooseApp * app);
32 
36 class MooseObject : public ConsoleStreamInterface, public libMesh::ParallelObject
37 {
38 public:
40 
41  virtual ~MooseObject() = default;
42 
47  const std::string & name() const { return _name; }
48 
53  const InputParameters & parameters() const { return _pars; }
54 
60  template <typename T>
61  const T & getParam(const std::string & name) const;
62 
67  inline bool isParamValid(const std::string & name) const { return _pars.isParamValid(name); }
68 
72  MooseApp & getMooseApp() { return _app; }
73 
77  virtual bool enabled() { return _enabled; }
78 
79  template <typename... Args>
80  [[noreturn]] void mooseError(Args &&... args) const
81  {
82  std::ostringstream oss;
83  moose::internal::mooseStreamAll(oss, std::forward<Args>(args)...);
84  std::string msg = oss.str();
85  callMooseErrorRaw(msg, &_app);
86  }
87 
88  template <typename... Args>
89  void mooseWarning(Args &&... args) const
90  {
91  moose::internal::mooseWarningStream(_console, std::forward<Args>(args)...);
92  }
93 
94  template <typename... Args>
95  void mooseDeprecated(Args &&... args) const
96  {
97  moose::internal::mooseDeprecatedStream(_console, std::forward<Args>(args)...);
98  }
99 
100  template <typename... Args>
101  void mooseInfo(Args &&... args) const
102  {
103  moose::internal::mooseInfoStream(_console, std::forward<Args>(args)...);
104  }
105 
106 protected:
109 
112 
114  const std::string & _name;
115 
117  const bool & _enabled;
118 };
119 
120 template <typename T>
121 const T &
122 MooseObject::getParam(const std::string & name) const
123 {
124  return InputParameters::getParamHelper(name, _pars, static_cast<T *>(0));
125 }
126 
127 #endif /* MOOSEOBJECT_H*/
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
void mooseDeprecatedStream(S &oss, Args &&...args)
Definition: MooseError.h:157
void mooseStreamAll(std::ostringstream &ss)
Definition: MooseError.C:78
static const T & getParamHelper(const std::string &name, const InputParameters &pars, const T *the_type)
void mooseWarning(Args &&...args) const
Definition: MooseObject.h:89
void callMooseErrorRaw(std::string &msg, MooseApp *app)
Definition: MooseObject.C:45
virtual ~MooseObject()=default
void mooseInfo(Args &&...args) const
Definition: MooseObject.h:101
void mooseWarningStream(S &oss, Args &&...args)
Definition: MooseError.h:129
MooseObject(const InputParameters &parameters)
Definition: MooseObject.C:35
virtual bool enabled()
Return the enabled status of the object.
Definition: MooseObject.h:77
Base class for MOOSE-based applications.
Definition: MooseApp.h:58
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
const bool & _enabled
Reference to the "enable" InputParaemters, used by Controls for toggling on/off MooseObjects.
Definition: MooseObject.h:117
void mooseInfoStream(S &oss, Args &&...args)
Definition: MooseError.h:145
An inteface for the _console for outputting to the Console object.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
Definition: MooseObject.h:111
MooseApp & getMooseApp()
Get the MooseApp this object is associated with.
Definition: MooseObject.h:72
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:22
void mooseDeprecated(Args &&...args) const
Definition: MooseObject.h:95
const std::string & _name
The name of this object, reference to value stored in InputParameters.
Definition: MooseObject.h:114
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.