OpenWalnut  1.4.0
WItemSelectionItem.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 WITEMSELECTIONITEM_H
26 #define WITEMSELECTIONITEM_H
27 
28 #include <string>
29 
30 #ifndef Q_MOC_RUN
31 #include <boost/shared_ptr.hpp>
32 #endif
33 
34 /**
35  * Class for keeping a single named item in a WItemSelection.
36  */
37 class WItemSelectionItem // NOLINT
38 {
39 public:
40  /**
41  * Abbreviation for a shared pointer.
42  */
43  typedef boost::shared_ptr< WItemSelectionItem > SPtr;
44 
45  /**
46  * Abbreviation for a const shared pointer.
47  */
48  typedef boost::shared_ptr< const WItemSelectionItem > ConstSPtr;
49 
50  /**
51  * Constructs a new item with the specified values.
52  *
53  * \param name Name of item.
54  * \param description Description, can be empty.
55  * \param icon Icon, can be NULL.
56  */
57  WItemSelectionItem( std::string name, std::string description = "", const char** icon = NULL );
58 
59  /**
60  * Destruction. Does NOT delete the icon!
61  */
62  virtual ~WItemSelectionItem();
63 
64  /**
65  * Returns the name of the item.
66  *
67  * \return the name
68  */
69  std::string getName() const;
70 
71  /**
72  * The description of the item.
73  *
74  * \return the description
75  */
76  std::string getDescription() const;
77 
78  /**
79  * The icon associated with this item. Can be NULL.
80  *
81  * \return the icon, might be NULL.
82  */
83  const char** getIcon() const;
84 
85  /**
86  * Dynamic cast of the object, if a derivative of WItemSelectionItem was add to WItemSelection.
87  *
88  * \return Returns the converted item of new type T or 0 if a conversion is not possible.
89  */
90  template< typename T >
91  T* getAs()
92  {
93  return dynamic_cast< T* >( this );
94  }
95 
96  /**
97  * Dynamic cast of the object, if a derivative of WItemSelectionItem was add to WItemSelection.
98  *
99  * \return Returns the converted item of new type T or 0 if a conversion is not possible.
100  */
101  template< typename T >
102  const T* getAs() const
103  {
104  return dynamic_cast< T* >( this );
105  }
106 
107  /**
108  * Compares this and another item using their names only.
109  *
110  * \param other the second to compare the this one with
111  *
112  * \return true if the names are equal.
113  */
114  bool operator==( const WItemSelectionItem& other ) const;
115 
116 protected:
117  /**
118  * Item name.
119  */
120  std::string m_name;
121 
122  /**
123  * Item description.
124  */
125  std::string m_description;
126 
127  /**
128  * Item icon.
129  */
130  const char** m_icon;
131 
132 private:
133 };
134 
135 #endif // WITEMSELECTIONITEM_H
std::string getName() const
Returns the name of the item.
std::string m_name
Item name.
boost::shared_ptr< const WItemSelectionItem > ConstSPtr
Abbreviation for a const shared pointer.
std::string m_description
Item description.
const char ** m_icon
Item icon.
T * getAs()
Dynamic cast of the object, if a derivative of WItemSelectionItem was add to WItemSelection.
WItemSelectionItem(std::string name, std::string description="", const char **icon=NULL)
Constructs a new item with the specified values.
virtual ~WItemSelectionItem()
Destruction.
std::string getDescription() const
The description of the item.
const T * getAs() const
Dynamic cast of the object, if a derivative of WItemSelectionItem was add to WItemSelection.
Class for keeping a single named item in a WItemSelection.
boost::shared_ptr< WItemSelectionItem > SPtr
Abbreviation for a shared pointer.
const char ** getIcon() const
The icon associated with this item.
bool operator==(const WItemSelectionItem &other) const
Compares this and another item using their names only.