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 WOBJECTNDIP_H 00026 #define WOBJECTNDIP_H 00027 00028 #include <string> 00029 00030 #include <boost/shared_ptr.hpp> 00031 00032 #include "WProperties.h" 00033 00034 /** 00035 * This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP). Just derive from this class and you get 00036 * the NDIP stuff for free. Managed for you. 00037 * 00038 * \note This is a useful base class for strategies in \ref WModule and with \ref WStrategyHelper. 00039 */ 00040 template< typename T > 00041 class WObjectNDIP: public T 00042 { 00043 public: 00044 /** 00045 * Shared ptr to an instance. 00046 */ 00047 typedef boost::shared_ptr< WObjectNDIP > SPtr; 00048 00049 /** 00050 * Shared ptr to a const instance. 00051 */ 00052 typedef boost::shared_ptr< const WObjectNDIP > ConstSPtr; 00053 00054 /** 00055 * Destructor. Implement if you have non trivial cleanup stuff. 00056 */ 00057 virtual ~WObjectNDIP(); 00058 00059 /** 00060 * The name of the object. 00061 * 00062 * \return the name 00063 */ 00064 virtual std::string getName() const; 00065 00066 /** 00067 * The description of this object. 00068 * 00069 * \return description text. 00070 */ 00071 virtual std::string getDescription() const; 00072 00073 /** 00074 * The icon of this object. 00075 * 00076 * \return the icon in XPM format. Can be NULL. 00077 */ 00078 virtual const char** getIcon() const; 00079 00080 /** 00081 * Return the property group of this object. 00082 * 00083 * \note the method is non-const to allow returning the properties as non-const 00084 * 00085 * \return the properties. 00086 */ 00087 virtual WProperties::SPtr getProperties(); 00088 00089 protected: 00090 /** 00091 * Construct a NDIP'ed object. 00092 * 00093 * \param name the name 00094 * \param description the description 00095 * \param icon an icon in XPM format. Can be NULL if no icon is required. 00096 */ 00097 WObjectNDIP( std::string name, std::string description, const char** icon = NULL ); 00098 00099 WProperties::SPtr m_properties; //!< the properties of the object. 00100 00101 private: 00102 std::string m_name; //!< the name 00103 std::string m_description; //!< the description 00104 const char** m_icon; //!< the icon 00105 }; 00106 00107 template< typename T > 00108 WObjectNDIP< T >::WObjectNDIP( std::string name, std::string description, const char** icon ): 00109 m_properties( new WProperties( name, description ) ), 00110 m_name( name ), 00111 m_description( description ), 00112 m_icon( icon ) 00113 { 00114 // init 00115 } 00116 00117 template< typename T > 00118 WObjectNDIP< T >::~WObjectNDIP() 00119 { 00120 // cleanup 00121 } 00122 00123 template< typename T > 00124 std::string WObjectNDIP< T >::getName() const 00125 { 00126 return m_name; 00127 } 00128 00129 template< typename T > 00130 std::string WObjectNDIP< T >::getDescription() const 00131 { 00132 return m_description; 00133 } 00134 00135 template< typename T > 00136 const char** WObjectNDIP< T >::getIcon() const 00137 { 00138 return m_icon; 00139 } 00140 00141 template< typename T > 00142 WProperties::SPtr WObjectNDIP< T >::getProperties() 00143 { 00144 return m_properties; 00145 } 00146 00147 00148 #endif // WOBJECTNDIP_H 00149