Beispiel #1
0
void Topology::addEdge(const Pair <std::string, std::string> &nodes, const Edge &edge) {
	if(! this->hasNode(nodes.first)) 
		throw NodeNotFoundException(nodes.first);
	else if(! this->hasNode(nodes.second))
		throw NodeNotFoundException(nodes.second);

	//Create a fnss::Pair that is commutative if the topology is not directed
	Pair<std::string, std::string> key(nodes);
	key.setCommutative(! this->directed);

	this->edges[key] = edge;
}
Beispiel #2
0
Node Topology::getNode(const std::string &id) const {
	nodesType::const_iterator it = this->nodes.find(id);
	if(it == this->nodes.end())
		throw NodeNotFoundException(id);
	
	return it->second;	
}
Beispiel #3
0
int InternalNode::nodeIndex(Node *aNode) const
{
    for (size_t i = 0; i < size(); ++i) {
        if (fMappings[i].second == aNode) {
            return static_cast<int>(i);
        }
    }
    throw NodeNotFoundException(aNode->toString(), toString());
}
Beispiel #4
0
Node Topology::removeNode(const std::string &id, bool pruneEdges) {
	nodesType::iterator it = this->nodes.find(id);
	if(it == this->nodes.end())
		throw NodeNotFoundException(id);

	Node ret = it->second;
	this->nodes.erase(it);

	if(pruneEdges) {
		std::queue<edgesType::iterator> eraseQueue;
		edgesType::iterator it;
		for(it = this->edges.begin(); it != this->edges.end(); it++) {
			if(it->first.first == id || it->first.second == id)
				eraseQueue.push(it);
		}

		while(! eraseQueue.empty()) {
			this->edges.erase(eraseQueue.front());
			eraseQueue.pop();
		}
	}

	return ret;
}