1
0
Fork 0

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.
This commit is contained in:
ehofman 2005-10-26 09:03:49 +00:00
parent 2b471a165f
commit b24dbb3f8b
23 changed files with 83 additions and 84 deletions

View file

@ -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);

View file

@ -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,

View file

@ -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;

View file

@ -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 <waypoint*> 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

View file

@ -397,7 +397,7 @@ void FGAIManager::processThermal( FGAIThermal* thermal ) {
void FGAIManager::processScenario( const string &filename ) {
FGAIScenario* s = new FGAIScenario( filename );
for (int i=0;i<s->nEntries();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())

View file

@ -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<FGModelID> ModelVec;
typedef vector<FGModelID>::iterator ModelVecIterator;
typedef vector<FGModelID>::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 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 ) {
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,

View file

@ -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<ParkPosition> retval;
vector<SGPropertyNode_ptr>::iterator it;
vector<SGPropertyNode_ptr>::const_iterator it;
vector<SGPropertyNode_ptr> children = entry_node->getChildren(name);
for (it = children.begin(); it != children.end(); ++it) {
string name = (*it)->getStringValue("name", "unnamed");

View file

@ -37,13 +37,13 @@ public:
FGAIScenario(const string &filename);
~FGAIScenario();
FGAIModelEntity* getNextEntry( void );
FGAIModelEntity* const getNextEntry( void );
int nEntries( void );
private:
typedef vector <FGAIModelEntity*> 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;

View file

@ -89,7 +89,7 @@ public:
private:
typedef vector <submodel*> 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;

View file

@ -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);

View file

@ -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);

View file

@ -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)

View file

@ -640,7 +640,7 @@ FGMetarEnvironmentCtrl::update_metar_properties( const FGMetar *m )
m->getPressure_inHg() );
vector<SGMetarCloud> cv = m->getClouds();
vector<SGMetarCloud>::iterator cloud;
vector<SGMetarCloud>::const_iterator cloud;
const char *cl = "/environment/clouds/layer[%i]";
for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {

View file

@ -306,7 +306,7 @@ FGClouds::update_metar_properties( FGMetar *m )
m->getPressure_inHg() );
vector<SGMetarCloud> cv = m->getClouds();
vector<SGMetarCloud>::iterator cloud;
vector<SGMetarCloud>::const_iterator cloud;
const char *cl = "/environment/clouds/layer[%i]";
for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {

View file

@ -128,7 +128,7 @@ FGMetar::FGMetar(const string& icao, const string& proxy, const string& port, co
// snow cover
map<string, SGMetarRunway> rm = getRunways();
map<string, SGMetarRunway>::iterator runway;
map<string, SGMetarRunway>::const_iterator runway;
for (runway = rm.begin(); runway != rm.end(); runway++) {
SGMetarRunway rwy = runway->second;
if (rwy.getDeposit() >= 3 ) {

View file

@ -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(" ");

View file

@ -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,

View file

@ -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& );
};

View file

@ -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; }

View file

@ -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;
}

View file

@ -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; }

View file

@ -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 )

View file

@ -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 );