1
0
Fork 0

Performance optimization: empty() instead of size()>0

empty() is guaranteed to be constant complexity for both vectors and lists, while size() has linear complexity for lists.
This commit is contained in:
Tom Paoletti 2013-03-21 19:42:22 -07:00 committed by James Turner
parent 296555f26b
commit 81cd33e2fa
22 changed files with 77 additions and 76 deletions

View file

@ -65,7 +65,7 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
time_t newEta;
time_t separation = 90;
bool found = false;
if (estimatedArrivalTimes.size() == 0) {
if (estimatedArrivalTimes.empty()) {
estimatedArrivalTimes.push_back(eta);
return eta;
} else {
@ -191,7 +191,7 @@ void FGTrafficRecord::setPositionAndIntentions(int pos,
{
currentPos = pos;
if (intentions.size()) {
if (! intentions.empty()) {
intVecIterator i = intentions.begin();
if ((*i) != pos) {
SG_LOG(SG_ATC, SG_ALERT,
@ -223,7 +223,7 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other)
//cerr << callsign << ": Check Position and intentions: we are on the same taxiway" << other.callsign << "Index = " << currentPos << endl;
result = true;
}
// else if (other.intentions.size())
// else if (! other.intentions.empty())
// {
// cerr << "Start check 2" << endl;
// intVecIterator i = other.intentions.begin();
@ -233,7 +233,7 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other)
// cerr << "Check Position and intentions: current matches other.intentions" << endl;
// result = true;
// }
else if (intentions.size()) {
else if (! intentions.empty()) {
//cerr << "Start check 3" << endl;
intVecIterator i = intentions.begin();
//while (!((i == intentions.end()) || ((*i) == other.currentPos)))
@ -277,7 +277,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net,
otherTargetNode = net->findSegment(other.currentPos)->getEnd()->getIndex(); // OKAY,...
if ((currentTargetNode == otherTargetNode) && currentTargetNode > 0)
return currentTargetNode;
if (intentions.size()) {
if (! intentions.empty()) {
for (i = intentions.begin(); i != intentions.end(); i++) {
if ((*i) > 0) {
if (currentTargetNode ==
@ -288,7 +288,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net,
}
}
}
if (other.intentions.size()) {
if (! other.intentions.empty()) {
for (i = other.intentions.begin(); i != other.intentions.end();
i++) {
if ((*i) > 0) {
@ -300,7 +300,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net,
}
}
}
if (intentions.size() && other.intentions.size()) {
if (! intentions.empty() && ! other.intentions.empty()) {
for (i = intentions.begin(); i != intentions.end(); i++) {
for (j = other.intentions.begin(); j != other.intentions.end();
j++) {
@ -332,7 +332,7 @@ bool FGTrafficRecord::onRoute(FGGroundNetwork * net,
net->findSegment(other.currentPos)->getEnd()->getIndex();
if ((node == othernode) && (node != -1))
return true;
if (other.intentions.size()) {
if (! other.intentions.empty()) {
for (intVecIterator i = other.intentions.begin();
i != other.intentions.end(); i++) {
if (*i > 0) {
@ -344,7 +344,7 @@ bool FGTrafficRecord::onRoute(FGGroundNetwork * net,
}
//if (other.currentPos > 0)
// othernode = net->findSegment(other.currentPos)->getEnd()->getIndex();
//if (intentions.size())
//if (! intentions.empty())
// {
// for (intVecIterator i = intentions.begin(); i != intentions.end(); i++)
// {
@ -388,7 +388,7 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net,
}
}
}
if (other.intentions.size()) {
if (! other.intentions.empty()) {
for (intVecIterator j = other.intentions.begin();
j != other.intentions.end(); j++) {
// cerr << "Current segment 1 " << (*i) << endl;
@ -820,7 +820,7 @@ void FGTowerController::announcePosition(int id,
TrafficVectorIterator i = activeTraffic.begin();
// Search whether the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -830,7 +830,7 @@ void FGTowerController::announcePosition(int id,
}
}
// Add a new TrafficRecord if no one exsists for this aircraft.
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || (activeTraffic.empty())) {
FGTrafficRecord rec;
rec.setId(id);
@ -843,7 +843,7 @@ void FGTowerController::announcePosition(int id,
activeTraffic.push_back(rec);
// Don't just schedule the aircraft for the tower controller, also assign if to the correct active runway.
ActiveRunwayVecIterator rwy = activeRunways.begin();
if (activeRunways.size()) {
if (! activeRunways.empty()) {
while (rwy != activeRunways.end()) {
if (rwy->getRunwayName() == intendedRoute->getRunway()) {
break;
@ -874,7 +874,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
// Search whether the current id has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
TrafficVectorIterator current, closest;
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -884,7 +884,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
}
}
// // update position of the current aircraft
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || (activeTraffic.empty())) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
} else {
@ -957,7 +957,7 @@ void FGTowerController::signOff(int id)
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -968,7 +968,7 @@ void FGTowerController::signOff(int id)
}
// If this aircraft has left the runway, we can clear the departure record for this runway
ActiveRunwayVecIterator rwy = activeRunways.begin();
if (activeRunways.size()) {
if (! activeRunways.empty()) {
//while ((rwy->getRunwayName() != i->getRunway()) && (rwy != activeRunways.end())) {
while (rwy != activeRunways.end()) {
if (rwy->getRunwayName() == i->getRunway()) {
@ -984,7 +984,7 @@ void FGTowerController::signOff(int id)
"AI error: Attempting to erase non-existing runway clearance record in FGTowerController::signoff at " << SG_ORIGIN);
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || (activeTraffic.empty())) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
} else {
@ -1005,7 +1005,7 @@ bool FGTowerController::hasInstruction(int id)
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1014,7 +1014,7 @@ bool FGTowerController::hasInstruction(int id)
i++;
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
@ -1029,7 +1029,7 @@ FGATCInstruction FGTowerController::getInstruction(int id)
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1038,7 +1038,7 @@ FGATCInstruction FGTowerController::getInstruction(int id)
i++;
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
@ -1084,7 +1084,7 @@ void FGStartupController::announcePosition(int id,
TrafficVectorIterator i = activeTraffic.begin();
// Search whether the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1094,7 +1094,7 @@ void FGStartupController::announcePosition(int id,
}
}
// Add a new TrafficRecord if no one exsists for this aircraft.
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
FGTrafficRecord rec;
rec.setId(id);
@ -1124,7 +1124,7 @@ bool FGStartupController::hasInstruction(int id)
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1133,7 +1133,7 @@ bool FGStartupController::hasInstruction(int id)
i++;
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
@ -1148,7 +1148,7 @@ FGATCInstruction FGStartupController::getInstruction(int id)
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1157,7 +1157,7 @@ FGATCInstruction FGStartupController::getInstruction(int id)
i++;
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
@ -1171,7 +1171,7 @@ void FGStartupController::signOff(int id)
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1180,7 +1180,7 @@ void FGStartupController::signOff(int id)
i++;
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
} else {
@ -1230,7 +1230,7 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
// Search search if the current id has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
TrafficVectorIterator current, closest;
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1542,7 +1542,7 @@ void FGApproachController::announcePosition(int id,
TrafficVectorIterator i = activeTraffic.begin();
// Search whether the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1552,7 +1552,7 @@ void FGApproachController::announcePosition(int id,
}
}
// Add a new TrafficRecord if no one exsists for this aircraft.
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
FGTrafficRecord rec;
rec.setId(id);
@ -1575,7 +1575,7 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double
// Search search if the current id has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
TrafficVectorIterator current, closest;
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1585,7 +1585,7 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double
}
}
// // update position of the current aircraft
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
} else {
@ -1624,7 +1624,7 @@ void FGApproachController::signOff(int id)
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1633,7 +1633,7 @@ void FGApproachController::signOff(int id)
i++;
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from approach at " << SG_ORIGIN);
} else {
@ -1653,7 +1653,7 @@ bool FGApproachController::hasInstruction(int id)
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
if (activeTraffic.size()) {
if (! activeTraffic.empty()) {
//while ((i->getId() != id) && i != activeTraffic.end()) {
while (i != activeTraffic.end()) {
if (i->getId() == id) {
@ -1662,7 +1662,7 @@ bool FGApproachController::hasInstruction(int id)
i++;
}
}
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {

View file

@ -479,7 +479,7 @@ public:
virtual std::string getName();
virtual void update(double dt);
bool hasActiveTraffic() {
return activeTraffic.size() != 0;
return ! activeTraffic.empty();
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
@ -516,7 +516,7 @@ public:
virtual void update(double dt);
bool hasActiveTraffic() {
return activeTraffic.size() != 0;
return ! activeTraffic.empty();
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
@ -558,7 +558,7 @@ public:
ActiveRunway* getRunway(const std::string& name);
bool hasActiveTraffic() {
return activeTraffic.size() != 0;
return ! activeTraffic.empty();
};
TrafficVector &getActiveTraffic() {
return activeTraffic;

View file

@ -572,7 +572,7 @@ FGReplay::record(double time)
{
FGReplayData* r = NULL;
if (recycler.size())
if (! recycler.empty())
{
r = recycler.front();
recycler.pop_front();
@ -588,7 +588,7 @@ void
FGReplay::interpolate( double time, const replay_list_type &list)
{
// sanity checking
if ( list.size() == 0 )
if ( list.empty() )
{
// handle empty list
return;
@ -639,7 +639,7 @@ FGReplay::replay( double time ) {
replayMessage(time);
if ( short_term.size() > 0 ) {
if ( ! short_term.empty() ) {
t1 = short_term.back()->sim_time;
t2 = short_term.front()->sim_time;
if ( time > t1 ) {
@ -649,7 +649,7 @@ FGReplay::replay( double time ) {
return true;
} else if ( time <= t1 && time >= t2 ) {
interpolate( time, short_term );
} else if ( medium_term.size() > 0 ) {
} else if ( ! medium_term.empty() ) {
t1 = short_term.front()->sim_time;
t2 = medium_term.back()->sim_time;
if ( time <= t1 && time >= t2 )
@ -660,7 +660,7 @@ FGReplay::replay( double time ) {
t2 = medium_term.front()->sim_time;
if ( time <= t1 && time >= t2 ) {
interpolate( time, medium_term );
} else if ( long_term.size() > 0 ) {
} else if ( ! long_term.empty() ) {
t1 = medium_term.front()->sim_time;
t2 = long_term.back()->sim_time;
if ( time <= t1 && time >= t2 )
@ -704,13 +704,13 @@ FGReplay::replay(double time, FGReplayData* pCurrentFrame, FGReplayData* pOldFra
double
FGReplay::get_start_time()
{
if ( long_term.size() > 0 )
if ( ! long_term.empty() )
{
return long_term.front()->sim_time;
} else if ( medium_term.size() > 0 )
} else if ( ! medium_term.empty() )
{
return medium_term.front()->sim_time;
} else if ( short_term.size() )
} else if ( ! short_term.empty() )
{
return short_term.front()->sim_time;
} else
@ -722,7 +722,7 @@ FGReplay::get_start_time()
double
FGReplay::get_end_time()
{
if ( short_term.size() )
if ( ! short_term.empty() )
{
return short_term.back()->sim_time;
} else

View file

@ -366,7 +366,7 @@ private:
const string& rwy_no_1(token[8]);
const string& rwy_no_2(token[17]);
if ( rwy_no_1.size() == 0 || rwy_no_2.size() == 0 )
if ( rwy_no_1.empty() || rwy_no_2.empty() )
return;
double displ_thresh1 = atof( token[11].c_str() );

View file

@ -115,7 +115,7 @@ protected:
* values of &lt;min&gt; and/or &lt;max&gt;.
*/
inline double get_output_value() const {
return _output_list.size() == 0 ? 0.0 : clamp(_output_list[0]->getDoubleValue());
return _output_list.empty() ? 0.0 : clamp(_output_list[0]->getDoubleValue());
}
simgear::PropertyList _output_list;
@ -140,7 +140,7 @@ public:
inline void AnalogComponent::disabled( double dt )
{
if( _feedback_if_disabled && _output_list.size() > 0 ) {
if( _feedback_if_disabled && ! _output_list.empty() ) {
InputValue * input;
if( (input = _valueInput.get_active() ) != NULL )
input->set_value( _output_list[0]->getDoubleValue() );

View file

@ -169,7 +169,7 @@ const FGCommonInput::binding_list_t & FGKeyboardInput::_find_key_bindings (unsig
FGButton &b = bindings[k];
// Try it straight, first.
if (b.bindings[modifiers].size() > 0)
if (! b.bindings[modifiers].empty())
return b.bindings[modifiers];
// Alt-Gr is CTRL+ALT

View file

@ -185,7 +185,7 @@ void HUD::draw(osg::State&)
if (!isVisible())
return;
if (!_items.size() && !_ladders.size())
if (_items.empty() && _ladders.empty())
return;
if (is3D()) {
@ -321,7 +321,7 @@ void HUD::common_draw()
_text_list.draw();
_line_list.draw();
if (_stipple_line_list.size()) {
if (! _stipple_line_list.empty()) {
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0x00FF);
_stipple_line_list.draw();

View file

@ -61,6 +61,7 @@ public:
void add(const LineSegment& seg) { _list.push_back(seg); }
void erase() { _list.erase(_list.begin(), _list.end()); }
inline unsigned int size() const { return _list.size(); }
inline bool empty() const { return _list.empty(); }
void draw() {
glBegin(GL_LINES);
std::vector<LineSegment>::const_iterator it, end = _list.end();

View file

@ -587,7 +587,7 @@ void KLN89::DtoPressed() {
} else {
_dir_page->SetId(_activeWaypoint.id);
}
} else if(_curPage == 6 && _activePage->GetSubPage() == 3 && fgGetBool("/instrumentation/kln89/scan-pull") && _activeFP->waypoints.size()) {
} else if(_curPage == 6 && _activePage->GetSubPage() == 3 && fgGetBool("/instrumentation/kln89/scan-pull") && ! _activeFP->waypoints.empty()) {
// NAV 4
_dir_page->SetId(((KLN89NavPage*)_activePage)->GetNav4WpId());
} else if(_curPage == 7 && _activePage->GetSubPage() == 0 && _mode == KLN89_MODE_CRSR) {
@ -658,7 +658,7 @@ void KLN89::MsgPressed() {
// TODO - handle persistent messages such as SUA alerting.
// (The message annunciation flashes before first view, but afterwards remains continuously lit with the message available
// until the potential conflict no longer pertains).
if(_dispMsg && _messageStack.size()) {
if(_dispMsg && ! _messageStack.empty()) {
_messageStack.pop_front();
}
_dispMsg = !_dispMsg;

View file

@ -97,7 +97,7 @@ typedef gps_waypoint_map::const_iterator gps_waypoint_map_const_iterator;
class GPSFlightPlan {
public:
std::vector<GPSWaypoint*> waypoints;
inline bool IsEmpty() { return(waypoints.size() == 0); }
inline bool IsEmpty() { return waypoints.empty(); }
};
// TODO - probably de-public the internals of the next 2 classes and add some methods!

View file

@ -977,7 +977,7 @@ MK_VIII::IOHandler::TerrainClearanceFilter::update (double agl)
// calculate average
double new_value = 0;
if (samples.size() > 0)
if (! samples.empty())
{
// time consuming loop => queue limited to 75 samples
// (= 15seconds * 5samples/second)

View file

@ -904,7 +904,7 @@ NavRadioImpl::~NavRadioImpl()
void NavRadioImpl::init()
{
if( 0 < _components.size() )
if( ! _components.empty() )
return;
_components.push_back( new VOR(_rootNode) );

View file

@ -313,14 +313,14 @@ FGLocale::getLocalizedStrings(const char* id, const char* resource)
if (_currentLocale)
{
simgear::PropertyList s = getLocalizedStrings(_currentLocale, id, resource);
if (s.size())
if (! s.empty())
return s;
}
if (_defaultLocale)
{
simgear::PropertyList s = getLocalizedStrings(_defaultLocale, id, resource);
if (s.size())
if (! s.empty())
return s;
}
}

View file

@ -50,13 +50,13 @@ FGLogger::init ()
Log &log = _logs[_logs.size()-1];
string filename = child->getStringValue("filename");
if (filename.size() == 0) {
if (filename.empty()) {
filename = "fg_log.csv";
child->setStringValue("filename", filename.c_str());
}
string delimiter = child->getStringValue("delimiter");
if (delimiter.size() == 0) {
if (delimiter.empty()) {
delimiter = ",";
child->setStringValue("delimiter", delimiter.c_str());
}

View file

@ -330,7 +330,7 @@ void printReport(SGMetar *m)
surface.push_back(buf);
}
if (surface.size()) {
if (! surface.empty()) {
vector<string>::iterator rwysurf = surface.begin();
for (i = 0; rwysurf != surface.end(); rwysurf++, i++) {
if (i)

View file

@ -1775,7 +1775,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
setupRoot();
// system.fgfsrc handling
if( hostname.size() > 0 ) {
if( ! hostname.empty() ) {
config.set(globals->get_fg_root());
config.append( "system.fgfsrc" );
config.concat( "." );
@ -2160,7 +2160,7 @@ void Options::showUsage() const
vector<SGPropertyNode_ptr> desc;
desc = option[k]->getChildren("description");
if (desc.size() > 0) {
if (! desc.empty()) {
for ( unsigned int l = 0; l < desc.size(); l++) {
string t = desc[l]->getStringValue();

View file

@ -329,7 +329,7 @@ static bool fgSetPosFromNAV( const string& id, const double& freq, FGPositioned:
FGNavList::TypeFilter filter(type);
const nav_list_type navlist = FGNavList::findByIdentAndFreq( id.c_str(), freq, &filter );
if (navlist.size() == 0 ) {
if (navlist.empty()) {
SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
<< id << ":" << freq );
return false;

View file

@ -209,7 +209,7 @@ do_reinit (const SGPropertyNode * arg)
bool result = true;
vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
if (subsystems.size() == 0) {
if (subsystems.empty()) {
globals->get_subsystem_mgr()->reinit();
} else {
for ( unsigned int i = 0; i < subsystems.size(); i++ ) {

View file

@ -567,7 +567,7 @@ FGGeneric::reinit()
// bad configuration
return;
}
if (!binary_mode && (line_separator.size() == 0 ||
if (!binary_mode && (line_separator.empty() ||
*line_separator.rbegin() != '\n')) {
SG_LOG(SG_IO, SG_WARN,

View file

@ -50,7 +50,7 @@ FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const std::string &refname ) :
FGSampleQueue::~FGSampleQueue ()
{
while ( _messages.size() > 0 ) {
while ( ! _messages.empty() ) {
delete _messages.front();
_messages.pop();
}
@ -92,7 +92,7 @@ FGSampleQueue::update (double dt)
if ( !now_playing ) {
// message queue idle, add next sound if we have one
if ( _messages.size() > 0 ) {
if ( ! _messages.empty() ) {
SGSampleGroup::add( _messages.front(), msgid );
_messages.pop();
play_once( msgid );

View file

@ -545,7 +545,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string &currentDesti
continue;
}
}
if (flights.size()) {
if (! flights.empty()) {
time_t arrival = flights.back()->getArrivalTime();
int groundTime = groundTimeFromRadius();
if ((*i)->getDepartureTime() < (arrival+(groundTime)))

View file

@ -350,7 +350,7 @@ void fgOSFullScreen()
std::vector<osgViewer::GraphicsWindow*> windows;
viewer->getWindows(windows);
if (windows.size() == 0)
if (windows.empty())
return; // Huh?!?
/* Toggling window fullscreen is only supported for the main GUI window.