From: ehofman Date: Wed, 26 Oct 2005 09:03:49 +0000 (+0000) Subject: Alex Romosan: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b24dbb3f8b0ebb53321a64be2f86dbb5f244833c;p=flightgear.git Alex Romosan: I tried to make sure accessor functions which return by reference act on const objects. also replaced some iterators with const_iterator and a few return/pass by reference that were missed the first time around. --- diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 022572563..9417fb5d1 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -61,7 +61,7 @@ public: void SetPerformance(const PERF_STRUCT *ps); void SetFlightPlan(FGAIFlightPlan *f); - FGAIFlightPlan* GetFlightPlan() { return fp; }; + FGAIFlightPlan* GetFlightPlan() const { return fp; }; void AccelTo(double speed); void PitchTo(double angle); void RollTo(double angle); diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 4f1713059..584e73714 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -108,7 +108,7 @@ public: FGAIBase(); virtual ~FGAIBase(); virtual void update(double dt); - inline Point3D GetPos() { return(pos); } + inline const Point3D& GetPos() const { return(pos); } enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic, otRocket, otStorm, otThermal, otStatic, diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index 39ca074d8..db4061b13 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -295,8 +295,8 @@ FGAIFlightPlan::~FGAIFlightPlan() } -FGAIFlightPlan::waypoint* -FGAIFlightPlan::getPreviousWaypoint( void ) +FGAIFlightPlan::waypoint* const +FGAIFlightPlan::getPreviousWaypoint( void ) const { if (wpt_iterator == waypoints.begin()) { return 0; @@ -306,14 +306,14 @@ FGAIFlightPlan::getPreviousWaypoint( void ) } } -FGAIFlightPlan::waypoint* -FGAIFlightPlan::getCurrentWaypoint( void ) +FGAIFlightPlan::waypoint* const +FGAIFlightPlan::getCurrentWaypoint( void ) const { return *wpt_iterator; } -FGAIFlightPlan::waypoint* -FGAIFlightPlan::getNextWaypoint( void ) +FGAIFlightPlan::waypoint* const +FGAIFlightPlan::getNextWaypoint( void ) const { wpt_vector_iterator i = waypoints.end(); i--; // end() points to one element after the last one. @@ -344,7 +344,7 @@ void FGAIFlightPlan::IncrementWaypoint(bool eraseWaypoints ) } // gives distance in feet from a position to a waypoint -double FGAIFlightPlan::getDistanceToGo(double lat, double lon, waypoint* wp){ +double FGAIFlightPlan::getDistanceToGo(double lat, double lon, waypoint* wp) const{ // get size of a degree2 at the present latitude // this won't work over large distances double ft_per_deg_lat = 366468.96 - 3717.12 * cos(lat / SG_RADIANS_TO_DEGREES); @@ -386,12 +386,12 @@ void FGAIFlightPlan::setLeadDistance(double distance_ft){ } -double FGAIFlightPlan::getBearing(waypoint* first, waypoint* second){ +double FGAIFlightPlan::getBearing(waypoint* first, waypoint* second) const{ return getBearing(first->latitude, first->longitude, second); } -double FGAIFlightPlan::getBearing(double lat, double lon, waypoint* wp){ +double FGAIFlightPlan::getBearing(double lat, double lon, waypoint* wp) const{ double course, distance; // double latd = lat; // double lond = lon; diff --git a/src/AIModel/AIFlightPlan.hxx b/src/AIModel/AIFlightPlan.hxx index 3c6ed9bca..17a5d1c27 100644 --- a/src/AIModel/AIFlightPlan.hxx +++ b/src/AIModel/AIFlightPlan.hxx @@ -62,37 +62,37 @@ public: const string& airline); ~FGAIFlightPlan(); - waypoint* getPreviousWaypoint( void ); - waypoint* getCurrentWaypoint( void ); - waypoint* getNextWaypoint( void ); + waypoint* const getPreviousWaypoint( void ) const; + waypoint* const getCurrentWaypoint( void ) const; + waypoint* const getNextWaypoint( void ) const; void IncrementWaypoint( bool erase ); - double getDistanceToGo(double lat, double lon, waypoint* wp); - int getLeg () { return leg;}; + double getDistanceToGo(double lat, double lon, waypoint* wp) const; + int getLeg () const { return leg;}; void setLeadDistance(double speed, double bearing, waypoint* current, waypoint* next); void setLeadDistance(double distance_ft); double getLeadDistance( void ) const {return lead_distance;} - double getBearing(waypoint* previous, waypoint* next); - double getBearing(double lat, double lon, waypoint* next); - time_t getStartTime() { return start_time; }; + double getBearing(waypoint* previous, waypoint* next) const; + double getBearing(double lat, double lon, waypoint* next) const; + time_t getStartTime() const { return start_time; }; void create(FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon, bool firstLeg, double radius, const string& fltType, const string& aircraftType, const string& airline); void setLeg(int val) { leg = val;}; void setTime(time_t st) { start_time = st; }; - int getGate() { return gateId; }; - double getLeadInAngle() { return leadInAngle; }; - const string& getRunway() { return rwy._rwy_no; }; - const string& getRunwayId() { return rwy._id; }; + int getGate() const { return gateId; }; + double getLeadInAngle() const { return leadInAngle; }; + const string& getRunway() const { return rwy._rwy_no; }; + const string& getRunwayId() const { return rwy._id; }; void setRepeat(bool r) { repeat = r; }; - bool getRepeat(void) { return repeat; }; + bool getRepeat(void) const { return repeat; }; void restart(void); private: FGRunway rwy; typedef vector wpt_vector_type; - typedef wpt_vector_type::iterator wpt_vector_iterator; + typedef wpt_vector_type::const_iterator wpt_vector_iterator; wpt_vector_type waypoints; wpt_vector_iterator wpt_iterator; @@ -121,4 +121,3 @@ private: #endif // _FG_AIFLIGHTPLAN_HXX - diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 96742864e..8b7154059 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -397,7 +397,7 @@ void FGAIManager::processThermal( FGAIThermal* thermal ) { void FGAIManager::processScenario( const string &filename ) { FGAIScenario* s = new FGAIScenario( filename ); for (int i=0;inEntries();i++) { - FGAIModelEntity* en = s->getNextEntry(); + FGAIModelEntity* const en = s->getNextEntry(); if (en) { if ( en->m_type == "aircraft") { @@ -430,7 +430,7 @@ void FGAIManager::processScenario( const string &filename ) { // This code keeps track of models that have already been loaded // Eventually we'd prbably need to find a way to keep track of models // that are unloaded again -ssgBranch * FGAIManager::getModel(const string& path) +ssgBranch * FGAIManager::getModel(const string& path) const { ModelVecIterator i = loadedModels.begin(); while (i != loadedModels.end()) diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index 86eaab9a1..66c89a2f4 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -46,12 +46,12 @@ private: string path; public: FGModelID(const string& pth, ssgBranch * mdl) { path =pth; model=mdl;}; - ssgBranch *getModelId() { return model;}; - const string & getPath() { return path;}; + ssgBranch * const getModelId() const { return model;}; + const string & getPath() const { return path;}; }; typedef vector ModelVec; -typedef vector::iterator ModelVecIterator; +typedef vector::const_iterator ModelVecIterator; class FGAIThermal; @@ -92,23 +92,23 @@ public: void destroyObject( int ID ); - inline double get_user_latitude() { return user_latitude; } - inline double get_user_longitude() { return user_longitude; } - inline double get_user_altitude() { return user_altitude; } - inline double get_user_heading() { return user_heading; } - inline double get_user_pitch() { return user_pitch; } - inline double get_user_yaw() { return user_yaw; } - inline double get_user_speed() {return user_speed; } - inline double get_wind_from_east() {return wind_from_east; } - inline double get_wind_from_north() {return wind_from_north; } - - inline int getNum( FGAIBase::object_type ot ) { + inline double get_user_latitude() const { return user_latitude; } + inline double get_user_longitude() const { return user_longitude; } + inline double get_user_altitude() const { return user_altitude; } + inline double get_user_heading() const { return user_heading; } + inline double get_user_pitch() const { return user_pitch; } + inline double get_user_yaw() const { return user_yaw; } + inline double get_user_speed() const {return user_speed; } + inline double get_wind_from_east() const {return wind_from_east; } + inline double get_wind_from_north() const {return wind_from_north; } + + inline int getNum( FGAIBase::object_type ot ) const { return (0 < ot && ot < FGAIBase::MAX_OBJECTS) ? numObjects[ot] : numObjects[0]; } void processScenario( const string &filename ); - ssgBranch * getModel(const string& path); + ssgBranch * getModel(const string& path) const; void setModel(const string& path, ssgBranch *model); static bool getStartPosition(const string& id, const string& pid, diff --git a/src/AIModel/AIScenario.cxx b/src/AIModel/AIScenario.cxx index 4491308fe..97a60fd4c 100644 --- a/src/AIModel/AIScenario.cxx +++ b/src/AIModel/AIScenario.cxx @@ -131,7 +131,7 @@ FGAIScenario::~FGAIScenario() } -FGAIModelEntity* +FGAIModelEntity* const FGAIScenario::getNextEntry( void ) { if (entries.size() == 0) return 0; @@ -171,7 +171,7 @@ getAllOffsetNodeVals(const char* name, SGPropertyNode * entry_node) { list retval; - vector::iterator it; + vector::const_iterator it; vector children = entry_node->getChildren(name); for (it = children.begin(); it != children.end(); ++it) { string name = (*it)->getStringValue("name", "unnamed"); diff --git a/src/AIModel/AIScenario.hxx b/src/AIModel/AIScenario.hxx index a6b46ccc2..992f30bb1 100644 --- a/src/AIModel/AIScenario.hxx +++ b/src/AIModel/AIScenario.hxx @@ -37,13 +37,13 @@ public: FGAIScenario(const string &filename); ~FGAIScenario(); - FGAIModelEntity* getNextEntry( void ); + FGAIModelEntity* const getNextEntry( void ); int nEntries( void ); private: typedef vector entry_vector_type; - typedef entry_vector_type::iterator entry_vector_iterator; + typedef entry_vector_type::const_iterator entry_vector_iterator; entry_vector_type entries; entry_vector_iterator entry_iterator; diff --git a/src/AIModel/submodel.hxx b/src/AIModel/submodel.hxx index 7c733d48e..143f8b74e 100644 --- a/src/AIModel/submodel.hxx +++ b/src/AIModel/submodel.hxx @@ -89,7 +89,7 @@ public: private: typedef vector submodel_vector_type; - typedef submodel_vector_type::iterator submodel_vector_iterator; + typedef submodel_vector_type::const_iterator submodel_vector_iterator; submodel_vector_type submodels; submodel_vector_iterator submodel_iterator; diff --git a/src/ATC/AIGAVFRTraffic.cxx b/src/ATC/AIGAVFRTraffic.cxx index 771e6013d..72c7685a5 100644 --- a/src/ATC/AIGAVFRTraffic.cxx +++ b/src/ATC/AIGAVFRTraffic.cxx @@ -72,7 +72,7 @@ FGAIGAVFRTraffic::~FGAIGAVFRTraffic() { // Init en-route to destID at point pt. // TODO - no idea what to do if pt is above planes ceiling due mountains!! -bool FGAIGAVFRTraffic::Init(Point3D pt, string destID, const string& callsign) { +bool FGAIGAVFRTraffic::Init(const Point3D& pt, const string& destID, const string& callsign) { FGAILocalTraffic::Init(callsign, destID, EN_ROUTE); // TODO FIXME - to get up and running we're going to ignore elev and get FGAIMgr to // pass in known good values for the test location. Need to fix this!!! (or at least canonically decide who has responsibility for setting elev). @@ -101,7 +101,7 @@ bool FGAIGAVFRTraffic::Init(Point3D pt, string destID, const string& callsign) { } // Init at srcID to fly to destID -bool FGAIGAVFRTraffic::Init(string srcID, string destID, const string& callsign, OperatingState state) { +bool FGAIGAVFRTraffic::Init(const string& srcID, const string& destID, const string& callsign, OperatingState state) { _enroute = false; FGAILocalTraffic::Init(callsign, srcID, PARKED); return(true); diff --git a/src/ATC/AIGAVFRTraffic.hxx b/src/ATC/AIGAVFRTraffic.hxx index c094f60a4..48c9ce940 100644 --- a/src/ATC/AIGAVFRTraffic.hxx +++ b/src/ATC/AIGAVFRTraffic.hxx @@ -42,9 +42,9 @@ public: ~FGAIGAVFRTraffic(); // Init en-route to destID at point pt. (lat, lon, elev) (elev in meters, lat and lon in degrees). - bool Init(Point3D pt, string destID, const string& callsign); + bool Init(const Point3D& pt, const string& destID, const string& callsign); // Init at srcID to fly to destID - bool Init(string srcID, string destID, const string& callsign, OperatingState state = PARKED); + bool Init(const string& srcID, const string& destID, const string& callsign, OperatingState state = PARKED); // Run the internal calculations void Update(double dt); diff --git a/src/ATC/tower.hxx b/src/ATC/tower.hxx index de0bf632f..69fce9ef9 100644 --- a/src/ATC/tower.hxx +++ b/src/ATC/tower.hxx @@ -162,14 +162,14 @@ public: // Public interface to the active runway - this will get more complex // in the future and consider multi-runway use, airplane weight etc. - inline const string& GetActiveRunway() { return activeRwy; } - inline const RunwayDetails& GetActiveRunwayDetails() { return rwy; } + inline const string& GetActiveRunway() const { return activeRwy; } + inline const RunwayDetails& GetActiveRunwayDetails() const { return rwy; } // Get the pattern direction of the active rwy. - inline int GetPatternDirection() { return rwy.patternDirection; } + inline int GetPatternDirection() const { return rwy.patternDirection; } - inline const string& get_trans_ident() { return trans_ident; } + inline const string& get_trans_ident() const { return trans_ident; } - inline FGGround* GetGroundPtr() { return ground; } + inline FGGround* const GetGroundPtr() const { return ground; } // Returns true if positions of crosswind/downwind/base leg turns should be constrained by previous traffic // plus the constraint position as a rwy orientated orthopos (meters) diff --git a/src/Environment/environment_ctrl.cxx b/src/Environment/environment_ctrl.cxx index 361ca423c..5625cd666 100644 --- a/src/Environment/environment_ctrl.cxx +++ b/src/Environment/environment_ctrl.cxx @@ -640,7 +640,7 @@ FGMetarEnvironmentCtrl::update_metar_properties( const FGMetar *m ) m->getPressure_inHg() ); vector cv = m->getClouds(); - vector::iterator cloud; + vector::const_iterator cloud; const char *cl = "/environment/clouds/layer[%i]"; for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) { diff --git a/src/Environment/fgclouds.cxx b/src/Environment/fgclouds.cxx index 9a5b51236..b3964c296 100644 --- a/src/Environment/fgclouds.cxx +++ b/src/Environment/fgclouds.cxx @@ -306,7 +306,7 @@ FGClouds::update_metar_properties( FGMetar *m ) m->getPressure_inHg() ); vector cv = m->getClouds(); - vector::iterator cloud; + vector::const_iterator cloud; const char *cl = "/environment/clouds/layer[%i]"; for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) { diff --git a/src/Environment/fgmetar.cxx b/src/Environment/fgmetar.cxx index 0f71c8e4b..acb5d5745 100644 --- a/src/Environment/fgmetar.cxx +++ b/src/Environment/fgmetar.cxx @@ -128,7 +128,7 @@ FGMetar::FGMetar(const string& icao, const string& proxy, const string& port, co // snow cover map rm = getRunways(); - map::iterator runway; + map::const_iterator runway; for (runway = rm.begin(); runway != rm.end(); runway++) { SGMetarRunway rwy = runway->second; if (rwy.getDeposit() >= 3 ) { diff --git a/src/Navaids/navdb.cxx b/src/Navaids/navdb.cxx index b9d5afc09..60aac0c3e 100644 --- a/src/Navaids/navdb.cxx +++ b/src/Navaids/navdb.cxx @@ -291,10 +291,10 @@ void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist, double threshold ) { nav_map_type navmap = loclist->get_navaids(); - nav_map_iterator freq = navmap.begin(); + nav_map_const_iterator freq = navmap.begin(); while ( freq != navmap.end() ) { nav_list_type locs = freq->second; - nav_list_iterator loc = locs.begin(); + nav_list_const_iterator loc = locs.begin(); while ( loc != locs.end() ) { string name = (*loc)->get_name(); string::size_type pos1 = name.find(" "); diff --git a/src/Navaids/navlist.cxx b/src/Navaids/navlist.cxx index 4b866580f..4b058e725 100644 --- a/src/Navaids/navlist.cxx +++ b/src/Navaids/navlist.cxx @@ -296,8 +296,8 @@ FGNavRecord *FGNavList::findClosest( double lon_rad, double lat_rad, // cout << "Master index = " << master_index << endl; // cout << "beacon search length = " << beacons.size() << endl; - nav_list_iterator current = navs.begin(); - nav_list_iterator last = navs.end(); + nav_list_const_iterator current = navs.begin(); + nav_list_const_iterator last = navs.end(); Point3D aircraft = sgGeodToCart( Point3D(lon_rad, lat_rad, diff --git a/src/Navaids/navrecord.hxx b/src/Navaids/navrecord.hxx index 34d3a579b..8b950abc5 100644 --- a/src/Navaids/navrecord.hxx +++ b/src/Navaids/navrecord.hxx @@ -88,11 +88,11 @@ public: inline int get_range() const { return range; } inline double get_multiuse() const { return multiuse; } inline void set_multiuse( double m ) { multiuse = m; } - inline const char *get_ident() { return ident.c_str(); } - inline string get_name() { return name; } - inline string get_apt_id() { return apt_id; } - inline bool get_serviceable() { return serviceable; } - inline const char *get_trans_ident() { return trans_ident.c_str(); } + inline const char *get_ident() const { return ident.c_str(); } + inline const string& get_name() const { return name; } + inline const string& get_apt_id() const { return apt_id; } + inline bool get_serviceable() const { return serviceable; } + inline const char *get_trans_ident() const { return trans_ident.c_str(); } friend istream& operator>> ( istream&, FGNavRecord& ); }; @@ -182,7 +182,7 @@ public: inline FGTACANRecord(void); inline ~FGTACANRecord(void) {} - inline string get_channel() { return channel; } + inline const string& get_channel() const { return channel; } inline int get_freq() const { return freq; } friend istream& operator>> ( istream&, FGTACANRecord& ); }; diff --git a/src/Objects/ssgEntityArray.hxx b/src/Objects/ssgEntityArray.hxx index 22612a4bd..659d6d6c5 100644 --- a/src/Objects/ssgEntityArray.hxx +++ b/src/Objects/ssgEntityArray.hxx @@ -32,18 +32,18 @@ public: ssgEntityArray (void) ; virtual ~ssgEntityArray (void) ; - ssgEntity *getModel () { return model ; } + ssgEntity *getModel () const { return model ; } void setModel ( ssgEntity *entity ) { model = entity; } void removeModel () ; void replaceModel ( ssgEntity *new_entity ) ; - ssgVertexArray *getLocations () { return locations; } - ssgVertexArray *getOrientations () { return orientations; } + ssgVertexArray *getLocations () const { return locations; } + ssgVertexArray *getOrientations () const { return orientations; } - float *getLocation ( int i ) { return locations->get( i ); } - float *getOrientation ( int i ) { return orientations->get( i ); } + float *getLocation ( int i ) const { return locations->get( i ); } + float *getOrientation ( int i ) const { return orientations->get( i ); } void addPlacement ( sgVec3 loc, sgVec3 orient ); - virtual int getNumPlacements() { return locations->getNum(); } + virtual int getNumPlacements() const { return locations->getNum(); } void removeAllPlacements(); ssgTransform *getPosTransform() { return pos; } diff --git a/src/Scenery/newcache.hxx b/src/Scenery/newcache.hxx index de0db296d..7f2b8cceb 100644 --- a/src/Scenery/newcache.hxx +++ b/src/Scenery/newcache.hxx @@ -97,8 +97,8 @@ public: void clear_cache(); // Return a pointer to the specified tile cache entry - inline FGTileEntry *get_tile( const long tile_index ) { - tile_map_iterator it = tile_cache.find( tile_index ); + inline FGTileEntry *get_tile( const long tile_index ) const { + const_tile_map_iterator it = tile_cache.find( tile_index ); if ( it != tile_cache.end() ) { it->second->set_timestamp(globals->get_sim_time_sec()); return it->second; @@ -108,7 +108,7 @@ public: } // Return a pointer to the specified tile cache entry - inline FGTileEntry *get_tile( const SGBucket& b ) { + inline FGTileEntry *get_tile( const SGBucket& b ) const { return get_tile( b.gen_index() ); } @@ -118,7 +118,7 @@ public: // External linear traversal of cache inline void reset_traversal() { current = tile_cache.begin(); } inline bool at_end() { return current == tile_cache.end(); } - inline FGTileEntry *get_current() { + inline FGTileEntry *get_current() const { // cout << "index = " << current->first << endl; return current->second; } diff --git a/src/Scenery/tileentry.hxx b/src/Scenery/tileentry.hxx index 51d3d34d0..e7f6fd3b2 100644 --- a/src/Scenery/tileentry.hxx +++ b/src/Scenery/tileentry.hxx @@ -274,7 +274,7 @@ public: /** * return the SSG Transform node for the terrain */ - inline ssgPlacementTransform *get_terra_transform() { return terra_transform; } + inline ssgPlacementTransform *get_terra_transform() const { return terra_transform; } inline double get_timestamp() const { return timestamp; } inline void set_timestamp( double time_ms ) { timestamp = time_ms; } diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index fd986a0ec..af7195b44 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -156,7 +156,7 @@ void FGTileMgr::sched_tile( const SGBucket& b, const bool is_inner_ring ) { // schedule a needed buckets for loading -void FGTileMgr::schedule_needed( double vis, SGBucket curr_bucket) { +void FGTileMgr::schedule_needed( double vis, const SGBucket& curr_bucket) { // sanity check (unfortunately needed!) if ( longitude < -180.0 || longitude > 180.0 || latitude < -90.0 || latitude > 90.0 ) diff --git a/src/Scenery/tilemgr.hxx b/src/Scenery/tilemgr.hxx index a487264da..18af47d94 100644 --- a/src/Scenery/tilemgr.hxx +++ b/src/Scenery/tilemgr.hxx @@ -80,7 +80,7 @@ private: void sched_tile( const SGBucket& b, const bool is_inner_ring ); // schedule a needed buckets for loading - void schedule_needed(double visibility_meters, SGBucket curr_bucket); + void schedule_needed(double visibility_meters, const SGBucket& curr_bucket); FGHitList hit_list; @@ -178,8 +178,8 @@ public: // tiles... void refresh_view_timestamps(); - inline SGBucket get_current_bucket () { return current_bucket; } - inline SGBucket get_previous_bucket () { return previous_bucket; } + inline const SGBucket& get_current_bucket () const { return current_bucket; } + inline const SGBucket& get_previous_bucket () const { return previous_bucket; } static bool set_tile_filter( bool f ); static int tile_filter_cb( ssgEntity *, int );