@@ -56,35 +56,24 @@ INCLUDES
56
56
FORWARD DECLARATIONS
57
57
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58
58
59
- template <typename T> T getValue (const SGPropertyNode* node)
60
- {
61
- static_assert (std::is_enum_v<T>, " PropertyTraits specialization for enum types only" );
62
- return static_cast <T>(node->getIntValue ());
63
- }
64
-
65
59
template <class C , class T >
66
60
class SGRawValueMethodsEnum : public SGRawValue <int >
67
61
{
68
62
public:
69
63
typedef T (C::* getter_t )() const ;
70
64
typedef void (C::* setter_t )(T);
71
65
SGRawValueMethodsEnum (C& obj,
72
- getter_t getter = 0 , setter_t setter = 0 )
73
- : _obj(obj), _getter(getter), _setter(setter) {
74
- }
75
- virtual ~SGRawValueMethodsEnum () {}
76
- virtual int getValue () const {
77
- if (_getter) { return (int )(_obj.*_getter)(); }
66
+ getter_t getter = nullptr , setter_t setter = nullptr )
67
+ : _obj(obj), _getter(getter), _setter(setter) {}
68
+ int getValue () const override {
69
+ if (_getter) { return static_cast <int >((_obj.*_getter)()); }
78
70
else { return SGRawValue<int >::DefaultValue (); }
79
71
}
80
- virtual bool setValue (int value) {
81
- return this ->setValue ((T)value);
82
- }
83
- bool setValue (T value) {
84
- if (_setter) { (_obj.*_setter)(value); return true ; }
72
+ bool setValue (int value) override {
73
+ if (_setter) { (_obj.*_setter)(static_cast <T>(value)); return true ; }
85
74
else return false ;
86
75
}
87
- virtual SGRaw* clone () const {
76
+ SGRaw* clone () const override {
88
77
return new SGRawValueMethodsEnum (_obj, _getter, _setter);
89
78
}
90
79
private:
@@ -100,19 +89,17 @@ class SGRawValueMethodsIndexedEnum : public SGRawValue<T>
100
89
typedef T (C::* getter_t )(U) const ;
101
90
typedef void (C::* setter_t )(U, T);
102
91
SGRawValueMethodsIndexedEnum (C& obj, U index,
103
- getter_t getter = 0 , setter_t setter = 0 )
104
- : _obj(obj), _index(index), _getter(getter), _setter(setter) {
105
- }
106
- virtual ~SGRawValueMethodsIndexedEnum () {}
107
- virtual T getValue () const {
92
+ getter_t getter = nullptr , setter_t setter = nullptr )
93
+ : _obj(obj), _index(index), _getter(getter), _setter(setter) {}
94
+ T getValue () const override {
108
95
if (_getter) { return (_obj.*_getter)(_index); }
109
96
else { return SGRawValue<T>::DefaultValue (); }
110
97
}
111
- virtual bool setValue (T value) {
98
+ bool setValue (T value) override {
112
99
if (_setter) { (_obj.*_setter)(_index, value); return true ; }
113
100
else return false ;
114
101
}
115
- virtual SGRaw* clone () const {
102
+ SGRaw* clone () const override {
116
103
return new SGRawValueMethodsIndexedEnum (_obj, _index, _getter, _setter);
117
104
}
118
105
private:
@@ -249,77 +236,6 @@ class JSBSIM_API FGPropertyManager
249
236
}
250
237
}
251
238
252
- /* *
253
- * Tie a property to a pair of simple functions.
254
- *
255
- * Every time the property value is queried, the getter (if any) will
256
- * be invoked; every time the property value is modified, the setter
257
- * (if any) will be invoked. The getter can be 0 to make the property
258
- * unreadable, and the setter can be 0 to make the property
259
- * unmodifiable.
260
- *
261
- * @param name The property name to tie (full path).
262
- * @param getter The getter function, or 0 if the value is unreadable.
263
- * @param setter The setter function, or 0 if the value is unmodifiable.
264
- */
265
-
266
- template <typename T> void
267
- Tie (const std::string &name, T (*getter)(), void (*setter)(T) = nullptr )
268
- {
269
- SGPropertyNode* property = root->getNode (name.c_str (), true );
270
- if (!property) {
271
- std::cerr << " Could not get or create property " << name << std::endl;
272
- return ;
273
- }
274
-
275
- if (!property->tie (SGRawValueFunctions<T>(getter, setter), false ))
276
- std::cerr << " Failed to tie property " << name << " to functions"
277
- << std::endl;
278
- else {
279
- tied_properties.push_back (PropertyState (property, nullptr ));
280
- if (!setter) property->setAttribute (SGPropertyNode::WRITE, false );
281
- if (!getter) property->setAttribute (SGPropertyNode::READ, false );
282
- if (FGJSBBase::debug_lvl & 0x20 ) std::cout << name << std::endl;
283
- }
284
- }
285
-
286
- /* *
287
- * Tie a property to a pair of indexed functions.
288
- *
289
- * Every time the property value is queried, the getter (if any) will
290
- * be invoked with the index provided; every time the property value
291
- * is modified, the setter (if any) will be invoked with the index
292
- * provided. The getter can be 0 to make the property unreadable, and
293
- * the setter can be 0 to make the property unmodifiable.
294
- *
295
- * @param name The property name to tie (full path).
296
- * @param index The integer argument to pass to the getter and
297
- * setter functions.
298
- * @param getter The getter function, or 0 if the value is unreadable.
299
- * @param setter The setter function, or 0 if the value is unmodifiable.
300
- */
301
- template <typename T> void
302
- Tie (const std::string &name, int index, T (*getter)(int ),
303
- void (*setter)(int , T) = nullptr )
304
- {
305
- SGPropertyNode* property = root->getNode (name.c_str (), true );
306
- if (!property) {
307
- std::cerr << " Could not get or create property " << name << std::endl;
308
- return ;
309
- }
310
-
311
- if (!property->tie (SGRawValueFunctionsIndexed<T>(index, getter, setter),
312
- false ))
313
- std::cerr << " Failed to tie property " << name << " to indexed functions"
314
- << std::endl;
315
- else {
316
- tied_properties.push_back (PropertyState (property, nullptr ));
317
- if (!setter) property->setAttribute (SGPropertyNode::WRITE, false );
318
- if (!getter) property->setAttribute (SGPropertyNode::READ, false );
319
- if (FGJSBBase::debug_lvl & 0x20 ) std::cout << name << std::endl;
320
- }
321
- }
322
-
323
239
/* *
324
240
* Tie a property to a pair of object methods.
325
241
*
@@ -337,7 +253,7 @@ class JSBSIM_API FGPropertyManager
337
253
* unmodifiable.
338
254
*/
339
255
template <class T , class V >
340
- typename std::enable_if <std::is_enum_v<V>, void >::type
256
+ typename std::enable_if_t <std::is_enum_v<V>, void >
341
257
Tie (const std::string &name, T * obj, V (T::*getter)() const ,
342
258
void (T::*setter)(V) = nullptr )
343
259
{
@@ -357,8 +273,9 @@ class JSBSIM_API FGPropertyManager
357
273
if (FGJSBBase::debug_lvl & 0x20 ) std::cout << name << std::endl;
358
274
}
359
275
}
276
+
360
277
template <class T , class V >
361
- typename std::enable_if <!std::is_enum_v<V>, void >::type
278
+ typename std::enable_if_t <!std::is_enum_v<V>, void >
362
279
Tie (const std::string &name, T * obj, V (T::*getter)() const ,
363
280
void (T::*setter)(V) = nullptr )
364
281
{
@@ -433,11 +350,11 @@ class JSBSIM_API FGPropertyManager
433
350
* @param getter The getter method, or 0 if the value is unreadable.
434
351
* @param setter The setter method, or 0 if the value is unmodifiable.
435
352
*/
436
- template <class T , class V , class U > void
437
- Tie (const std::string& name, T* obj, U index, V(T::* getter)(U) const ,
353
+ template <class T , class V , class U >
354
+ typename std::enable_if_t <std::is_enum_v<U>, void >
355
+ Tie (const std::string& name, T* obj, U index, V(T::* getter)(U) const ,
438
356
void (T::* setter)(U, V) = nullptr )
439
357
{
440
- static_assert (std::is_enum_v<U>, " Specialization for enum types only" );
441
358
SGPropertyNode* property = root->getNode (name.c_str (), true );
442
359
if (!property) {
443
360
std::cerr << " Could not get or create property " << name << std::endl;
0 commit comments