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