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