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