MIRA
DefaultInitializer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_DEFAULTINITIALIZER_H_
48 #define _MIRA_DEFAULTINITIALIZER_H_
49 
52 
53 namespace mira {
54 
56 
62 #define MIRA_INITIALIZE_THIS mira::DefaultInitializer::initialize(*this)
63 
65 
93 class DefaultInitializer : public AbstractReflector<DefaultInitializer>
94 {
95 public:
96 
101  template <typename T>
102  static void initialize(T& object)
103  {
105  r.invoke(object);
106  }
107 
108 public:
109 
110  template<typename T, typename U>
111  void member(const char* name, T& member, const char* comment,
112  const U& defaultValue,
114  initializeMember(member,defaultValue);
115  }
116 
117  template<typename T, typename U>
118  void member(const char* name, const T& member, Setter<T> setter,
119  const char* comment, const U& defaultValue,
121  initializeMember(setter,defaultValue);
122  }
123 
124  template<typename T, typename U>
125  void member(const char* name, Getter<T> getter, Setter<T> setter,
126  const char* comment, const U& defaultValue,
128  initializeMember(setter,defaultValue);
129  }
130 
131  template<typename T, typename U>
132  void property(const char* name, T& member, const char* comment,
133  const U& defaultValue, PropertyHint&& hint = PropertyHint(),
135  initializeMember(member,defaultValue);
136  }
137 
138  template<typename T, typename U>
139  void property(const char* name, const T& member, Setter<T> setter,
140  const char* comment, const U& defaultValue,
141  PropertyHint&& hint = PropertyHint(),
143  initializeMember(setter,defaultValue);
144  }
145 
146  template<typename T, typename U>
147  void property(const char* name, Getter<T> getter, Setter<T> setter,
148  const char* comment, const U& defaultValue,
149  PropertyHint&& hint = PropertyHint(),
151  initializeMember(setter,defaultValue);
152  }
153 
154 public:
155 
156  // the methods without default values, that should be inherited from ReflectorInterfaces
157  // (however, they are not inherited, since we have template methods of the same
158  // name defined above)
159  template<typename T>
160  void member(const char* name, T& member, const char* comment,
162  template<typename T>
163  void member(const char* name, const std::string& id, T& member,
164  const char* comment, ReflectCtrlFlags flags = REFLECT_CTRLFLAG_NONE) {}
165  template<typename T>
166  void member(const char* name, const T& member, Setter<T> setter,
167  const char* comment, ReflectCtrlFlags flags = REFLECT_CTRLFLAG_NONE) {}
168  template<typename T>
169  void member(const char* name, Getter<T> getter, Setter<T> setter,
170  const char* comment, ReflectCtrlFlags flags = REFLECT_CTRLFLAG_NONE) {}
171  template<typename T>
172  void property(const char* name, T& member, const char* comment,
173  PropertyHint&& hint = PropertyHint(),
175  template<typename T>
176  void property(const char* name, const std::string& id, T& member,
177  const char* comment, PropertyHint&& hint = PropertyHint(),
179  template<typename T>
180  void property(const char* name, const T& member, Setter<T> setter,
181  const char* comment, PropertyHint&& hint = PropertyHint(),
183  template<typename T>
184  void property(const char* name, Getter<T> getter, Setter<T> setter,
185  const char* comment, PropertyHint&& hint = PropertyHint(),
187 
188 private:
189 
190 
191  template<typename T, typename U>
192  void initializeMember(T& member, const U& defaultValue) {
193  // #############################################################
194  // If you get a compiler error here, your default value does not
195  // match to your member type and cannot be casted. Make sure
196  // that the data type of your default value can be casted to
197  // the data type of your member!
198  // #############################################################
199  member=defaultValue;
200  }
201 
202  // Specialization for serialization::IgnoreMissing
203  template<typename T>
204  void initializeMember(T& member, const serialization::IgnoreMissing&) {}
205 
206 };
207 
209 
210 } // namespace
211 
212 #endif
void property(const char *name, const std::string &id, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:176
void property(const char *name, const T &member, Setter< T > setter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:180
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Abstract base class for most Reflectors.
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:160
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:169
Setter< T > setter(void(*f)(const T &))
Creates a Setter for global or static class methods taking the argument by const reference.
Definition: GetterSetter.h:443
Holds a boost::function object to a special setter function that must meet the signature "void method...
Definition: GetterSetter.h:395
Marker for indicating parameters that should be ignored if they are missing in the config file...
void member(const char *name, const T &member, Setter< T > setter, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:166
A property hint gives optional instructions to the property editor, i.e.
Definition: PropertyHint.h:82
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:125
Abstract base class for most Reflectors.
Definition: AbstractReflector.h:160
Reflector that visits the reflect method of objects in order to initialize them using the specified d...
Definition: DefaultInitializer.h:93
void property(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:147
No flags.
Definition: ReflectControlFlags.h:65
Getter< T > getter(T(*f)())
Creates a Getter for global or static class methods returning the result by value.
Definition: GetterSetter.h:136
static void initialize(T &object)
Invokes the reflector and initializes the members of &#39;object&#39; with the specified default values...
Definition: DefaultInitializer.h:102
void member(const char *name, const T &member, Setter< T > setter, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:118
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:172
Holds a boost::function object to a special getter function that must meet the signature "T method()"...
Definition: GetterSetter.h:87
void property(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:184
void member(const char *name, const std::string &id, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:163
void property(const char *name, T &member, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:132
ReflectCtrlFlags
Control Flags that can modify the behavior of certain reflectors.
Definition: ReflectControlFlags.h:63
void property(const char *name, const T &member, Setter< T > setter, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:139
void member(const char *name, T &member, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: DefaultInitializer.h:111
void invoke(T &object)
Invokes this reflector on the specified object.
Definition: AbstractReflector.h:259