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 WITEMSELECTIONITEM_H 00026 #define WITEMSELECTIONITEM_H 00027 00028 #include <string> 00029 00030 #include <boost/shared_ptr.hpp> 00031 00032 /** 00033 * Class for keeping a single named item in a WItemSelection. 00034 */ 00035 class WItemSelectionItem // NOLINT 00036 { 00037 public: 00038 /** 00039 * Abbreviation for a shared pointer. 00040 */ 00041 typedef boost::shared_ptr< WItemSelectionItem > SPtr; 00042 00043 /** 00044 * Abbreviation for a const shared pointer. 00045 */ 00046 typedef boost::shared_ptr< const WItemSelectionItem > ConstSPtr; 00047 00048 /** 00049 * Constructs a new item with the specified values. 00050 * 00051 * \param name Name of item. 00052 * \param description Description, can be empty. 00053 * \param icon Icon, can be NULL. 00054 */ 00055 WItemSelectionItem( std::string name, std::string description = "", const char** icon = NULL ); 00056 00057 /** 00058 * Destruction. Does NOT delete the icon! 00059 */ 00060 virtual ~WItemSelectionItem(); 00061 00062 /** 00063 * Returns the name of the item. 00064 * 00065 * \return the name 00066 */ 00067 std::string getName() const; 00068 00069 /** 00070 * The description of the item. 00071 * 00072 * \return the description 00073 */ 00074 std::string getDescription() const; 00075 00076 /** 00077 * The icon associated with this item. Can be NULL. 00078 * 00079 * \return the icon, might be NULL. 00080 */ 00081 const char** getIcon() const; 00082 00083 /** 00084 * Dynamic cast of the object, if a derivative of WItemSelectionItem was add to WItemSelection. 00085 * 00086 * \return Returns the converted item of new type T or 0 if a conversion is not possible. 00087 */ 00088 template< typename T > 00089 T* getAs() 00090 { 00091 return dynamic_cast< T* >( this ); 00092 } 00093 00094 /** 00095 * Dynamic cast of the object, if a derivative of WItemSelectionItem was add to WItemSelection. 00096 * 00097 * \return Returns the converted item of new type T or 0 if a conversion is not possible. 00098 */ 00099 template< typename T > 00100 const T* getAs() const 00101 { 00102 return dynamic_cast< T* >( this ); 00103 } 00104 00105 /** 00106 * Compares this and another item using their names only. 00107 * 00108 * \param other the second to compare the this one with 00109 * 00110 * \return true if the names are equal. 00111 */ 00112 bool operator==( const WItemSelectionItem& other ) const; 00113 00114 protected: 00115 /** 00116 * Item name. 00117 */ 00118 std::string m_name; 00119 00120 /** 00121 * Item description. 00122 */ 00123 std::string m_description; 00124 00125 /** 00126 * Item icon. 00127 */ 00128 const char** m_icon; 00129 00130 private: 00131 }; 00132 00133 #endif // WITEMSELECTIONITEM_H