(Usefull for eg. heading selector to start again with 1 for
values higher than 360)
+<rel>, <min>, <max> and <wrap> are only used for numeric data types. <rel> can
+additionally be used with type 'bool', where it toggles the value, if the received
+value evaluates to 'true', otherwise the value is left unchanged.
Chunks can also consist of a single constant <format>, like in:
<format>Data Section</format>
bool FGGeneric::parse_message_binary(int length) {
char *p2, *p1 = buf;
int32_t tmp32;
- double val;
int i = -1;
p2 = p1 + length;
break;
case FG_BOOL:
- _in_message[i].prop->setBoolValue( p1[0] != 0 );
+ updateValue(_in_message[i], p1[0] != 0);
p1 += 1;
break;
bool FGGeneric::parse_message_ascii(int length) {
char *p2, *p1 = buf;
- double val;
int i = -1;
int chunks = _in_message.size();
int line_separator_size = line_separator.size();
break;
case FG_BOOL:
- _in_message[i].prop->setBoolValue( atof(p1) != 0.0 );
+ updateValue(_in_message[i], atof(p1) != 0.0);
break;
case FG_FIXED:
}
}
-/*
- set/getValue: Implementations for supported datatypes
-*/
-#define DEF_DATA_ACCESS(type, method)\
-template<>\
-const type FGGeneric::getValue(SGPropertyNode_ptr& prop)\
-{\
- return prop->get##method##Value();\
-}\
-\
-template<>\
-void FGGeneric::setValue(SGPropertyNode_ptr& prop, const type& val)\
-{\
- prop->set##method##Value(val);\
+void FGGeneric::updateValue(FGGeneric::_serial_prot& prot, bool val)
+{
+ if( prot.rel )
+ {
+ // value inverted if received true, otherwise leave unchanged
+ if( val )
+ setValue(prot.prop, !getValue<bool>(prot.prop));
+ }
+ else
+ {
+ setValue(prot.prop, val);
+ }
}
-
-DEF_DATA_ACCESS(int, Int)
-DEF_DATA_ACCESS(float, Float)
-DEF_DATA_ACCESS(double, Double)
-
setValue(prot.prop, new_val);
}
-
- template<class T>
- static const T getValue(SGPropertyNode_ptr& prop);
-
- template<class T>
- static void setValue(SGPropertyNode_ptr& prop, const T& val);
+ // Special handling for bool (relative change = toggle, no min/max, no wrap)
+ static void updateValue(_serial_prot& prot, bool val);
};