std::vector<EFANode *> EFAFragment::getCommonNodes(EFAFragment * other) const { std::set<EFANode *> frag1_nodes = getAllNodes(); std::set<EFANode *> frag2_nodes = other->getAllNodes(); std::vector<EFANode *> common_nodes = Efa::getCommonElems(frag1_nodes, frag2_nodes); return common_nodes; }
void ActionChoiceWindow::ActionNode::getAllNodes(ActionNode* treeRoot, NodeSet& nodes) { nodes.insert(treeRoot); const NodeSet children = treeRoot->getChildren(); for (NodeSet::const_iterator iter = children.begin(); iter != children.end(); iter++) getAllNodes(*iter, nodes); }
void EFAFragment3D::getNodeInfo(std::vector<std::vector<unsigned int>> & face_node_indices, std::vector<EFANode *> & nodes) const { // get all nodes' pointers - a vector std::set<EFANode *> all_node_set = getAllNodes(); nodes.resize(all_node_set.size()); std::copy(all_node_set.begin(), all_node_set.end(), nodes.begin()); // get face connectivity face_node_indices.clear(); for (unsigned int i = 0; i < _faces.size(); ++i) { std::vector<unsigned int> line_face_indices; for (unsigned int j = 0; j < _faces[i]->numNodes(); ++j) { EFANode * node = _faces[i]->getNode(j); unsigned int vec_index = std::find(nodes.begin(), nodes.end(), node) - nodes.begin(); line_face_indices.push_back(vec_index); } face_node_indices.push_back(line_face_indices); } }
ActionChoiceWindow::NodeSet ActionChoiceWindow::ActionNode::getAllNodesNotBelow( ActionNode* treeRoot, ActionChoiceWindow::ActionNode* targetNode) { NodeSet allNodes; getAllNodes(treeRoot, allNodes); NodeSet nodes; for (NodeSet::iterator iter = allNodes.begin(); iter != allNodes.end(); iter++) { bool leaveOut = false; if ((*iter)->getParent() == treeRoot || *iter == targetNode || (*iter)->getButton() == NULL) { leaveOut = true; continue; } ActionNode* node = *iter; while(node->getParent() != NULL) { node = node->getParent(); if (node == targetNode) { leaveOut = true; continue; } } if (!leaveOut) nodes.insert(*iter); } return nodes; }
void TunManager::sync(std::shared_ptr<SwitchState> state) { // prepare the existing and new addresses typedef Interface::Addresses Addresses; typedef boost::container::flat_map<RouterID, Addresses> AddrMap; AddrMap newAddrs; auto map = state->getInterfaces(); for (const auto& intf : map->getAllNodes()) { const auto& addrs = intf.second->getAddresses(); newAddrs[intf.second->getRouterID()].insert(addrs.begin(), addrs.end()); } AddrMap oldAddrs; auto newMinMtu = getMinMtu(state); for (const auto& intf : intfs_) { const auto& addrs = intf.second->getAddresses(); oldAddrs[intf.first].insert(addrs.begin(), addrs.end()); if (intf.second->getMtu() != newMinMtu) { intf.second->setMtu(newMinMtu); } } // now, lock all interfaces and apply changes. Interfaces will be stopped // if there is some change to the interface std::lock_guard<std::mutex> lock(mutex_); auto applyAddrChanges = [&](const std::string& name, RouterID rid, int ifIndex, const Addresses& oldAddrs, const Addresses& newAddrs) { applyChanges( oldAddrs, newAddrs, [&](Addresses::const_iterator& oldIter, Addresses::const_iterator& newIter) { if (oldIter->second == newIter->second) { // addresses and masks are both same return; } removeTunAddress(name, rid, ifIndex, oldIter->first, oldIter->second); addTunAddress(name, rid, ifIndex, newIter->first, newIter->second); }, [&](Addresses::const_iterator& newIter) { addTunAddress(name, rid, ifIndex, newIter->first, newIter->second); }, [&](Addresses::const_iterator& oldIter) { removeTunAddress(name, rid, ifIndex, oldIter->first, oldIter->second); }); }; applyChanges( oldAddrs, newAddrs, [&](const AddrMap::const_iterator& oldIter, const AddrMap::const_iterator& newIter) { const auto& oldAddrs = oldIter->second; const auto& newAddrs = newIter->second; auto iter = intfs_.find(oldIter->first); CHECK(iter != intfs_.end()); const auto& intf = iter->second; int ifIndex = intf->getIfIndex(); auto rid = intf->getRouterId(); const auto& name = intf->getName(); applyAddrChanges(name, rid, ifIndex, oldAddrs, newAddrs); iter->second->setAddresses(newAddrs); }, [&](const AddrMap::const_iterator& newIter) { addIntf(newIter->first, newIter->second); }, [&](const AddrMap::const_iterator& oldIter) { removeIntf(oldIter->first); }); start(); }