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 "ControllableItem.h" 11 : #include "ConsoleUtils.h" 12 : 13 1470170 : ControllableItem::ControllableItem(const MooseObjectParameterName & name, 14 : libMesh::Parameters::Value * value, 15 1470170 : const std::set<ExecFlagType> & flags) 16 1470170 : : _execute_flags(flags) 17 : { 18 1470170 : _pairs.emplace_back(name, value); 19 1470170 : } 20 : 21 17 : ControllableItem::ControllableItem() {} 22 : 23 : void 24 41656 : ControllableItem::connect(ControllableItem * item, bool type_check) 25 : { 26 83446 : for (const auto & pair : item->_pairs) 27 : { 28 41792 : if (type_check && type() != pair.second->type()) 29 2 : mooseError("The master parameter (", 30 2 : name(), 31 : ") has a type '", 32 4 : type(), 33 : "' and cannot be connected to the parameter (", 34 2 : pair.first, 35 : ") with a different type of '", 36 6 : pair.second->type(), 37 : "'."); 38 : 39 41790 : _pairs.emplace_back(pair.first, pair.second); 40 : } 41 41654 : } 42 : 43 : std::string 44 294 : ControllableItem::dump(unsigned int indent /*=0*/) const 45 : { 46 : 47 : // Count of objects, for printing a number with the parameter 48 294 : unsigned int index = 0; 49 : 50 294 : std::ostringstream oss; 51 592 : for (const auto & pair : _pairs) 52 : { 53 298 : if (index == 0) // master parameter 54 294 : oss << ConsoleUtils::indent(indent) << COLOR_GREEN << pair.first << COLOR_DEFAULT << " = "; 55 : else // secondary parameters 56 8 : oss << ConsoleUtils::indent(indent + 2) << COLOR_YELLOW << pair.first << COLOR_DEFAULT 57 4 : << " = "; 58 : 59 298 : pair.second->print(oss); 60 298 : oss << " <" << pair.second->type() << ">" << '\n'; 61 298 : index++; 62 : } 63 588 : return oss.str(); 64 294 : } 65 : 66 : std::string 67 41779 : ControllableItem::type() const 68 : { 69 41779 : return _pairs[0].second->type(); 70 : } 71 : 72 : const MooseObjectParameterName & 73 1929608 : ControllableItem::name() const 74 : { 75 1929608 : return _pairs[0].first; 76 : } 77 : 78 17 : ControllableAlias::ControllableAlias(const MooseObjectParameterName & name, ControllableItem * item) 79 17 : : ControllableItem(), _name(name) 80 : { 81 17 : connect(item, false); 82 17 : } 83 : 84 : const MooseObjectParameterName & 85 15 : ControllableAlias::name() const 86 : { 87 15 : return _name; 88 : } 89 : 90 : std::string 91 2 : ControllableAlias::dump(unsigned int indent /*=0*/) const 92 : { 93 : // The output stream 94 2 : std::ostringstream oss; 95 2 : oss << ConsoleUtils::indent(indent) << COLOR_GREEN << _name << COLOR_DEFAULT; 96 4 : for (const auto & pair : _pairs) 97 : { 98 2 : oss << ConsoleUtils::indent(indent + 2) << COLOR_YELLOW << pair.first << COLOR_DEFAULT << " = "; 99 2 : pair.second->print(oss); 100 2 : oss << " <" << pair.second->type() << ">\n"; 101 : } 102 4 : return oss.str(); 103 2 : } 104 : 105 : std::ostream & 106 0 : operator<<(std::ostream & stream, const ControllableItem & obj) 107 : { 108 0 : return stream << obj.dump(); 109 : }