From a7e4f2a971acf2262cd1a5840c774a7d8a784a4b Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Thu, 28 Mar 2013 16:49:52 +0000
Subject: [PATCH] std:: namespace fixes, AIBase cleanup.

Make data members in AIBase protected, and move FGAIModelData to be
a private helper in the .cxx file.
---
 src/AIModel/AIAircraft.hxx                 |  2 +-
 src/AIModel/AIBallistic.cxx                |  3 +-
 src/AIModel/AIBallistic.hxx                | 21 +++---
 src/AIModel/AIBase.cxx                     | 67 +++++++++++++-------
 src/AIModel/AIBase.hxx                     | 74 ++++++++--------------
 src/AIModel/AIFlightPlan.cxx               |  1 +
 src/AIModel/AIFlightPlanCreate.cxx         |  1 +
 src/AIModel/AIFlightPlanCreateCruise.cxx   |  1 +
 src/AIModel/AIFlightPlanCreatePushBack.cxx |  1 +
 src/AIModel/AIGroundVehicle.cxx            |  2 +
 src/AIModel/AIMultiplayer.cxx              |  1 +
 src/AIModel/AIShip.cxx                     |  1 +
 src/AIModel/AIShip.hxx                     | 18 +++---
 src/AIModel/AITanker.cxx                   |  2 +
 src/AIModel/AITanker.hxx                   |  4 +-
 src/AIModel/submodel.cxx                   |  2 +
 src/ATC/atc_mgr.cxx                        |  2 +
 src/Main/positioninit.cxx                  |  1 +
 18 files changed, 107 insertions(+), 97 deletions(-)

diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx
index 58fd417f6..2f7c2d547 100644
--- a/src/AIModel/AIAircraft.hxx
+++ b/src/AIModel/AIAircraft.hxx
@@ -52,7 +52,7 @@ public:
     void initializeFlightPlan();
     FGAIFlightPlan* GetFlightPlan() const { return fp; };
     void ProcessFlightPlan( double dt, time_t now );
-    time_t checkForArrivalTime(const string& wptName);
+    time_t checkForArrivalTime(const std::string& wptName);
     
     void AccelTo(double speed);
     void PitchTo(double angle);
diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx
index 962795e88..5a50034b1 100644
--- a/src/AIModel/AIBallistic.cxx
+++ b/src/AIModel/AIBallistic.cxx
@@ -35,6 +35,7 @@
 #include <Environment/gravity.hxx>
 
 using namespace simgear;
+using std::string;
 
 const double FGAIBallistic::slugs_to_kgs = 14.5939029372;
 const double FGAIBallistic::slugs_to_lbs = 32.1740485564;
@@ -505,7 +506,7 @@ bool FGAIBallistic::getHtAGL(double start){
             _ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET;
 
             if (material) {
-                const vector<string>& names = material->get_names();
+                const std::vector<string>& names = material->get_names();
                 _solid = material->get_solid();
                 _load_resistance = material->get_load_resistance();
                 _frictionFactor = material->get_friction_factor();
diff --git a/src/AIModel/AIBallistic.hxx b/src/AIModel/AIBallistic.hxx
index fbbeeb4d7..ca8b92879 100644
--- a/src/AIModel/AIBallistic.hxx
+++ b/src/AIModel/AIBallistic.hxx
@@ -31,9 +31,6 @@
 #include "AIManager.hxx"
 #include "AIBase.hxx"
 
-using std::vector;
-using std::list;
-
 class FGAIBallistic : public FGAIBase {
 
 public:
@@ -72,15 +69,15 @@ public:
     void setCollision(bool c);
     void setExpiry(bool e);
     void setImpact(bool i);
-    void setImpactReportNode(const string&);
+    void setImpactReportNode(const std::string&);
     void setContentsNode(const SGPropertyNode_ptr);
     void setFuseRange(double f);
-    void setSMPath(const string&);
+    void setSMPath(const std::string&);
     void setSubID(int i);
-    void setSubmodel(const string&);
+    void setSubmodel(const std::string&);
     void setExternalForce( bool f );
-    void setForcePath(const string&);
-    void setContentsPath(const string&);
+    void setForcePath(const std::string&);
+    void setContentsPath(const std::string&);
     void setForceStabilisation( bool val );
     void setGroundOffset(double g);
     void setLoadOffset(double l);
@@ -188,7 +185,7 @@ private:
     bool   _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
     double _contents_lb;     // contents of the object
     double _weight_lb;       // weight of the object (no contents if appropriate) (lbs)
-    string _mat_name;
+    std::string _mat_name;
 
     bool   _report_collision;       // if true a collision point with AI Objects is calculated
     bool   _report_impact;          // if true an impact point on the terrain is calculated
@@ -215,9 +212,9 @@ private:
     double _dt_count;
     double _next_run;
 
-    string _submodel;
-    string _force_path;
-    string _contents_path;
+    std::string _submodel;
+    std::string _force_path;
+    std::string _contents_path;
 
     void handle_collision();
     void handle_expiry();
diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx
index 01c0c2691..4db3e8f11 100644
--- a/src/AIModel/AIBase.cxx
+++ b/src/AIModel/AIBase.cxx
@@ -53,8 +53,52 @@ const char *default_model = "Models/Geometry/glider.ac";
 const double FGAIBase::e = 2.71828183;
 const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
 
+using std::string;
 using namespace simgear;
 
+class FGAIModelData : public simgear::SGModelData {
+public:
+    FGAIModelData(SGPropertyNode *root = NULL)
+        : _nasal( new FGNasalModelDataProxy(root) ),
+        _ready(false),
+        _initialized(false)
+    {
+    }
+
+    
+    ~FGAIModelData()
+    {
+    }
+    
+    /** osg callback, thread-safe */
+    void modelLoaded(const std::string& path, SGPropertyNode *prop, osg::Node *n)
+    {
+        // WARNING: Called in a separate OSG thread! Only use thread-safe stuff here...
+        if (_ready)
+            return;
+        
+        _fxpath = prop->getStringValue("sound/path");
+        _nasal->modelLoaded(path, prop, n);
+        
+        _ready = true;
+
+    }
+    
+    /** init hook to be called after model is loaded.
+     * Not thread-safe. Call from main thread only. */
+    void init(void) { _initialized = true; }
+    
+    bool needInitilization(void) { return _ready && !_initialized;}
+    bool isInitialized(void) { return _initialized;}
+    inline std::string& get_sound_path() { return _fxpath;}
+    
+private:
+    std::auto_ptr<FGNasalModelDataProxy> _nasal;
+    std::string _fxpath;
+    bool _ready;
+    bool _initialized;
+};
+
 FGAIBase::FGAIBase(object_type ot, bool enableHot) :
     _max_speed(300),
     _name(""),
@@ -843,27 +887,4 @@ int FGAIBase::_newAIModelID() {
 }
 
 
-FGAIModelData::FGAIModelData(SGPropertyNode *root)
-  : _nasal( new FGNasalModelDataProxy(root) ),
-    _ready(false),
-    _initialized(false)
-{
-}
 
-FGAIModelData::~FGAIModelData()
-{
-    delete _nasal;
-    _nasal = NULL;
-}
-
-void FGAIModelData::modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *n)
-{
-    // WARNING: Called in a separate OSG thread! Only use thread-safe stuff here...
-    if (_ready)
-        return;
-
-    _fxpath = prop->getStringValue("sound/path");
-    _nasal->modelLoaded(path, prop, n);
-
-    _ready = true;
-}
diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx
index 70e7c9718..52be8e5a3 100644
--- a/src/AIModel/AIBase.hxx
+++ b/src/AIModel/AIBase.hxx
@@ -22,9 +22,10 @@
 
 #include <string>
 
+#include <osg/LOD>
+
 #include <simgear/constants.h>
 #include <simgear/scene/model/placement.hxx>
-#include <simgear/scene/model/modellib.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 #include <simgear/structure/SGReferenced.hxx>
@@ -35,16 +36,12 @@
 
 #include <Main/fg_props.hxx>
 
-
-using std::string;
-
 namespace simgear {
 class BVHMaterial;
 }
 class FGAIManager;
 class FGAIFlightPlan;
 class FGFX;
-class FGNasalModelDataProxy;
 class FGAIModelData;    // defined below
 
 
@@ -71,8 +68,8 @@ public:
     void updateLOD();
     void setManager(FGAIManager* mgr, SGPropertyNode* p);
     void setPath( const char* model );
-    void setSMPath( const string& p );
-    void setCallSign(const string& );
+    void setSMPath( const std::string& p );
+    void setCallSign(const std::string& );
     void setSpeed( double speed_KTAS );
     void setAltitude( double altitude_ft );
     void setAltitudeAGL( double altitude_agl_ft );
@@ -95,8 +92,8 @@ public:
     void setImpactLat( double lat );
     void setImpactLon( double lon );
     void setImpactElev( double e );
-    void setParentName(const string& p);
-    void setName(const string& n);
+    void setParentName(const std::string& p);
+    void setName(const std::string& n);
     void setMaxSpeed(double kts);
 
     void calcRangeBearing(double lat, double lon, double lat2, double lon2,
@@ -118,29 +115,31 @@ public:
     bool getGroundElevationM(const SGGeod& pos, double& elev,
                              const simgear::BVHMaterial** material) const;
 
-    double _elevation_m;
 
     double _getCartPosX() const;
     double _getCartPosY() const;
     double _getCartPosZ() const;
+    
+protected:
+    double _elevation_m;
+    
 
     double _x_offset;
     double _y_offset;
     double _z_offset;
-
+    
     double _pitch_offset;
     double _roll_offset;
     double _yaw_offset;
-
+    
     double _max_speed;
-
-    string _path;
-    string _callsign;
-    string _submodel;
+    
+    std::string _path;
+    std::string _callsign;
+    std::string _submodel;
     std::string _name;
-    string _parent;
-
-protected:
+    std::string _parent;
+    
     /**
      * Tied-properties helper, record nodes which are tied for easy un-tie-ing
      */
@@ -195,7 +194,7 @@ protected:
     double rotation;     // value used by radar display instrument
     double ht_diff;      // value used by radar display instrument
 
-    string model_path;   //Path to the 3D model
+    std::string model_path;   //Path to the 3D model
     SGModelPlacement aip;
 
     bool delete_me;
@@ -318,7 +317,7 @@ public:
 
     static bool _isNight();
 
-     string & getCallSign();
+    std::string & getCallSign();
 };
 
 inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) {
@@ -330,7 +329,7 @@ inline void FGAIBase::setPath(const char* model ) {
     model_path.append(model);
 }
 
-inline void FGAIBase::setSMPath(const string& p) {
+inline void FGAIBase::setSMPath(const std::string& p) {
     _path = p;
 }
 
@@ -376,10 +375,10 @@ inline void FGAIBase::setLatitude ( double latitude ) {
     pos.setLatitudeDeg( latitude );
 }
 
-inline void FGAIBase::setCallSign(const string& s) {
+inline void FGAIBase::setCallSign(const std::string& s) {
     _callsign = s;
 }
-inline string& FGAIBase::getCallSign() {
+inline std::string& FGAIBase::getCallSign() {
     return _callsign;
 }
 
@@ -407,11 +406,11 @@ inline void FGAIBase::setYawoffset(double y) {
     _yaw_offset = y;
 }
 
-inline void FGAIBase::setParentName(const string& p) {
+inline void FGAIBase::setParentName(const std::string& p) {
     _parent = p;
 }
 
-inline void FGAIBase::setName(const string& n) {
+inline void FGAIBase::setName(const std::string& n) {
     _name = n;
 }
 
@@ -453,27 +452,4 @@ inline void FGAIBase::setMaxSpeed(double m) {
 }
 
 
-class FGAIModelData : public simgear::SGModelData {
-public:
-    FGAIModelData(SGPropertyNode *root = 0);
-    ~FGAIModelData();
-
-    /** osg callback, thread-safe */
-    void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *n);
-
-    /** init hook to be called after model is loaded.
-     * Not thread-safe. Call from main thread only. */
-    void init(void) { _initialized = true; }
-
-    bool needInitilization(void) { return _ready && !_initialized;}
-    bool isInitialized(void) { return _initialized;}
-    inline std::string& get_sound_path() { return _fxpath;}
-
-private:
-    FGNasalModelDataProxy *_nasal;
-    std::string _fxpath;
-    bool _ready;
-    bool _initialized;
-};
-
 #endif // _FG_AIBASE_HXX
diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx
index ce20ea2b3..61ba0e56b 100644
--- a/src/AIModel/AIFlightPlan.cxx
+++ b/src/AIModel/AIFlightPlan.cxx
@@ -45,6 +45,7 @@
 #include "AIAircraft.hxx"
 
 using std::cerr;
+using std::string;
 
 FGAIWaypoint::FGAIWaypoint() {
   speed       = 0;
diff --git a/src/AIModel/AIFlightPlanCreate.cxx b/src/AIModel/AIFlightPlanCreate.cxx
index caad321e2..9ec77c2c3 100644
--- a/src/AIModel/AIFlightPlanCreate.cxx
+++ b/src/AIModel/AIFlightPlanCreate.cxx
@@ -41,6 +41,7 @@
 #include <FDM/LaRCsim/basic_aero.h>
 #include <Navaids/navrecord.hxx>
 
+using std::string;
 
 /* FGAIFlightPlan::create()
  * dynamically create a flight plan for AI traffic, based on data provided by the
diff --git a/src/AIModel/AIFlightPlanCreateCruise.cxx b/src/AIModel/AIFlightPlanCreateCruise.cxx
index beecef8eb..709378f90 100644
--- a/src/AIModel/AIFlightPlanCreateCruise.cxx
+++ b/src/AIModel/AIFlightPlanCreateCruise.cxx
@@ -38,6 +38,7 @@
 #include "performancedata.hxx"
 
 using std::iostream;
+using std::string;
 
 /*
 void FGAIFlightPlan::evaluateRoutePart(double deplat,
diff --git a/src/AIModel/AIFlightPlanCreatePushBack.cxx b/src/AIModel/AIFlightPlanCreatePushBack.cxx
index cb5ade5cc..0e7efc80c 100644
--- a/src/AIModel/AIFlightPlanCreatePushBack.cxx
+++ b/src/AIModel/AIFlightPlanCreatePushBack.cxx
@@ -38,6 +38,7 @@
 #include "AIAircraft.hxx"
 #include "performancedata.hxx"
 
+using std::string;
 
 // TODO: Use James Turner's createOnGround functions.
 bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
diff --git a/src/AIModel/AIGroundVehicle.cxx b/src/AIModel/AIGroundVehicle.cxx
index b813b3c82..15424079e 100644
--- a/src/AIModel/AIGroundVehicle.cxx
+++ b/src/AIModel/AIGroundVehicle.cxx
@@ -30,6 +30,8 @@
 
 #include "AIGroundVehicle.hxx"
 
+using std::string;
+
 FGAIGroundVehicle::FGAIGroundVehicle() :
 FGAIShip(otGroundVehicle),
 
diff --git a/src/AIModel/AIMultiplayer.cxx b/src/AIModel/AIMultiplayer.cxx
index 0c9bd9740..2b9c09c4e 100644
--- a/src/AIModel/AIMultiplayer.cxx
+++ b/src/AIModel/AIMultiplayer.cxx
@@ -29,6 +29,7 @@
 
 #include "AIMultiplayer.hxx"
 
+using std::string;
 
 // #define SG_DEBUG SG_ALERT
 
diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx
index 0ec8f65f8..a202feb48 100644
--- a/src/AIModel/AIShip.cxx
+++ b/src/AIModel/AIShip.cxx
@@ -40,6 +40,7 @@
 
 #include "AIShip.hxx"
 
+using std::string;
 
 FGAIShip::FGAIShip(object_type ot) :
 // allow HOT to be enabled
diff --git a/src/AIModel/AIShip.hxx b/src/AIModel/AIShip.hxx
index 34038db90..009b735f5 100644
--- a/src/AIModel/AIShip.hxx
+++ b/src/AIModel/AIShip.hxx
@@ -52,9 +52,9 @@ public:
     void YawTo(double angle);
     void ClimbTo(double altitude);
     void TurnTo(double heading);
-    void setCurrName(const string&);
-    void setNextName(const string&);
-    void setPrevName(const string&);
+    void setCurrName(const std::string&);
+    void setNextName(const std::string&);
+    void setPrevName(const std::string&);
     void setLeadAngleGain(double g);
     void setLeadAngleLimit(double l);
     void setLeadAngleProp(double p);
@@ -99,8 +99,8 @@ private:
 
     void setServiceable(bool s);
     void Run(double dt);
-    void setStartTime(const string&);
-    void setUntilTime(const string&);
+    void setStartTime(const std::string&);
+    void setUntilTime(const std::string&);
     //void setWPPos();
     void setWPAlt();
     void setXTrackError();
@@ -110,7 +110,7 @@ private:
     double getRange(double lat, double lon, double lat2, double lon2) const;
     double getCourse(double lat, double lon, double lat2, double lon2) const;
     double getDaySeconds();
-    double processTimeString(const string& time);
+    double processTimeString(const std::string& time);
 
     bool initFlightPlan();
     bool advanceFlightPlan (double elapsed_sec, double day_sec);
@@ -129,9 +129,9 @@ private:
     double _xtrack_error;
     double _curr_alt, _prev_alt;
 
-    string _prev_name, _curr_name, _next_name;
-    string _path;
-    string _start_time, _until_time;
+    std::string _prev_name, _curr_name, _next_name;
+    std::string _path;
+    std::string _start_time, _until_time;
 
     bool _repeat;
     bool _fp_init;
diff --git a/src/AIModel/AITanker.cxx b/src/AIModel/AITanker.cxx
index 6ab43e034..73ec62538 100644
--- a/src/AIModel/AITanker.cxx
+++ b/src/AIModel/AITanker.cxx
@@ -25,6 +25,8 @@
 
 #include "AITanker.hxx"
 
+using std::string;
+
 FGAITanker::FGAITanker(FGAISchedule* ref): FGAIAircraft(ref){
 }
 
diff --git a/src/AIModel/AITanker.hxx b/src/AIModel/AITanker.hxx
index 8dcfe11ad..fcea6a28f 100644
--- a/src/AIModel/AITanker.hxx
+++ b/src/AIModel/AITanker.hxx
@@ -44,10 +44,10 @@ public:
 
     virtual const char* getTypeString(void) const { return "tanker"; }
 
-    void setTACANChannelID(const string& id);
+    void setTACANChannelID(const std::string& id);
     
 private:
-    string TACAN_channel_id;     // The TACAN channel of this tanker
+    std::string TACAN_channel_id;     // The TACAN channel of this tanker
     bool contact;                // set if this tanker is within fuelling range
 
     virtual void Run(double dt);
diff --git a/src/AIModel/submodel.cxx b/src/AIModel/submodel.cxx
index dac04da9d..b3721466a 100644
--- a/src/AIModel/submodel.cxx
+++ b/src/AIModel/submodel.cxx
@@ -25,6 +25,8 @@
 
 using std::cout;
 using std::endl;
+using std::string;
+using std::vector;
 
 const double FGSubmodelMgr::lbs_to_slugs = 0.031080950172;
 
diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx
index 4326af82a..416229ca7 100644
--- a/src/ATC/atc_mgr.cxx
+++ b/src/ATC/atc_mgr.cxx
@@ -32,6 +32,8 @@
 #include "atc_mgr.hxx"
 
 
+using std::string;
+
 FGATCManager::FGATCManager() {
     controller = 0;
     prevController = 0;
diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx
index 0c148d6d6..d189b917b 100644
--- a/src/Main/positioninit.cxx
+++ b/src/Main/positioninit.cxx
@@ -37,6 +37,7 @@
 #include <AIModel/AIManager.hxx>
 
 using std::endl;
+using std::string;
 
 namespace flightgear
 {