OpenWalnut  1.4.0
WObjectNDIP.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 WOBJECTNDIP_H
26 #define WOBJECTNDIP_H
27 
28 #include <string>
29 
30 #ifndef Q_MOC_RUN
31 #include <boost/shared_ptr.hpp>
32 #endif
33 
34 #include "WProperties.h"
35 
36 /**
37  * This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP). Just derive from this class and you get
38  * the NDIP stuff for free. Managed for you.
39  *
40  * \note This is a useful base class for strategies in \ref WModule and with \ref WStrategyHelper.
41  */
42 template< typename T >
43 class WObjectNDIP: public T
44 {
45 public:
46  /**
47  * Shared ptr to an instance.
48  */
49  typedef boost::shared_ptr< WObjectNDIP > SPtr;
50 
51  /**
52  * Shared ptr to a const instance.
53  */
54  typedef boost::shared_ptr< const WObjectNDIP > ConstSPtr;
55 
56  /**
57  * Destructor. Implement if you have non trivial cleanup stuff.
58  */
59  virtual ~WObjectNDIP();
60 
61  /**
62  * The name of the object.
63  *
64  * \return the name
65  */
66  virtual std::string getName() const;
67 
68  /**
69  * The description of this object.
70  *
71  * \return description text.
72  */
73  virtual std::string getDescription() const;
74 
75  /**
76  * The icon of this object.
77  *
78  * \return the icon in XPM format. Can be NULL.
79  */
80  virtual const char** getIcon() const;
81 
82  /**
83  * Return the property group of this object.
84  *
85  * \note the method is non-const to allow returning the properties as non-const
86  *
87  * \return the properties.
88  */
90 
91 protected:
92  /**
93  * Construct a NDIP'ed object.
94  *
95  * \param name the name
96  * \param description the description
97  * \param icon an icon in XPM format. Can be NULL if no icon is required.
98  */
99  WObjectNDIP( std::string name, std::string description, const char** icon = NULL );
100 
101  WProperties::SPtr m_properties; //!< the properties of the object.
102 
103 private:
104  std::string m_name; //!< the name
105  std::string m_description; //!< the description
106  const char** m_icon; //!< the icon
107 };
108 
109 template< typename T >
110 WObjectNDIP< T >::WObjectNDIP( std::string name, std::string description, const char** icon ):
111  m_properties( new WProperties( name, description ) ),
112  m_name( name ),
113  m_description( description ),
114  m_icon( icon )
115 {
116  // init
117 }
118 
119 template< typename T >
121 {
122  // cleanup
123 }
124 
125 template< typename T >
126 std::string WObjectNDIP< T >::getName() const
127 {
128  return m_name;
129 }
130 
131 template< typename T >
133 {
134  return m_description;
135 }
136 
137 template< typename T >
138 const char** WObjectNDIP< T >::getIcon() const
139 {
140  return m_icon;
141 }
142 
143 template< typename T >
145 {
146  return m_properties;
147 }
148 
149 
150 #endif // WOBJECTNDIP_H
151 
virtual std::string getDescription() const
The description of this object.
Definition: WObjectNDIP.h:132
virtual WProperties::SPtr getProperties()
Return the property group of this object.
Definition: WObjectNDIP.h:144
std::string m_description
the description
Definition: WObjectNDIP.h:105
std::string m_name
the name
Definition: WObjectNDIP.h:104
virtual std::string getName() const
The name of the object.
Definition: WObjectNDIP.h:126
This is a base class for everything which has a Name,Description,Icon and Properties (=NDIP)...
Definition: WObjectNDIP.h:43
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
WObjectNDIP(std::string name, std::string description, const char **icon=NULL)
Construct a NDIP'ed object.
Definition: WObjectNDIP.h:110
boost::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
virtual ~WObjectNDIP()
Destructor.
Definition: WObjectNDIP.h:120
const char ** m_icon
the icon
Definition: WObjectNDIP.h:106
boost::shared_ptr< WObjectNDIP > SPtr
Shared ptr to an instance.
Definition: WObjectNDIP.h:49
WProperties::SPtr m_properties
the properties of the object.
Definition: WObjectNDIP.h:101
boost::shared_ptr< const WObjectNDIP > ConstSPtr
Shared ptr to a const instance.
Definition: WObjectNDIP.h:54
virtual const char ** getIcon() const
The icon of this object.
Definition: WObjectNDIP.h:138