OpenWalnut  1.3.1
WItemSelection.h
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 #ifndef WITEMSELECTION_H
26 #define WITEMSELECTION_H
27 
28 #include <vector>
29 #include <string>
30 #include <utility>
31 
32 #include <boost/tuple/tuple.hpp>
33 #include <boost/shared_ptr.hpp>
34 #include <boost/signals2/signal.hpp>
35 #include <boost/enable_shared_from_this.hpp>
36 
37 #include "WSharedSequenceContainer.h"
38 #include "WItemSelectionItem.h"
39 
40 class WItemSelector;
41 
42 /**
43  * A class containing a list of named items. It is mainly a container for an std::vector but with the difference that there can be so called
44  * Selectors which are able to select some subset of the item set. This is especially useful in properties where item selection is needed. The
45  * class is kept very restrictive to keep the interface clean and sleek and to keep the item set consistent among several threads. So please do
46  * not implement any function that might change the item list, use the provided ones. If the item list changes, existing selectors get invalid
47  * automatically using the change condition of the inherited WSharedSequenceContainer.
48  */
49 class WItemSelection: public boost::enable_shared_from_this< WItemSelection >,
50  public WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >
51 {
52  friend class WItemSelector; // for proper locking and unlocking
53 public:
54  /**
55  * Convenience typedef for a boost::shared_ptr< WItemSelection >
56  */
57  typedef boost::shared_ptr< WItemSelection > SPtr;
58 
59  /**
60  * Convenience typedef for a boost::shared_ptr< const WItemSelection >
61  */
62  typedef boost::shared_ptr< const WItemSelection > ConstSPtr;
63 
64  /**
65  * Default constructor.
66  */
68 
69  /**
70  * Destructor.
71  */
72  virtual ~WItemSelection();
73 
74  /**
75  * Creates an default selection (all items selected). The selector gets invalid if another item is added.
76  *
77  * \return an selector.
78  */
79  virtual WItemSelector getSelectorAll();
80 
81  /**
82  * Creates an default selection (no items selected). The selector gets invalid if another item is added.
83  *
84  * \return an selector.
85  */
87 
88  /**
89  * Creates an default selection (first item selected). The selector gets invalid if another item is added.
90  *
91  * \return an selector.
92  */
94 
95  /**
96  * Creates an default selection (last item selected). The selector gets invalid if another item is added.
97  *
98  * \return an selector.
99  */
100  virtual WItemSelector getSelectorLast();
101 
102  /**
103  * Creates an default selection (a specified items selected). The selector gets invalid if another item is added.
104  *
105  * \param item the item to select.
106  *
107  * \return an selector.
108  */
109  virtual WItemSelector getSelector( size_t item );
110 
111  /**
112  * Convenience method to create a new item.
113  *
114  * \param name name of the item
115  * \param description the description, can be empty
116  * \param icon the icon, can be NULL
117  *
118  * \return the Item.
119  */
120  static boost::shared_ptr< WItemSelectionItem > Item( std::string name, std::string description = "", const char** icon = NULL )
121  {
122  return boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) );
123  }
124 
125  /**
126  * Convenience method to add a new item.
127  *
128  * \param name name of the item
129  * \param description the description, can be empty
130  * \param icon the icon, can be NULL
131  *
132  */
133  void addItem( std::string name, std::string description = "", const char** icon = NULL );
134 
135  /**
136  * Method to add a new item, which can be derived from WItemSelectionItem.
137  *
138  * \param item WItemSelectionItem or derivation which should be add.
139  */
140  void addItem( boost::shared_ptr< WItemSelectionItem > item );
141 
142 private:
143 };
144 
145 #endif // WITEMSELECTION_H
146