OpenWalnut 1.2.5
WItemSelection.h
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 #include "WExportCommon.h"
00040 
00041 class WItemSelector;
00042 
00043 /**
00044  * 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
00045  * Selectors which are able to select some subset of the item set. This is especially useful in properties where item selection is needed. The
00046  * 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
00047  * not implement any function that might change the item list, use the provided ones. If the item list changes, existing selectors get invalid
00048  * automatically using the change condition of the inherited WSharedSequenceContainer.
00049  */
00050 class OWCOMMON_EXPORT WItemSelection: public boost::enable_shared_from_this< WItemSelection >,
00051                                       public WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >
00052 {
00053 friend class WItemSelector; // for proper locking and unlocking
00054 public:
00055     /**
00056      * Convenience typedef for a boost::shared_ptr< WItemSelection >
00057      */
00058     typedef boost::shared_ptr< WItemSelection > SPtr;
00059 
00060     /**
00061      * Convenience typedef for a  boost::shared_ptr< const WItemSelection >
00062      */
00063     typedef boost::shared_ptr< const WItemSelection > ConstSPtr;
00064 
00065     /**
00066      * Default constructor.
00067      */
00068     WItemSelection();
00069 
00070     /**
00071      * Destructor.
00072      */
00073     virtual ~WItemSelection();
00074 
00075     /**
00076      * Creates an default selection (all items selected). The selector gets invalid if another item is added.
00077      *
00078      * \return an selector.
00079      */
00080     virtual WItemSelector getSelectorAll();
00081 
00082     /**
00083      * Creates an default selection (no items selected). The selector gets invalid if another item is added.
00084      *
00085      * \return an selector.
00086      */
00087     virtual WItemSelector getSelectorNone();
00088 
00089     /**
00090      * Creates an default selection (first item selected). The selector gets invalid if another item is added.
00091      *
00092      * \return an selector.
00093      */
00094     virtual WItemSelector getSelectorFirst();
00095 
00096     /**
00097      * Creates an default selection (last item selected). The selector gets invalid if another item is added.
00098      *
00099      * \return an selector.
00100      */
00101     virtual WItemSelector getSelectorLast();
00102 
00103     /**
00104      * Creates an default selection (a specified items selected). The selector gets invalid if another item is added.
00105      *
00106      * \param item the item to select.
00107      *
00108      * \return an selector.
00109      */
00110     virtual WItemSelector getSelector( size_t item );
00111 
00112     /**
00113      * Convenience method to create a new item.
00114      *
00115      * \param name name of the item
00116      * \param description the description, can be empty
00117      * \param icon the icon, can be NULL
00118      *
00119      * \return the Item.
00120      */
00121     static boost::shared_ptr< WItemSelectionItem > Item( std::string name, std::string description = "", const char** icon = NULL )
00122     {
00123         return boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) );
00124     }
00125 
00126     /**
00127      * Convenience method to add a new item.
00128      *
00129      * \param name name of the item
00130      * \param description the description, can be empty
00131      * \param icon the icon, can be NULL
00132      *
00133      */
00134     void addItem( std::string name, std::string description = "", const char** icon = NULL );
00135 
00136 private:
00137 };
00138 
00139 #endif  // WITEMSELECTION_H
00140 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends