WItemSelection.h 4.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WITEMSELECTION_H
#define WITEMSELECTION_H

#include <vector>
#include <string>
#include <utility>

32
#include <boost/tuple/tuple.hpp>
33
#include <boost/shared_ptr.hpp>
34
#include <boost/signals2/signal.hpp>
35 36
#include <boost/enable_shared_from_this.hpp>

37
#include "WSharedSequenceContainer.h"
38
#include "WItemSelectionItem.h"
39

40 41 42 43 44 45
class WItemSelector;

/**
 * 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
 * Selectors which are able to select some subset of the item set. This is especially useful in properties where item selection is needed. The
 * 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 50
class WItemSelection: public boost::enable_shared_from_this< WItemSelection >, public WSharedSequenceContainer<
                std::vector< boost::shared_ptr< WItemSelectionItem > > >
51
{
52
    friend class WItemSelector; // for proper locking and unlocking
53
public:
54 55 56 57 58 59 60 61 62 63
    /**
     * Convenience typedef for a boost::shared_ptr< WItemSelection >
     */
    typedef boost::shared_ptr< WItemSelection > SPtr;

    /**
     * Convenience typedef for a  boost::shared_ptr< const WItemSelection >
     */
    typedef boost::shared_ptr< const WItemSelection > ConstSPtr;

64 65 66 67 68 69 70 71 72 73 74
    /**
     * Default constructor.
     */
    WItemSelection();

    /**
     * Destructor.
     */
    virtual ~WItemSelection();

    /**
75
     * Creates an default selection (all items selected). The selector gets invalid if another item is added.
76 77 78 79 80 81
     *
     * \return an selector.
     */
    virtual WItemSelector getSelectorAll();

    /**
82
     * Creates an default selection (no items selected). The selector gets invalid if another item is added.
83 84 85 86 87 88
     *
     * \return an selector.
     */
    virtual WItemSelector getSelectorNone();

    /**
89
     * Creates an default selection (first item selected). The selector gets invalid if another item is added.
90 91 92 93 94
     *
     * \return an selector.
     */
    virtual WItemSelector getSelectorFirst();

95 96 97 98 99 100 101
    /**
     * Creates an default selection (last item selected). The selector gets invalid if another item is added.
     *
     * \return an selector.
     */
    virtual WItemSelector getSelectorLast();

102
    /**
103
     * Creates an default selection (a specified items selected). The selector gets invalid if another item is added.
104 105 106 107 108 109 110
     *
     * \param item the item to select.
     *
     * \return an selector.
     */
    virtual WItemSelector getSelector( size_t item );

111
    /**
112
     * Convenience method to create a new item.
113
     *
114 115 116
     * \param name name of the item
     * \param description the description, can be empty
     * \param icon the icon, can be NULL
117
     *
118
     * \return the Item.
119
     */
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 130 131
     * \param name name of the item
     * \param description the description, can be empty
     * \param icon the icon, can be NULL
132 133
     *
     */
134
    void addItem( std::string name, std::string description = "", const char** icon = NULL );
135

136 137
    /**
     * Method to add a new item, which can be derived from WItemSelectionItem.
138 139
     *
     * \param item WItemSelectionItem or derivation which should be add.
140 141 142
     */
    void addItem( boost::shared_ptr< WItemSelectionItem > item );

143 144 145 146
private:
};

#endif  // WITEMSELECTION_H