示例#1
0
std::vector< Edge::sptr > Graph::getEdges( Node::csptr node, bool upStream, std::string nature , std::string portID)
{
    OSLM_ASSERT("Node "<<node->getID() <<" not found in graph", m_nodes.find( Node::constCast(node) ) != m_nodes.end() );
    OSLM_ASSERT("Port "<< portID <<" not found in graph", portID.empty() || node->findPort(portID,upStream) ); // portID if specified must be on node

    std::vector< Edge::sptr > result;
    result.reserve(4);

    for ( ConnectionContainer::const_iterator i=m_connections.begin() ; i !=  m_connections.end() ; ++i )
    {
        Edge::sptr edge = i->first;
        Node::sptr nodeFrom = i->second.first;
        Node::sptr nodeTo = i->second.second;

        bool isConnectedEdge = ( upStream ? ( nodeTo == node ) : ( nodeFrom == node ) );
        bool isCorrectNature =  nature.empty() || (  edge->getNature() == nature );
        bool isCorrectPort = portID.empty() ||
                  ( upStream ? ( edge->getToPortID()== portID ) : (  edge->getFromPortID()== portID ) );

        if ( isConnectedEdge && isCorrectNature && isCorrectPort)
        {
            result.push_back( edge );
        }
    }

    return result;
}
示例#2
0
std::vector< Edge::sptr > Graph::getEdges( const Node::csptr &node, bool upStream,
                                           const std::string &nature,
                                           const std::string &portID
                                           )
{
    SLM_ASSERT("Node " + node->getID()  + " not found in graph", m_nodes.find( Node::constCast(node) ) != m_nodes.end());
    SLM_ASSERT("Port " + portID  + " not found on node" + node->getID(),
               portID.empty() || node->findPort(portID, upStream));

    std::vector< Edge::sptr > result;
    result.reserve(4);

    ConnectionContainer::const_iterator end = m_connections.end();
    for ( ConnectionContainer::const_iterator i=m_connections.begin(); i != end; ++i )
    {
        const Edge::sptr &edge = i->first;
        const Node::sptr &nodeFrom = i->second.first;
        const Node::sptr &nodeTo = i->second.second;

        bool isConnectedEdge = ( upStream ? nodeTo : nodeFrom ) == node ;
        if( !isConnectedEdge)
        {
            continue;
        }

        bool isCorrectPort = portID.empty() || portID == ( upStream ? edge->getToPortID() : edge->getFromPortID() );
        if( !isCorrectPort)
        {
            continue;
        }

        bool isCorrectNature =  nature.empty() || edge->getNature() == nature;
        if( !isCorrectNature)
        {
            continue;
        }

        result.push_back( edge );
    }

    return result;
}