OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 #include "WExportCommon.h"
40 
41 class WItemSelector;
42 
43 /**
44  * 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
45  * Selectors which are able to select some subset of the item set. This is especially useful in properties where item selection is needed. The
46  * 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
47  * not implement any function that might change the item list, use the provided ones. If the item list changes, existing selectors get invalid
48  * automatically using the change condition of the inherited WSharedSequenceContainer.
49  */
50 class OWCOMMON_EXPORT WItemSelection: public boost::enable_shared_from_this< WItemSelection >,
51  public WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >
52 {
53 friend class WItemSelector; // for proper locking and unlocking
54 public:
55  /**
56  * Convenience typedef for a boost::shared_ptr< WItemSelection >
57  */
58  typedef boost::shared_ptr< WItemSelection > SPtr;
59 
60  /**
61  * Convenience typedef for a boost::shared_ptr< const WItemSelection >
62  */
63  typedef boost::shared_ptr< const WItemSelection > ConstSPtr;
64 
65  /**
66  * Default constructor.
67  */
69 
70  /**
71  * Destructor.
72  */
73  virtual ~WItemSelection();
74 
75  /**
76  * Creates an default selection (all items selected). The selector gets invalid if another item is added.
77  *
78  * \return an selector.
79  */
80  virtual WItemSelector getSelectorAll();
81 
82  /**
83  * Creates an default selection (no items selected). The selector gets invalid if another item is added.
84  *
85  * \return an selector.
86  */
87  virtual WItemSelector getSelectorNone();
88 
89  /**
90  * Creates an default selection (first item selected). The selector gets invalid if another item is added.
91  *
92  * \return an selector.
93  */
94  virtual WItemSelector getSelectorFirst();
95 
96  /**
97  * Creates an default selection (last item selected). The selector gets invalid if another item is added.
98  *
99  * \return an selector.
100  */
101  virtual WItemSelector getSelectorLast();
102 
103  /**
104  * Creates an default selection (a specified items selected). The selector gets invalid if another item is added.
105  *
106  * \param item the item to select.
107  *
108  * \return an selector.
109  */
110  virtual WItemSelector getSelector( size_t item );
111 
112  /**
113  * Convenience method to create a new item.
114  *
115  * \param name name of the item
116  * \param description the description, can be empty
117  * \param icon the icon, can be NULL
118  *
119  * \return the Item.
120  */
121  static boost::shared_ptr< WItemSelectionItem > Item( std::string name, std::string description = "", const char** icon = NULL )
122  {
123  return boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) );
124  }
125 
126  /**
127  * Convenience method to add a new item.
128  *
129  * \param name name of the item
130  * \param description the description, can be empty
131  * \param icon the icon, can be NULL
132  *
133  */
134  void addItem( std::string name, std::string description = "", const char** icon = NULL );
135 
136 private:
137 };
138 
139 #endif // WITEMSELECTION_H
140