Пример #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
bool Graph::addEdge(Edge::sptr edge, Node::csptr nodeSource, Node::csptr nodeDestination)
{
    // edge not already recorded
    if (m_connections.find( edge ) !=  m_connections.end() )
    {
        return false; // edge already stored
    }
    // node registred ?
    if (m_nodes.find( Node::constCast(nodeSource) ) ==  m_nodes.end() )
    {
        return false; // node already stored
    }
    // node registred ?
    if ( m_nodes.find( Node::constCast(nodeDestination) ) ==  m_nodes.end() )
    {
        return false; // node already stored
    }

    // test port existance
    Port::sptr sourcePort = nodeSource->findPort( edge->getIdentifiers().first, DOWN_STREAM );
    if ( !sourcePort )
    {
        return false; // port doesn't exist
    }

    // test port existance
    Port::sptr sourceDest= nodeDestination->findPort( edge->getIdentifiers().second , UP_STREAM );
    if ( !sourceDest )
    {
        return false; // port doesn't exist
    }


    // test port compatibility
    if ( sourcePort->getType() !=  sourceDest->getType() )
    {
        return false; // incompatible type
    }

    m_connections[ edge ] = std::make_pair(  Node::constCast(nodeSource), Node::constCast(nodeDestination) );

    return true;
}
Пример #3
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;
}