You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.4 KiB
73 lines
2.4 KiB
#include <functional>
|
|
#include <ext/functional>
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <ept/debtags/tag.h>
|
|
#include <ept/debtags/vocabulary.h>
|
|
#include <adept/filtersidebar.h>
|
|
#include <adept/tagchooser.h>
|
|
|
|
using namespace adept;
|
|
using namespace aptFront;
|
|
using namespace std;
|
|
using namespace __gnu_cxx;
|
|
|
|
template< typename H, typename G1, typename G2 >
|
|
struct _compose2_binary {
|
|
_compose2_binary( H _h, G1 _g1, G2 _g2 )
|
|
: h( _h ), g1( _g1 ), g2( _g2 )
|
|
{}
|
|
|
|
typename H::result_type operator()(
|
|
typename G1::argument_type a,
|
|
typename G2::argument_type b )
|
|
{
|
|
return h( g1( a ), g2( b ) );
|
|
}
|
|
|
|
H h;
|
|
G1 g1;
|
|
G2 g2;
|
|
};
|
|
|
|
template< typename H, typename G1, typename G2 >
|
|
_compose2_binary< H, G1, G2 > compose2_binary( H h, G1 g1, G2 g2 ) {
|
|
return _compose2_binary< H, G1, G2 >( h, g1, g2 );
|
|
}
|
|
|
|
void FilterSidebar::setCardinality( const Lister::Cardinality &c )
|
|
{
|
|
using namespace wibble::operators;
|
|
ept::debtags::Tag::Set all, smart;
|
|
|
|
kdDebug() << "FilterSidebar::setCardinality" << endl;
|
|
Lister::Cardinality cprime;
|
|
remove_copy_if( c.begin(), c.end(), inserter( cprime, cprime.begin() ),
|
|
compose1( bind1st( equal_to< int >(), 0 ),
|
|
select2nd<
|
|
Lister::Cardinality::value_type >() ) );
|
|
transform( cprime.begin(), cprime.end(), inserter( all, all.begin() ),
|
|
select1st< Lister::Cardinality::value_type >() );
|
|
m_all->setTags( all );
|
|
ept::debtags::Vocabulary &t = cache::Global().get().tags();
|
|
m_easy->setTags( all & ( t.facetByName( "interface" ).tags()
|
|
| t.facetByName( "works-with" ).tags()
|
|
| t.facetByName( "use" ).tags()
|
|
| t.facetByName( "role" ).tags() ) );
|
|
|
|
typedef vector< pair< ept::debtags::Tag, int > > Vec;
|
|
Vec vec;
|
|
copy( cprime.begin(), cprime.end(), back_inserter( vec ) );
|
|
sort( vec.begin(), vec.end(),
|
|
compose2_binary( less< int >(),
|
|
select2nd< Vec::value_type >(),
|
|
select2nd< Vec::value_type >() ) );
|
|
Vec::reverse_iterator end = vec.rbegin();
|
|
advance( end, vec.size() < 10 ? vec.size() : 10 );
|
|
transform( vec.rbegin(), end, inserter( smart, smart.begin() ),
|
|
select1st< Vec::value_type >() );
|
|
|
|
m_smart->setTags( smart );
|
|
m_smart->openToplevel();
|
|
}
|