OpenWalnut  1.4.0
WItemSelection.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <string>
26 #include <vector>
27 
28 #include "WLogger.h"
29 
30 #include "exceptions/WOutOfBounds.h"
31 #include "exceptions/WNameNotUnique.h"
32 #include "WItemSelector.h"
33 
34 #include "WItemSelection.h"
35 
37  WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >()
38 {
39  // initialize members
40 }
41 
43 {
44  // cleanup
45 }
46 
48 {
51 
52  for( size_t i = 0; i < r->get().size(); ++i )
53  {
54  l.push_back( i );
55  }
56  return WItemSelector( shared_from_this(), l );
57 }
58 
60 {
63  return WItemSelector( shared_from_this(), l );
64 }
65 
67 {
70 
71  if( r->get().size() >= 1 )
72  {
73  l.push_back( 0 );
74  }
75  return WItemSelector( shared_from_this(), l );
76 }
77 
79 {
82 
83  if( r->get().size() >= 1 )
84  {
85  l.push_back( r->get().size() - 1 );
86  }
87  return WItemSelector( shared_from_this(), l );
88 }
89 
91 {
94 
95  if( r->get().size() <= item )
96  {
97  throw WOutOfBounds( std::string( "The specified item does not exist." ) );
98  }
99  l.push_back( item );
100  return WItemSelector( shared_from_this(), l );
101 }
102 
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 void WItemSelection::addItem( boost::shared_ptr< WItemSelectionItem > item )
109 {
110  push_back( item );
111 }
112 
void addItem(std::string name, std::string description="", const char **icon=NULL)
Convenience method to add a new item.
void push_back(const typename std::vector< boost::shared_ptr< WItemSelectionItem > >::value_type &x)
Adds a new element at the end of the container.
This class provides a common interface for thread-safe access to sequence containers (list...
virtual WItemSelector getSelectorAll()
Creates an default selection (all items selected).
std::vector< size_t > IndexList
The type used for storing index lists.
Definition: WItemSelector.h:59
virtual WItemSelector getSelectorNone()
Creates an default selection (no items selected).
Indicates invalid element access of a container.
Definition: WOutOfBounds.h:36
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
virtual WItemSelector getSelector(size_t item)
Creates an default selection (a specified items selected).
virtual ~WItemSelection()
Destructor.
virtual WItemSelector getSelectorLast()
Creates an default selection (last item selected).
This class represents a subset of a WItemSelection.
Definition: WItemSelector.h:52
virtual WItemSelector getSelectorFirst()
Creates an default selection (first item selected).
Class for keeping a single named item in a WItemSelection.
boost::shared_ptr< WSharedObjectTicketRead< std::vector< boost::shared_ptr< WItemSelectionItem > > > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:62
WItemSelection()
Default constructor.