| 52 | } |
| 53 | |
| 54 | void WireAttributes::set_attribute(const WireNetwork& wire_network, |
| 55 | const std::string& name, const MatrixFr& values) { |
| 56 | AttrMap::iterator itr = m_attr_map.find(name); |
| 57 | if (itr == m_attr_map.end()) { |
| 58 | throw_attribute_not_found_error(name); |
| 59 | } |
| 60 | |
| 61 | if (itr->second->get_attribute_type() == WireAttribute::VERTEX) { |
| 62 | if (values.rows() != wire_network.get_num_vertices()) { |
| 63 | std::stringstream err_msg; |
| 64 | err_msg << "Vertex attribute has " << values.rows() << " rows" << std::endl; |
| 65 | err_msg << "Expect " << wire_network.get_num_vertices() << " rows"; |
| 66 | throw RuntimeError(err_msg.str()); |
| 67 | } |
| 68 | } else { |
| 69 | if (values.rows() != wire_network.get_num_edges()) { |
| 70 | std::stringstream err_msg; |
| 71 | err_msg << "Edge attribute has " << values.rows() << " rows" << std::endl; |
| 72 | err_msg << "Expect " << wire_network.get_num_edges() << " rows"; |
| 73 | throw RuntimeError(err_msg.str()); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | itr->second->set_values(values); |
| 78 | } |
| 79 | |
| 80 | bool WireAttributes::is_vertex_attribute(const std::string& name) const { |
| 81 | AttrMap::const_iterator itr = m_attr_map.find(name); |