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