pns_itemset.cpp 2.05 KB
Newer Older
1 2 3
/*
 * KiRouter - a push-and-(sometimes-)shove PCB router
 *
4
 * Copyright (C) 2013-2014 CERN
5
 * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6
 *
7 8 9 10
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
11
 *
12 13 14 15
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
19 20 21 22 23 24
 */

#include <boost/foreach.hpp>

#include "pns_itemset.h"

25
PNS_ITEMSET::PNS_ITEMSET( PNS_ITEM* aInitialItem )
26
{
27 28
    if(aInitialItem)
        m_items.push_back(aInitialItem);
29 30
}

31

32 33
PNS_ITEMSET::~PNS_ITEMSET()
{
34
    Clear();
35 36
}

37

38 39
void PNS_ITEMSET::Clear()
{
40
    BOOST_FOREACH(PNS_ITEM* item, m_ownedItems)
41 42 43 44 45 46 47 48
    {
        delete item;
    }

    m_items.clear();
    m_ownedItems.clear();
}

49

50
PNS_ITEMSET& PNS_ITEMSET::FilterLayers( int aStart, int aEnd )
51
{
52
    ITEM_VECTOR newItems;
53 54 55 56 57 58 59
    PNS_LAYERSET l;

    if( aEnd < 0 )
        l = PNS_LAYERSET( aStart );
    else
        l = PNS_LAYERSET( aStart, aEnd );

60
    BOOST_FOREACH( PNS_ITEM* item, m_items )
61

62
    if( item->Layers().Overlaps( l ) )
63 64 65
        newItems.push_back( item );

    m_items = newItems;
66

67
    return *this;
68 69
}

70 71

PNS_ITEMSET& PNS_ITEMSET::FilterKinds( int aKindMask )
72
{
73
    ITEM_VECTOR newItems;
74

75 76 77 78 79
    BOOST_FOREACH( PNS_ITEM* item, m_items )
    {
        if( item->OfKind ( aKindMask ) )
            newItems.push_back( item );
    }
80 81

    m_items = newItems;
82

83
    return *this;
84 85
}

86 87

PNS_ITEMSET& PNS_ITEMSET::FilterNet( int aNet )
88
{
89
    ITEM_VECTOR newItems;
90

91 92 93 94 95
    BOOST_FOREACH( PNS_ITEM* item, m_items )
    {
        if( item->Net() == aNet )
            newItems.push_back( item );
    }
96 97

    m_items = newItems;
98

99
    return *this;
100
}