inline void operator()(boost::any& to_set, const boost::any& new_value) { if(new_value.type() == to_set.type()) { to_set = new_value; } else { try { std::vector<int> int_vals = boost::any_cast< std::vector<int> >(new_value); const Uint nb_vals = int_vals.size(); std::vector<Uint> result(nb_vals); for(Uint i = 0; i != nb_vals; ++i) { if(int_vals[i] < 0) { std::stringstream err; err << "Tried to store a negative value in an unsigned int option array at index " << i; throw BadValue(FromHere(), err.str()); } result[i] = static_cast<Uint>(int_vals[i]); } to_set = result; } catch(boost::bad_any_cast& e) { throw CastingFailed(FromHere(), std::string("Failed to cast object of type ") + new_value.type().name() + " to type std::vector<Uint>"); } } }
void FieldGenerator::signal_update(Common::SignalArgs& node) { Component::Ptr mesh_component = access_component_ptr(URI(option("Mesh").value_str())); if(!mesh_component) throw ValueNotFound(FromHere(), "The path for the mesh is incorrect"); CMesh::Ptr mesh = boost::dynamic_pointer_cast<CMesh>(mesh_component); if(!mesh) throw BadValue(FromHere(), "The given path does not point to a mesh"); const std::string field_name = option("FieldName").value_str(); const std::string var_name = option("VariableName").value_str(); const Real value = option("Value").value<Real>(); // Get the field, if it exists CField::Ptr field = boost::dynamic_pointer_cast<CField>(mesh->get_child_ptr(field_name)); // We can update the field if it exists AND contains the variable that we need if(field && !field->has_variable(var_name)) { throw ValueExists(FromHere(), "A field with name " + field_name + " already exists, but it does not contain a variable named " + var_name); } // If the field didn't exist, we create it if(!field) { mesh->create_scalar_field(field_name, var_name, CF::Mesh::CField::Basis::POINT_BASED); } // Proto placeholder MeshTerm<0, ScalarField> s(field_name, var_name); // Update the field value for_each_node(mesh->topology(), s = value); }
TreeView::TreeView(CentralPanel * optionsPanel, QMainWindow * parent, bool contextMenuAllowed) : QTreeView(parent), m_context_menu_allowed(contextMenuAllowed) { if(m_context_menu_allowed && optionsPanel == nullptr) throw BadValue(FromHere(), "Options panel is a nullptr pointer"); // instantiate class attributes m_model_filter = new FilteringModel(this); m_central_panel = optionsPanel; m_signal_manager = new SignalManager(parent); m_model_filter->setSourceModel(NTree::global().get()); m_model_filter->setDynamicSortFilter(true); this->setModel(m_model_filter); this->set_read_only(false); // when right clicking on the Client, // a "Context menu event" must be generated this->setContextMenuPolicy(Qt::CustomContextMenu); this->header()->setResizeMode(QHeaderView::ResizeToContents); this->header()->setStretchLastSection(true); if(m_context_menu_allowed) { connect(NTree::global().get(), SIGNAL(current_index_changed(QModelIndex, QModelIndex)), this, SLOT(current_index_changed(QModelIndex, QModelIndex))); } }
/// Write-only accessor to _frameType. void setFrameType(const std::string frameTypeStr) { switch (tolower(frameTypeStr[0])) { case 'p': _frameType = "PCap"; break; case 'l': _frameType = "LinuxTap"; break; case 'i': _frameType = "IEEE"; break; default: throw BadValue("Unrecognized value '" + frameTypeStr + "' provided for frame type."); } }
CLink& CLink::link_to ( Component::Ptr lnkto ) { if ( is_null(lnkto) ) throw BadValue(FromHere(), "Cannot link to null component"); if (lnkto->is_link()) throw SetupError(FromHere(), "Cannot link a CLink to another CLink"); m_link_component = lnkto; return *this; }
// reads out, converted to real axis length. bool get (Fractal::Value& res) const { Fractal::Value t = 0; if (!get_raw(t)) throw BadValue("Sorry, could not parse zoom control value"); switch(mode) { case RE_AX: res = t; break; case IM_AX: res = im_to_re(t); break; case RE_PIX: res = pix_to_ax(t); break; case IM_PIX: res = pix_to_ax(im_to_re(t)); break; case ZOOM: res = zoom_to_ax(t); break; } // At this point res is the requested real axis length. Use the same limit (more or less) as MainWindow applies. if (std::isinf(res)) // zoom factor 0 throw BadValue("Sorry, that zoom is not valid"); Fractal::Value limit = 2.099 * _mw->get_rwidth() * Fractal::Maths::smallest_min_pixel_size(); if (res < limit) throw BadValue("Sorry, that zoom is too deep, pixels would be smaller than the resolution limit"); return true; }
// Sets the value of a cell (r,c) to v. void Board::set(short r, short c, unsigned char v) { if (v >= 1 && v <= size) { // For valid values only. if (ifEmpty(r,c)) { // for empty cells. empty[r][c] = false; nEmpty--; }; board[r][c] = v; } else if (v == 0) makeEmpty(r, c); // v=0 means empty. else throw BadValue(); // v is not valid. };
void C3DViewBuilder::signal_create_3dview(SignalArgs &args) { SignalOptions options( args ); std::string name = options.value<std::string>("3DView name"); URI parent = options.value<URI>("Parent"); // some checks if(name.empty()) throw BadValue(FromHere(), "The 3DView name is empty."); if(parent.empty()) throw BadValue(FromHere(), "The parent is empty."); if(parent.scheme() != URI::Scheme::CPATH) throw InvalidURI(FromHere(), "The parent scheme is not CPATH"); // create and add the component Handle<Component> parent_comp = Core::instance().root().access_component(parent); Handle<C3DView> view = parent_comp->create_component<C3DView>( name ); view->mark_basic(); }
void CPlotter::signal_create_xyplot(SignalArgs &args) { SignalOptions options( args ); std::string name = options.value<std::string>("Plot name"); URI parent = options.value<URI>("Parent"); // some checks if(name.empty()) throw BadValue(FromHere(), "The plot name is empty."); if(parent.empty()) throw BadValue(FromHere(), "The parent is empty."); if(parent.scheme() != URI::Scheme::CPATH) throw InvalidURI(FromHere(), "The parent scheme is not CPATH"); // create and add the component Handle< Component > parent_comp = Core::instance().root().access_component(parent); boost::shared_ptr< CPlotXY > plot(common::allocate_component<CPlotXY>(name)); parent_comp->add_component( plot ); plot->mark_basic(); plot->set_data(m_data); }
void NetworkQueue::insert_transaction( const QString & uuid, NetworkQueue::Priority priority ) { if ( !m_new_transactions.contains(uuid) ) throw ValueNotFound( FromHere(), "No transaction found with UuiD [" + uuid.toStdString() + "]."); else { Transaction * transaction = m_new_transactions[uuid]; switch ( priority ) { case HIGH: m_transactions.prepend( transaction ); m_current_index++; break; case MEDIUM: if( m_current_index == -1 ) m_transactions.append( transaction ); else { m_transactions.insert( m_current_index, transaction ); m_current_index++; } break; case LOW: m_transactions.append( transaction ); break; case IMMEDIATE: throw BadValue( FromHere(), "Immediate priority cannot be applied to a transaction." ); } start(); // run the transaction (ignored if another one is already being executed) SignalFrame args = transaction->actions[0]; m_new_transactions.remove( uuid ); } }
void TwoSstar::config_order() { m_coeffs->options().set( "order", options().value<Uint>("order") ); std::vector<Real> alpha; std::vector<Real> beta; std::vector<Real> gamma; // Set defaults Values switch ( m_coeffs->order() ) { case 1: // Simple Forward Euler alpha += 0.; beta += 1.0; gamma += 0.0; break; case 2: // R-K 2 alpha += 0.0, 0.0; beta += 0.5, 1.0; gamma += 0.0, 0.5; break; case 3: // 3rd order TVD R-K scheme alpha += 0.0, 1.0/4.0, 2.0/3.0; beta += 1.0, 1.0/4.0, 2.0/3.0; gamma += 0.0, 0.5, 1.0; break; case 4: // R-K 4 alpha += 0.0, 0.0, 0.0, 0.0; beta += 1.0/4.0, 1.0/3.0, 1.0/2.0, 1.0; gamma += 0.0, 0.5, 0.5, 1.0; break; } if (gamma[0] != 0) throw BadValue(FromHere(),"gamma[0] must be zero for consistent time marching"); m_coeffs->options().set("alpha",alpha); m_coeffs->options().set("beta",beta); m_coeffs->options().set("gamma",gamma); }
/// constructor /// @param name the component will appear under this name PEObjectWrapperMultiArray(const std::string& name) : PEObjectWrapper(name) { throw BadValue( FromHere() , "There is no PEObjectWrapper for boost::multi_array with this dimension. Make specialization (see example for dim=1 and dim=2)" ); }