https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ControllableItem.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 "ControllableItem.h"
11#include "ConsoleUtils.h"
12
15 const std::set<ExecFlagType> & flags)
16 : _execute_flags(flags)
17{
18 _pairs.emplace_back(name, value);
19}
20
22
23void
25{
26 for (const auto & pair : item->_pairs)
27 {
28 if (type_check && type() != pair.second->type())
29 mooseError("The master parameter (",
30 name(),
31 ") has a type '",
32 type(),
33 "' and cannot be connected to the parameter (",
34 pair.first,
35 ") with a different type of '",
36 pair.second->type(),
37 "'.");
38
39 _pairs.emplace_back(pair.first, pair.second);
40 }
41}
42
43std::string
44ControllableItem::dump(unsigned int indent /*=0*/) const
45{
46
47 // Count of objects, for printing a number with the parameter
48 unsigned int index = 0;
49
50 std::ostringstream oss;
51 for (const auto & pair : _pairs)
52 {
53 if (index == 0) // master parameter
54 oss << ConsoleUtils::indent(indent) << COLOR_GREEN << pair.first << COLOR_DEFAULT << " = ";
55 else // secondary parameters
56 oss << ConsoleUtils::indent(indent + 2) << COLOR_YELLOW << pair.first << COLOR_DEFAULT
57 << " = ";
58
59 pair.second->print(oss);
60 oss << " <" << pair.second->type() << ">" << '\n';
61 index++;
62 }
63 return oss.str();
64}
65
66std::string
68{
69 return _pairs[0].second->type();
70}
71
74{
75 return _pairs[0].first;
76}
77
79 : ControllableItem(), _name(name)
80{
81 connect(item, false);
82}
83
86{
87 return _name;
88}
89
90std::string
91ControllableAlias::dump(unsigned int indent /*=0*/) const
92{
93 // The output stream
94 std::ostringstream oss;
95 oss << ConsoleUtils::indent(indent) << COLOR_GREEN << _name << COLOR_DEFAULT;
96 for (const auto & pair : _pairs)
97 {
98 oss << ConsoleUtils::indent(indent + 2) << COLOR_YELLOW << pair.first << COLOR_DEFAULT << " = ";
99 pair.second->print(oss);
100 oss << " <" << pair.second->type() << ">\n";
101 }
102 return oss.str();
103}
104
105std::ostream &
106operator<<(std::ostream & stream, const ControllableItem & obj)
107{
108 return stream << obj.dump();
109}
std::ostream & operator<<(std::ostream &stream, const ControllableItem &obj)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
ControllableAlias(const MooseObjectParameterName &name, ControllableItem *)
virtual std::string dump(unsigned int indent=0) const override
Returns a string displaying the parameter name and current value.
MooseObjectParameterName _name
virtual const MooseObjectParameterName & name() const override
Return the name of the master parameter.
An intermediate object for building a "controllable item", where an "item" can refer to multiple inpu...
std::vector< std::pair< MooseObjectParameterName, libMesh::Parameters::Value * > > _pairs
List of names for this item.
ControllableItem()
Constructor for creating an empty item (see ControllableAlias)
virtual std::string dump(unsigned int indent=0) const
Returns a string displaying the parameter name and current value.
virtual const MooseObjectParameterName & name() const
Return the name of the master parameter.
void connect(ControllableItem *item, bool type_check=true)
Connects the supplied item with this item to allow for multiple parameters to be changed by one.
std::string type() const
Return the type of the master parameter.
A class for storing an input parameter name.
std::string indent(unsigned int spaces)
Create empty string for indenting.