1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2013, 2014 Henrik Tidefelt
20 Shapes::Kernel::Node::ListRef
21 Shapes::Kernel::Node::prepend_edges( const T
& edges
, bool directed
, const ListRef
& rest
, const RefCountPtr
< const Lang::Graph
> & graph
, const Kernel::EdgePredicate
* filter
)
23 Kernel::Node::ListRef result
= rest
;
25 for( typename
T::const_iterator e
= edges
.begin( ); e
!= edges
.end( ); ++e
){
26 result
= Helpers::SingleList_cons( static_cast< Lang::Value
* >( new Lang::Edge( graph
, *e
, directed
) ), result
);
29 for( typename
T::const_iterator e
= edges
.begin( ); e
!= edges
.end( ); ++e
){
30 if( (*filter
)( **e
) ){
31 result
= Helpers::SingleList_cons( static_cast< Lang::Value
* >( new Lang::Edge( graph
, *e
, directed
) ), result
);
39 Shapes::Kernel::Node::ListRef
40 Shapes::Kernel::Node::prepend_edges_neighbor( Kernel::Node
* neighbor
, const T
& edges
, bool directed
, const ListRef
& rest
, const RefCountPtr
< const Lang::Graph
> & graph
, const Kernel::EdgePredicate
* filter
)
42 /* Out of all four arguments to the Kernel::Edge constructor, only one of the first two and the third will be used. */
43 Kernel::Edge
edgeLow( neighbor
, neighbor
, 0, true );
44 Kernel::Edge
edgeHigh( neighbor
, neighbor
, std::numeric_limits
< size_t >::max( ), true );
45 Kernel::Node::ListRef result
= rest
;
46 typename
T::const_iterator eBegin
= edges
.lower_bound( & edgeLow
);
47 typename
T::const_iterator eEnd
= edges
.upper_bound( & edgeHigh
);
49 for( typename
T::const_iterator e
= eBegin
; e
!= eEnd
; ++e
){
50 result
= Helpers::SingleList_cons( static_cast< Lang::Value
* >( new Lang::Edge( graph
, *e
, directed
) ), result
);
53 for( typename
T::const_iterator e
= eBegin
; e
!= eEnd
; ++e
){
54 if( (*filter
)( **e
) ){
55 result
= Helpers::SingleList_cons( static_cast< Lang::Value
* >( new Lang::Edge( graph
, *e
, directed
) ), result
);
64 Shapes::Kernel::EdgeLabelPredicate
< T
>::EdgeLabelPredicate( const RefCountPtr
< std::vector
< Kernel::ValueRef
> > & edgeLabels
, const T
& label
)
65 : edgeLabels_( edgeLabels
), label_( label
)
67 if( edgeLabels_
== NullPtr
< std::vector
< Kernel::ValueRef
> >( ) )
72 Shapes::Kernel::EdgeLabelPredicate
< T
>::~EdgeLabelPredicate( )
77 Shapes::Kernel::EdgeLabelPredicate
< T
>::operator () ( const Edge
& e
) const
81 const T
* ptr
= dynamic_cast< const T
* >( (*edgeLabels_
)[ e
.index( ) ].getPtr( ) );
84 return *ptr
== label_
;