On Sun, 12 Aug 2007, Hans Fugal wrote:

That's because there is no custom comparison predicate for comparing
bucket*. vector<bucket*> is just a list of pointers, and so uses the
sort order for pointers. You'd have to set up an STL functor to sort
them, which is ugly and difficult (but certainly doable). If sorting
is unnecessary it's a better way to go, obviously. :-)

Yep, that's what I figured out eventually. I think it is safer to keep the
sorting for now - in case e.g. the user changes the layer elevations using the property browser.

The patch included adds a comparison predicate for buckets.

Please test it and commit it if it is acceptable. It works fine here.

Cheers,

Anders
--
---------------------------------------------------------------------------
Anders Gidenstam
mail: anders(at)gidenstam.org
WWW: http://www.gidenstam.org/FlightGear/JSBSim-LTA/
diff --git a/src/Environment/environment_ctrl.cxx 
b/src/Environment/environment_ctrl.cxx
index a1ed5f2..0ca2cba 100644
--- a/src/Environment/environment_ctrl.cxx
+++ b/src/Environment/environment_ctrl.cxx
@@ -231,7 +231,7 @@ FGInterpolateEnvironmentCtrl::read_table (const 
SGPropertyNode * node,
             table.push_back(b);
         }
     }
-    sort(table.begin(), table.end());
+    sort(table.begin(), table.end(), bucket::lessThan);
 }
 
 void
@@ -312,6 +312,11 @@ FGInterpolateEnvironmentCtrl::bucket::operator< (const 
bucket &b) const
     return (altitude_ft < b.altitude_ft);
 }
 
+bool
+FGInterpolateEnvironmentCtrl::bucket::lessThan(bucket *a, bucket *b)
+{
+    return (a->altitude_ft) < (b->altitude_ft);
+}
 
 
 ////////////////////////////////////////////////////////////////////////
diff --git a/src/Environment/environment_ctrl.hxx 
b/src/Environment/environment_ctrl.hxx
index f561f05..cd01b55 100644
--- a/src/Environment/environment_ctrl.hxx
+++ b/src/Environment/environment_ctrl.hxx
@@ -134,6 +134,8 @@ private:
         double altitude_ft;
         FGEnvironment environment;
         bool operator< (const bucket &b) const;
+        // LessThan predicate for bucket pointers.
+        static bool lessThan(bucket *a, bucket *b);
     };
 
     void read_table (const SGPropertyNode * node, vector<bucket *> &table);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to