From 133cfbfa7f4ec62ddc97bd93d4a50fec81b52362 Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Wed, 2 Feb 2011 22:05:54 +0100 Subject: [PATCH 1/5] Fixed several compiler warnings uninitialized or unused variables, init sequence, ... --- src/AIModel/AIBase.cxx | 2 +- src/AIModel/AIWingman.cxx | 4 ++-- src/FDM/YASim/Gear.cpp | 6 ++++-- src/FDM/YASim/Rotorpart.cpp | 4 ++-- src/Instrumentation/dclgps.cxx | 2 +- src/Instrumentation/heading_indicator_dg.cxx | 1 - src/Instrumentation/rnav_waypt_controller.cxx | 3 +++ src/Time/sunsolver.cxx | 3 +-- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 1e3b775d4..33cb073cb 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -59,8 +59,8 @@ FGAIBase::FGAIBase(object_type ot) : props( NULL ), model_removed( fgGetNode("/ai/models/model-removed", true) ), manager( NULL ), - fp( NULL ), _installed(false), + fp( NULL ), _impact_lat(0), _impact_lon(0), _impact_elev(0), diff --git a/src/AIModel/AIWingman.cxx b/src/AIModel/AIWingman.cxx index cef9ad737..be053c447 100644 --- a/src/AIModel/AIWingman.cxx +++ b/src/AIModel/AIWingman.cxx @@ -375,7 +375,7 @@ void FGAIWingman::Break(double dt) { void FGAIWingman::Join(double dt) { double range, bearing, az2; - double parent_hdg, parent_spd, parent_ht= 0; + double parent_hdg, parent_spd = 0; double p_hdg, p_pch, p_rll = 0; setTgtOffsets(dt, 25); @@ -425,7 +425,7 @@ void FGAIWingman::Join(double dt) { double rel_brg = calcRelBearingDeg(bearing, hdg); double recip_brg = calcRecipBearingDeg(bearing); double angle = calcAngle(distance,_offsetpos, pos); - double approx_angle = atan2(daltM, range); + //double approx_angle = atan2(daltM, range); double frm_spd = 50; // formation speed double join_rnge = 1000.0; double recip_parent_hdg = calcRecipBearingDeg(parent_hdg); diff --git a/src/FDM/YASim/Gear.cpp b/src/FDM/YASim/Gear.cpp index 886a1a989..ce2517c73 100644 --- a/src/FDM/YASim/Gear.cpp +++ b/src/FDM/YASim/Gear.cpp @@ -332,8 +332,10 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot) float b = ground[3] - Math::dot3(tmp, ground)+BumpAltitude; // Calculate the point of ground _contact. - _frac = a/(a-b); - if(b < 0) _frac = 1; + if(b < 0) + _frac = 1; + else + _frac = a/(a-b); for(i=0; i<3; i++) _contact[i] = _pos[i] + _frac*_cmpr[i]; diff --git a/src/FDM/YASim/Rotorpart.cpp b/src/FDM/YASim/Rotorpart.cpp index 77520dee9..bd54f4122 100644 --- a/src/FDM/YASim/Rotorpart.cpp +++ b/src/FDM/YASim/Rotorpart.cpp @@ -99,7 +99,7 @@ void Rotorpart::inititeration(float dt,float *rot) float b; b=_rotor->getBalance(); float s =Math::sin(_phi+_direction); - float c =Math::cos(_phi+_direction); + //float c =Math::cos(_phi+_direction); if (s>0) _balance=(b>0)?(1.-s*(1.-b)):(1.-s)*(1.+b); else @@ -548,7 +548,7 @@ void Rotorpart::calcForce(float* v, float rho, float* out, float* torque, float dirblade[3]; Math::cross3(_normal,_directionofcentripetalforce,dirblade); - float vblade=Math::abs(Math::dot3(dirblade,v)); + //float vblade=Math::abs(Math::dot3(dirblade,v)); alpha=_alphaalt+(alpha-_alphaalt)*factor; _alpha=alpha; diff --git a/src/Instrumentation/dclgps.cxx b/src/Instrumentation/dclgps.cxx index 58e87dc20..ec78643aa 100644 --- a/src/Instrumentation/dclgps.cxx +++ b/src/Instrumentation/dclgps.cxx @@ -654,7 +654,7 @@ string DCLGPS::ExpandSIAPIdent(const string& ident) { Col 107-111 MSA center fix. We can ignore this. */ void DCLGPS::LoadApproachData() { - FGNPIAP* iap; + FGNPIAP* iap = NULL; GPSWaypoint* wp; GPSFlightPlan* fp; const GPSWaypoint* cwp; diff --git a/src/Instrumentation/heading_indicator_dg.cxx b/src/Instrumentation/heading_indicator_dg.cxx index 9bcd19b67..bb9c1620e 100644 --- a/src/Instrumentation/heading_indicator_dg.cxx +++ b/src/Instrumentation/heading_indicator_dg.cxx @@ -125,7 +125,6 @@ HeadingIndicatorDG::update (double dt) double yaw_rate = _yaw_rate_node->getDoubleValue(); double error = _error_node->getDoubleValue(); double g = _g_node->getDoubleValue(); - int sign = 0; if ( fabs ( yaw_rate ) > 5 ) { error += 0.033 * -yaw_rate * dt ; diff --git a/src/Instrumentation/rnav_waypt_controller.cxx b/src/Instrumentation/rnav_waypt_controller.cxx index 278484d0a..e728b88d2 100644 --- a/src/Instrumentation/rnav_waypt_controller.cxx +++ b/src/Instrumentation/rnav_waypt_controller.cxx @@ -342,6 +342,9 @@ public: case RESTRICT_NONE: assert(false); break; + case SPEED_RESTRICT_MACH: + assert(false); + break; } } diff --git a/src/Time/sunsolver.cxx b/src/Time/sunsolver.cxx index b903f5e56..b45e0bf2c 100644 --- a/src/Time/sunsolver.cxx +++ b/src/Time/sunsolver.cxx @@ -53,13 +53,12 @@ void fgSunPositionGST(double gst, double *lon, double *lat) { /* double *lat; (return) latitude */ /* double *lon; (return) longitude */ - double alpha, delta; double tmp; SGPropertyNode* sun = fgGetNode("/ephemeris/sun"); assert(sun); double xs = sun->getDoubleValue("xs"); - double ys = sun->getDoubleValue("ys"); + //double ys = sun->getDoubleValue("ys"); double ye = sun->getDoubleValue("ye"); double ze = sun->getDoubleValue("ze"); double ra = atan2(ye, xs); From edfc06119afc178c34f738565555e6aac599b6c1 Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Fri, 4 Feb 2011 19:38:22 +0100 Subject: [PATCH 2/5] Not reported by cppcheck: fix another memory leak :) Extends/changes commit 687be046789e2f509ccf93155456c47f3f463e0c to fix a related second leak (with "model"). --- src/Model/modelmgr.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index 181435ef1..2e6ad72bc 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -70,10 +70,6 @@ FGModelMgr::add_model (SGPropertyNode * node) { SG_LOG(SG_GENERAL, SG_INFO, "Adding model " << node->getStringValue("name", "[unnamed]")); - Instance * instance = new Instance; - SGModelPlacement *model = new SGModelPlacement; - instance->model = model; - instance->node = node; const char *path = node->getStringValue("path", "Models/Geometry/glider.ac"); osg::Node *object; @@ -83,9 +79,13 @@ FGModelMgr::add_model (SGPropertyNode * node) } catch (const sg_throwable& t) { SG_LOG(SG_GENERAL, SG_ALERT, "Error loading " << path << ":\n " << t.getFormattedMessage() << t.getOrigin()); - delete instance; return; } + + Instance * instance = new Instance; + SGModelPlacement *model = new SGModelPlacement; + instance->model = model; + instance->node = node; model->init( object ); From ad8d46ba648263630b8777c53f852b75cad7ecdd Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Sat, 5 Feb 2011 17:49:26 +0100 Subject: [PATCH 3/5] Improved fix for #204 and #222: JSBSim::unbind() needs to untie _all_ its properties Extends and partially reverts commit 287cc74965e11ff3888117a9d9b88ed2bdbb9252 Previous fix did not consider properties outside the /fdm/jsbsim branch. FGPropertyManager now keeps track of all its tied properties - and provides a method to cleanly untie them again. --- src/FDM/JSBSim/FGFDMExec.h | 7 +++++-- src/FDM/JSBSim/JSBSim.cxx | 21 +------------------ .../JSBSim/input_output/FGPropertyManager.cpp | 18 ++++++++++++++++ .../JSBSim/input_output/FGPropertyManager.h | 8 +++++++ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index 10736f4a4..c1038c471 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -101,8 +101,8 @@ CLASS DOCUMENTATION file: @code - fdmex = new FGFDMExec( � ); - result = fdmex->LoadModel( � ); + fdmex = new FGFDMExec( ... ); + result = fdmex->LoadModel( ... ); @endcode When an aircraft model is loaded, the config file is parsed and for each of the @@ -226,6 +226,9 @@ public: /// Default destructor ~FGFDMExec(); + /** Unbind all tied JSBSim properties. */ + void unbind(void) {instance->unbind();} + /** This routine places a model into the runlist at the specified rate. The "rate" is not really a clock rate. It represents how many calls to the FGFDMExec::Run() method must be made before the model is executed. A diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index a9e9be771..0cc00259a 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -422,28 +422,9 @@ void FGJSBsim::init() /******************************************************************************/ -void checkTied ( FGPropertyManager *node ) -{ - int N = node->nChildren(); - string name; - - for (int i=0; i<N; i++) { - if (node->getChild(i)->nChildren() ) { - checkTied( (FGPropertyManager*)node->getChild(i) ); - } - if ( node->getChild(i)->isTied() ) { - name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName(); - node->Untie(name); - } - } -} - -/******************************************************************************/ - void FGJSBsim::unbind() { - SGPropertyNode* instance = globals->get_props()->getNode("/fdm/jsbsim"); - checkTied((FGPropertyManager*)instance); + fdmex->unbind(); FGInterface::unbind(); } diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.cpp b/src/FDM/JSBSim/input_output/FGPropertyManager.cpp index 11e566965..899565ed2 100755 --- a/src/FDM/JSBSim/input_output/FGPropertyManager.cpp +++ b/src/FDM/JSBSim/input_output/FGPropertyManager.cpp @@ -49,6 +49,19 @@ COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs] namespace JSBSim { bool FGPropertyManager::suppress_warning = true; +std::vector<std::string> FGPropertyManager::tied_properties; + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGPropertyManager::unbind(void) +{ + vector<string>::iterator it; + for (it = tied_properties.begin();it < tied_properties.end();it++) + { + Untie(*it); + } + tied_properties.clear(); +} //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -301,6 +314,7 @@ void FGPropertyManager::Untie (const string &name) void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) @@ -312,6 +326,7 @@ void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault) void FGPropertyManager::Tie (const string &name, int *pointer, bool useDefault ) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) @@ -323,6 +338,7 @@ void FGPropertyManager::Tie (const string &name, int *pointer, void FGPropertyManager::Tie (const string &name, long *pointer, bool useDefault ) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) @@ -334,6 +350,7 @@ void FGPropertyManager::Tie (const string &name, long *pointer, void FGPropertyManager::Tie (const string &name, float *pointer, bool useDefault ) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) @@ -344,6 +361,7 @@ void FGPropertyManager::Tie (const string &name, float *pointer, void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault) { + tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; else if (debug_lvl & 0x20) diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.h b/src/FDM/JSBSim/input_output/FGPropertyManager.h index c29b5a412..54ea91874 100644 --- a/src/FDM/JSBSim/input_output/FGPropertyManager.h +++ b/src/FDM/JSBSim/input_output/FGPropertyManager.h @@ -77,6 +77,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase { private: static bool suppress_warning; + static std::vector<std::string> tied_properties; public: /// Constructor FGPropertyManager(void) {suppress_warning = false;} @@ -399,6 +400,13 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase */ void Untie (const std::string &name); + /** + * Unbind all properties bound by this manager to an external data source. + * + * Classes should use this function to release control of any + * properties they have bound using this property manager. + */ + void unbind (void); // Templates cause ambiguity here From 0d233c0dfc2cab48be7642ef17f11e1b9ff9ced5 Mon Sep 17 00:00:00 2001 From: ThorstenB <brehmt@gmail.com> Date: Sun, 6 Feb 2011 15:16:58 +0100 Subject: [PATCH 4/5] Bertrand Coconnier: updated fix for #204 and #222: JSBSim reset Use shared property pointers instead of path strings, adapt method names to JSBSim style, catch all property ties, proper error handling when tieing failed. --- src/FDM/JSBSim/FGFDMExec.cpp | 18 +-------- src/FDM/JSBSim/FGFDMExec.h | 2 +- src/FDM/JSBSim/JSBSim.cxx | 2 +- .../JSBSim/input_output/FGPropertyManager.cpp | 37 +++++++++++-------- .../JSBSim/input_output/FGPropertyManager.h | 26 ++++++++----- 5 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index b3b7003c2..ade4209cd 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -78,22 +78,6 @@ static const char *IdHdr = ID_FDMEXEC; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -void checkTied ( FGPropertyManager *node ) -{ - int N = node->nChildren(); - string name; - - for (int i=0; i<N; i++) { - if (node->getChild(i)->nChildren() ) { - checkTied( (FGPropertyManager*)node->getChild(i) ); - } - if ( node->getChild(i)->isTied() ) { - name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName(); - node->Untie(name); - } - } -} - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Constructor @@ -185,7 +169,7 @@ FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) : Root(root) FGFDMExec::~FGFDMExec() { try { - checkTied( instance ); + Unbind(); DeAllocate(); if (IdFDM == 0) { // Meaning this is no child FDM diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index c1038c471..b982654e7 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -227,7 +227,7 @@ public: ~FGFDMExec(); /** Unbind all tied JSBSim properties. */ - void unbind(void) {instance->unbind();} + void Unbind(void) {instance->Unbind();} /** This routine places a model into the runlist at the specified rate. The "rate" is not really a clock rate. It represents how many calls to the diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index 0cc00259a..b1daa9cd3 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -424,7 +424,7 @@ void FGJSBsim::init() void FGJSBsim::unbind() { - fdmex->unbind(); + fdmex->Unbind(); FGInterface::unbind(); } diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.cpp b/src/FDM/JSBSim/input_output/FGPropertyManager.cpp index 899565ed2..c0218ec20 100755 --- a/src/FDM/JSBSim/input_output/FGPropertyManager.cpp +++ b/src/FDM/JSBSim/input_output/FGPropertyManager.cpp @@ -53,7 +53,7 @@ std::vector<std::string> FGPropertyManager::tied_properties; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGPropertyManager::unbind(void) +void FGPropertyManager::Unbind(void) { vector<string>::iterator it; for (it = tied_properties.begin();it < tied_properties.end();it++) @@ -314,11 +314,12 @@ void FGPropertyManager::Untie (const string &name) void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault) { - tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; - else if (debug_lvl & 0x20) - cout << name << endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -326,11 +327,12 @@ void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault) void FGPropertyManager::Tie (const string &name, int *pointer, bool useDefault ) { - tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; - else if (debug_lvl & 0x20) - cout << name << endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -338,11 +340,12 @@ void FGPropertyManager::Tie (const string &name, int *pointer, void FGPropertyManager::Tie (const string &name, long *pointer, bool useDefault ) { - tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; - else if (debug_lvl & 0x20) - cout << name << endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -350,22 +353,24 @@ void FGPropertyManager::Tie (const string &name, long *pointer, void FGPropertyManager::Tie (const string &name, float *pointer, bool useDefault ) { - tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; - else if (debug_lvl & 0x20) - cout << name << endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault) { - tied_properties.push_back(name); if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault)) cerr << "Failed to tie property " << name << " to a pointer" << endl; - else if (debug_lvl & 0x20) - cout << name << endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } } // namespace JSBSim diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.h b/src/FDM/JSBSim/input_output/FGPropertyManager.h index 54ea91874..a08f89681 100644 --- a/src/FDM/JSBSim/input_output/FGPropertyManager.h +++ b/src/FDM/JSBSim/input_output/FGPropertyManager.h @@ -406,7 +406,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * Classes should use this function to release control of any * properties they have bound using this property manager. */ - void unbind (void); + void Unbind (void); // Templates cause ambiguity here @@ -534,8 +534,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase { if (!tie(name.c_str(), SGRawValueFunctions<V>(getter, setter), useDefault)) std::cout << "Failed to tie property " << name << " to functions" << std::endl; - else if (debug_lvl & 0x20) - std::cout << name << std::endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } @@ -562,8 +564,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase { if (!tie(name.c_str(), SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault)) std::cout << "Failed to tie property " << name << " to indexed functions" << std::endl; - else if (debug_lvl & 0x20) - std::cout << name << std::endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } @@ -592,8 +596,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase { if (!tie(name.c_str(), SGRawValueMethods<T,V>(*obj, getter, setter), useDefault)) std::cout << "Failed to tie property " << name << " to object methods" << std::endl; - else if (debug_lvl & 0x20) - std::cout << name << std::endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } /** @@ -621,8 +627,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase { if (!tie(name.c_str(), SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault)) std::cout << "Failed to tie property " << name << " to indexed object methods" << std::endl; - else if (debug_lvl & 0x20) - std::cout << name << std::endl; + else { + tied_properties.push_back(name); + if (debug_lvl & 0x20) std::cout << name << std::endl; + } } }; } From d1b35578c86b47596fd77cdc397689503c00345e Mon Sep 17 00:00:00 2001 From: Torsten Dreyer <Torsten@t3r.de> Date: Sun, 6 Feb 2011 15:44:09 +0100 Subject: [PATCH 5/5] Move tiedpropertylist from flightgear to simgear --- src/Environment/environment.hxx | 4 +- src/Environment/environment_ctrl.cxx | 2 +- src/Environment/environment_mgr.hxx | 4 +- src/Environment/metarairportfilter.hxx | 1 - src/Environment/metarproperties.hxx | 4 +- src/Environment/realwx_ctrl.cxx | 4 +- src/Environment/terrainsampler.cxx | 6 +- src/Environment/tiedpropertylist.hxx | 80 -------------------------- 8 files changed, 12 insertions(+), 93 deletions(-) delete mode 100644 src/Environment/tiedpropertylist.hxx diff --git a/src/Environment/environment.hxx b/src/Environment/environment.hxx index 048b17992..c1da68037 100644 --- a/src/Environment/environment.hxx +++ b/src/Environment/environment.hxx @@ -25,7 +25,7 @@ #include <simgear/compiler.h> #include <cmath> -#include "tiedpropertylist.hxx" +#include <simgear/props/tiedpropertylist.hxx> /** * Model the natural environment. @@ -146,7 +146,7 @@ private: double wind_from_down_fps; bool live_update; - TiedPropertyList _tiedProperties; + simgear::TiedPropertyList _tiedProperties; }; diff --git a/src/Environment/environment_ctrl.cxx b/src/Environment/environment_ctrl.cxx index d4ebbf595..c182f0625 100644 --- a/src/Environment/environment_ctrl.cxx +++ b/src/Environment/environment_ctrl.cxx @@ -123,7 +123,7 @@ private: LayerTable _aloft_table; FGEnvironment _environment; - TiedPropertyList _tiedProperties; + simgear::TiedPropertyList _tiedProperties; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/src/Environment/environment_mgr.hxx b/src/Environment/environment_mgr.hxx index d9c770319..e6041f813 100644 --- a/src/Environment/environment_mgr.hxx +++ b/src/Environment/environment_mgr.hxx @@ -25,7 +25,7 @@ #include <simgear/compiler.h> #include <simgear/structure/subsystem_mgr.hxx> #include <simgear/math/SGMath.hxx> -#include "tiedpropertylist.hxx" +#include <simgear/props/tiedpropertylist.hxx> #ifdef SG_HAVE_STD_INCLUDES # include <cmath> @@ -96,7 +96,7 @@ private: FGClouds *fgClouds; SGPropertyNode_ptr _altitudeNode; bool _cloudLayersDirty; - TiedPropertyList _tiedProperties; + simgear::TiedPropertyList _tiedProperties; }; #endif // _ENVIRONMENT_MGR_HXX diff --git a/src/Environment/metarairportfilter.hxx b/src/Environment/metarairportfilter.hxx index 568a28b95..f31eb64f5 100644 --- a/src/Environment/metarairportfilter.hxx +++ b/src/Environment/metarairportfilter.hxx @@ -24,7 +24,6 @@ #include <Airports/simple.hxx> #include <simgear/props/props.hxx> -#include "tiedpropertylist.hxx" namespace Environment { diff --git a/src/Environment/metarproperties.hxx b/src/Environment/metarproperties.hxx index 0e157169e..7d108100d 100644 --- a/src/Environment/metarproperties.hxx +++ b/src/Environment/metarproperties.hxx @@ -25,7 +25,7 @@ #include <Airports/simple.hxx> #include <simgear/props/props.hxx> -#include "tiedpropertylist.hxx" +#include <simgear/props/tiedpropertylist.hxx> namespace Environment { @@ -89,7 +89,7 @@ private: bool _snow_cover; std::string _decoded; protected: - TiedPropertyList _tiedProperties; + simgear::TiedPropertyList _tiedProperties; MagneticVariation * _magneticVariation; }; diff --git a/src/Environment/realwx_ctrl.cxx b/src/Environment/realwx_ctrl.cxx index 98fe6ed3b..197f4cf52 100644 --- a/src/Environment/realwx_ctrl.cxx +++ b/src/Environment/realwx_ctrl.cxx @@ -25,7 +25,6 @@ #endif #include "realwx_ctrl.hxx" -#include "tiedpropertylist.hxx" #include "metarproperties.hxx" #include "metarairportfilter.hxx" #include "fgmetar.hxx" @@ -34,6 +33,7 @@ #include <simgear/structure/exception.hxx> #include <simgear/misc/strutils.hxx> +#include <simgear/props/tiedpropertylist.hxx> #include <algorithm> #if defined(ENABLE_THREADS) #include <OpenThreads/Thread> @@ -105,7 +105,7 @@ protected: bool _enabled; bool __enabled; - TiedPropertyList _tiedProperties; + simgear::TiedPropertyList _tiedProperties; ; typedef std::vector<LiveMetarProperties_ptr> MetarPropertiesList; MetarPropertiesList _metarProperties; }; diff --git a/src/Environment/terrainsampler.cxx b/src/Environment/terrainsampler.cxx index 276c8ffb1..0d08af84e 100644 --- a/src/Environment/terrainsampler.cxx +++ b/src/Environment/terrainsampler.cxx @@ -32,7 +32,7 @@ #include "terrainsampler.hxx" using simgear::PropertyList; -#include "tiedpropertylist.hxx" +#include <simgear/props/tiedpropertylist.hxx> namespace Environment { /** @@ -93,7 +93,7 @@ private: SGPropertyNode_ptr _positionLongitudeNode; deque<double> _elevations; - TiedPropertyList _tiedProperties; + simgear::TiedPropertyList _tiedProperties; }; AreaSampler::AreaSampler( SGPropertyNode_ptr rootNode ) : @@ -329,7 +329,7 @@ private: SGPropertyNode_ptr _rootNode; bool _enabled; - TiedPropertyList _tiedProperties; + simgear::TiedPropertyList _tiedProperties; }; TerrainSamplerImplementation::TerrainSamplerImplementation( SGPropertyNode_ptr rootNode ) : diff --git a/src/Environment/tiedpropertylist.hxx b/src/Environment/tiedpropertylist.hxx deleted file mode 100644 index cfdd57c97..000000000 --- a/src/Environment/tiedpropertylist.hxx +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef __TIEDPROPERTYLIST_HXX -#define __TIEDPROPERTYLIST_HXX -#include <simgear/props/props.hxx> -using simgear::PropertyList; - -// Maybe this goes into SimGear's props.hxx later? -class TiedPropertyList : PropertyList { -public: - TiedPropertyList() {} - TiedPropertyList( SGPropertyNode_ptr root ) : _root(root) {} - - void setRoot( SGPropertyNode_ptr root ) { _root = root; } - SGPropertyNode_ptr getRoot() const { return _root; } - - template<typename T> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, const SGRawValue<T> &rawValue, bool useDefault = true ) { - bool success = node->tie( rawValue, useDefault ); - if( success ) { - SG_LOG( SG_ALL, SG_INFO, "Tied " << node->getPath() ); - push_back( node ); - } else { -#if PROPS_STANDALONE - cerr << "Failed to tie property " << node->getPath() << endl; -#else - SG_LOG(SG_GENERAL, SG_WARN, "Failed to tie property " << node->getPath() ); -#endif - } - return node; - } - - template <class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, V * value, bool useDefault = true ) { - return Tie( node, SGRawValuePointer<V>(value), useDefault ); - } - - template <class V> SGPropertyNode_ptr Tie( const char * relative_path, V * value, bool useDefault = true ) { - return Tie( _root->getNode(relative_path,true), SGRawValuePointer<V>(value), useDefault ); - } - - template <class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true ) { - return Tie(node, SGRawValueFunctions<V>(getter, setter), useDefault ); - } - - template <class V> SGPropertyNode_ptr Tie( const char * relative_path, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true ) { - return Tie(_root->getNode(relative_path, true), SGRawValueFunctions<V>(getter, setter), useDefault ); - } - - template <class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, int index, V (*getter)(int), void (*setter)(int, V) = 0, bool useDefault = true) { - return Tie( node, SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault ); - } - - template <class V> SGPropertyNode_ptr Tie( const char * relative_path, int index, V (*getter)(int), void (*setter)(int, V) = 0, bool useDefault = true) { - return Tie( _root->getNode( relative_path, true ), SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault ); - } - - template <class T, class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, T * obj, V (T::*getter)() const, void (T::*setter)(V) = 0, bool useDefault = true) { - return Tie( node, SGRawValueMethods<T,V>(*obj, getter, setter), useDefault ); - } - - template <class T, class V> SGPropertyNode_ptr Tie( const char * relative_path, T * obj, V (T::*getter)() const, void (T::*setter)(V) = 0, bool useDefault = true) { - return Tie( _root->getNode( relative_path, true), SGRawValueMethods<T,V>(*obj, getter, setter), useDefault ); - } - - template <class T, class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, T * obj, int index, V (T::*getter)(int) const, void (T::*setter)(int, V) = 0, bool useDefault = true) { - return Tie( node, SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault); - } - - template <class T, class V> SGPropertyNode_ptr Tie( const char * relative_path, T * obj, int index, V (T::*getter)(int) const, void (T::*setter)(int, V) = 0, bool useDefault = true) { - return Tie( _root->getNode( relative_path, true ), SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault); - } - - void Untie() { - while( size() > 0 ) { - SG_LOG( SG_ALL, SG_INFO, "untie of " << back()->getPath() ); - back()->untie(); - pop_back(); - } - } -private: - SGPropertyNode_ptr _root; -}; -#endif