WItemSelection.cpp 2.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#include <string>
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
26
#include <vector>
27 28 29 30

#include "WLogger.h"

#include "exceptions/WOutOfBounds.h"
31
#include "exceptions/WNameNotUnique.h"
32 33 34 35
#include "WItemSelector.h"

#include "WItemSelection.h"

36 37
WItemSelection::WItemSelection() :
                WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >()
38 39 40 41 42 43 44 45 46 47 48 49
{
    // initialize members
}

WItemSelection::~WItemSelection()
{
    // cleanup
}

WItemSelector WItemSelection::getSelectorAll()
{
    WItemSelector::IndexList l;
50
    ReadTicket r = getReadTicket();
51

52
    for( size_t i = 0; i < r->get().size(); ++i )
53 54 55 56 57 58 59 60 61
    {
        l.push_back( i );
    }
    return WItemSelector( shared_from_this(), l );
}

WItemSelector WItemSelection::getSelectorNone()
{
    WItemSelector::IndexList l;
62
    ReadTicket r = getReadTicket();
63 64 65 66 67 68
    return WItemSelector( shared_from_this(), l );
}

WItemSelector WItemSelection::getSelectorFirst()
{
    WItemSelector::IndexList l;
69
    ReadTicket r = getReadTicket();
70

71
    if( r->get().size() >= 1 )
72 73 74 75 76 77
    {
        l.push_back( 0 );
    }
    return WItemSelector( shared_from_this(), l );
}

78 79 80 81 82
WItemSelector WItemSelection::getSelectorLast()
{
    WItemSelector::IndexList l;
    ReadTicket r = getReadTicket();

83
    if( r->get().size() >= 1 )
84 85 86 87 88 89
    {
        l.push_back( r->get().size() - 1 );
    }
    return WItemSelector( shared_from_this(), l );
}

90 91 92
WItemSelector WItemSelection::getSelector( size_t item )
{
    WItemSelector::IndexList l;
93
    ReadTicket r = getReadTicket();
94

95
    if( r->get().size() <= item )
96
    {
97
        throw WOutOfBounds( std::string( "The specified item does not exist." ) );
98 99 100 101 102
    }
    l.push_back( item );
    return WItemSelector( shared_from_this(), l );
}

103
void WItemSelection::addItem( std::string name, std::string description, const char** icon )
104
{
105
    push_back( boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) ) );
106 107
}

108 109
void WItemSelection::addItem( boost::shared_ptr< WItemSelectionItem > item )
{
110
    push_back( item );
111 112
}