From ccf15ac97e1182f0e374ceb41c92ba6d646adb55 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Mon, 13 Feb 2012 00:06:51 +0100 Subject: [PATCH] Remove unneeded function and add bool relative changes --- docs-mini/README.protocol | 3 +++ src/Network/generic.cxx | 37 ++++++++++++++----------------------- src/Network/generic.hxx | 8 ++------ 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/docs-mini/README.protocol b/docs-mini/README.protocol index 080c42bda..e106f5f80 100644 --- a/docs-mini/README.protocol +++ b/docs-mini/README.protocol @@ -148,6 +148,9 @@ For input chunks there exist some more options: (Usefull for eg. heading selector to start again with 1 for values higher than 360) +, , and are only used for numeric data types. 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 , like in: Data Section diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index 2f96180c9..930a07084 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -273,7 +273,6 @@ bool FGGeneric::gen_message() { bool FGGeneric::parse_message_binary(int length) { char *p2, *p1 = buf; int32_t tmp32; - double val; int i = -1; p2 = p1 + length; @@ -291,7 +290,7 @@ bool FGGeneric::parse_message_binary(int length) { break; case FG_BOOL: - _in_message[i].prop->setBoolValue( p1[0] != 0 ); + updateValue(_in_message[i], p1[0] != 0); p1 += 1; break; @@ -338,7 +337,6 @@ bool FGGeneric::parse_message_binary(int length) { 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(); @@ -365,7 +363,7 @@ bool FGGeneric::parse_message_ascii(int length) { 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: @@ -712,23 +710,16 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg) } } -/* - 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(prot.prop)); + } + else + { + setValue(prot.prop, val); + } } - -DEF_DATA_ACCESS(int, Int) -DEF_DATA_ACCESS(float, Float) -DEF_DATA_ACCESS(double, Double) - diff --git a/src/Network/generic.hxx b/src/Network/generic.hxx index eb732830b..0b27248f5 100644 --- a/src/Network/generic.hxx +++ b/src/Network/generic.hxx @@ -129,13 +129,9 @@ private: setValue(prot.prop, new_val); } - - template - static const T getValue(SGPropertyNode_ptr& prop); - - template - 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); };