OpenWalnut  1.5.0dev
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 <memory>
26 #include <string>
27 #include <vector>
28 
29 #include "WItemSelection.h"
30 #include "WItemSelector.h"
31 #include "WLogger.h"
32 #include "exceptions/WNameNotUnique.h"
33 #include "exceptions/WOutOfBounds.h"
34 
36  WSharedSequenceContainer< std::vector< std::shared_ptr< WItemSelectionItem > > >()
37 {
38  // initialize members
39 }
40 
42 {
43  // cleanup
44 }
45 
47 {
50 
51  for( size_t i = 0; i < r->get().size(); ++i )
52  {
53  l.push_back( i );
54  }
55  return WItemSelector( shared_from_this(), l );
56 }
57 
59 {
62  return WItemSelector( shared_from_this(), l );
63 }
64 
66 {
69 
70  if( r->get().size() >= 1 )
71  {
72  l.push_back( 0 );
73  }
74  return WItemSelector( shared_from_this(), l );
75 }
76 
78 {
81 
82  if( r->get().size() >= 1 )
83  {
84  l.push_back( r->get().size() - 1 );
85  }
86  return WItemSelector( shared_from_this(), l );
87 }
88 
90 {
93 
94  if( r->get().size() <= item )
95  {
96  throw WOutOfBounds( std::string( "The specified item does not exist." ) );
97  }
98  l.push_back( item );
99  return WItemSelector( shared_from_this(), l );
100 }
101 
102 void WItemSelection::addItem( std::string name, std::string description, const char** icon )
103 {
104  push_back( std::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) ) );
105 }
106 
107 void WItemSelection::addItem( std::shared_ptr< WItemSelectionItem > item )
108 {
109  push_back( item );
110 }
111 
Class for keeping a single named item in a WItemSelection.
virtual WItemSelector getSelectorLast()
Creates an default selection (last item selected).
virtual WItemSelector getSelectorNone()
Creates an default selection (no items selected).
virtual WItemSelector getSelectorFirst()
Creates an default selection (first item selected).
friend class WItemSelector
for proper locking and unlocking
void addItem(std::string name, std::string description="", const char **icon=NULL)
Convenience method to add a new item.
virtual WItemSelector getSelector(size_t item)
Creates an default selection (a specified items selected).
WItemSelection()
Default constructor.
virtual ~WItemSelection()
Destructor.
virtual WItemSelector getSelectorAll()
Creates an default selection (all items selected).
This class represents a subset of a WItemSelection.
Definition: WItemSelector.h:53
std::vector< size_t > IndexList
The type used for storing index lists.
Definition: WItemSelector.h:59
Indicates invalid element access of a container.
Definition: WOutOfBounds.h:37
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:65
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
This class provides a common interface for thread-safe access to sequence containers (list,...
void push_back(const typename S::value_type &x)
Adds a new element at the end of the container.