OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WITEMSELECTION_H 00026 #define WITEMSELECTION_H 00027 00028 #include <vector> 00029 #include <string> 00030 #include <utility> 00031 00032 #include <boost/tuple/tuple.hpp> 00033 #include <boost/shared_ptr.hpp> 00034 #include <boost/signals2/signal.hpp> 00035 #include <boost/enable_shared_from_this.hpp> 00036 00037 #include "WSharedSequenceContainer.h" 00038 #include "WItemSelectionItem.h" 00039 00040 class WItemSelector; 00041 00042 /** 00043 * 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 00044 * Selectors which are able to select some subset of the item set. This is especially useful in properties where item selection is needed. The 00045 * 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 00046 * not implement any function that might change the item list, use the provided ones. If the item list changes, existing selectors get invalid 00047 * automatically using the change condition of the inherited WSharedSequenceContainer. 00048 */ 00049 class WItemSelection: public boost::enable_shared_from_this< WItemSelection >, 00050 public WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > > 00051 { 00052 friend class WItemSelector; // for proper locking and unlocking 00053 public: 00054 /** 00055 * Convenience typedef for a boost::shared_ptr< WItemSelection > 00056 */ 00057 typedef boost::shared_ptr< WItemSelection > SPtr; 00058 00059 /** 00060 * Convenience typedef for a boost::shared_ptr< const WItemSelection > 00061 */ 00062 typedef boost::shared_ptr< const WItemSelection > ConstSPtr; 00063 00064 /** 00065 * Default constructor. 00066 */ 00067 WItemSelection(); 00068 00069 /** 00070 * Destructor. 00071 */ 00072 virtual ~WItemSelection(); 00073 00074 /** 00075 * Creates an default selection (all items selected). The selector gets invalid if another item is added. 00076 * 00077 * \return an selector. 00078 */ 00079 virtual WItemSelector getSelectorAll(); 00080 00081 /** 00082 * Creates an default selection (no items selected). The selector gets invalid if another item is added. 00083 * 00084 * \return an selector. 00085 */ 00086 virtual WItemSelector getSelectorNone(); 00087 00088 /** 00089 * Creates an default selection (first item selected). The selector gets invalid if another item is added. 00090 * 00091 * \return an selector. 00092 */ 00093 virtual WItemSelector getSelectorFirst(); 00094 00095 /** 00096 * Creates an default selection (last item selected). The selector gets invalid if another item is added. 00097 * 00098 * \return an selector. 00099 */ 00100 virtual WItemSelector getSelectorLast(); 00101 00102 /** 00103 * Creates an default selection (a specified items selected). The selector gets invalid if another item is added. 00104 * 00105 * \param item the item to select. 00106 * 00107 * \return an selector. 00108 */ 00109 virtual WItemSelector getSelector( size_t item ); 00110 00111 /** 00112 * Convenience method to create a new item. 00113 * 00114 * \param name name of the item 00115 * \param description the description, can be empty 00116 * \param icon the icon, can be NULL 00117 * 00118 * \return the Item. 00119 */ 00120 static boost::shared_ptr< WItemSelectionItem > Item( std::string name, std::string description = "", const char** icon = NULL ) 00121 { 00122 return boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) ); 00123 } 00124 00125 /** 00126 * Convenience method to add a new item. 00127 * 00128 * \param name name of the item 00129 * \param description the description, can be empty 00130 * \param icon the icon, can be NULL 00131 * 00132 */ 00133 void addItem( std::string name, std::string description = "", const char** icon = NULL ); 00134 00135 /** 00136 * Method to add a new item, which can be derived from WItemSelectionItem. 00137 * 00138 * \param item WItemSelectionItem or derivation which should be add. 00139 */ 00140 void addItem( boost::shared_ptr< WItemSelectionItem > item ); 00141 00142 private: 00143 }; 00144 00145 #endif // WITEMSELECTION_H 00146