[Positioner] Test pointers as booleans

This commit is contained in:
Matteo Cypriani 2014-05-13 17:29:08 -04:00
parent ec8c1244cd
commit 92db007d6b
19 changed files with 33 additions and 33 deletions

View File

@ -61,7 +61,7 @@ Building::~Building()
*/ */
void Building::add_area(const Area *const area) void Building::add_area(const Area *const area)
{ {
if (area == NULL) if (!area)
return ; return ;
string area_name = area->get_name() ; string area_name = area->get_name() ;

View File

@ -112,7 +112,7 @@ inline void Building::set_name(const std::string &_name)
*/ */
inline void Building::add_waypoint(Waypoint *const wp) inline void Building::add_waypoint(Waypoint *const wp)
{ {
if (wp != NULL) if (wp)
waypoints.insert(wp) ; waypoints.insert(wp) ;
} }

View File

@ -126,7 +126,7 @@ public:
PosUtil::hash_combine(seed, static_cast<Request>(source)) ; PosUtil::hash_combine(seed, static_cast<Request>(source)) ;
PosUtil::hash_combine(seed, source.get_direction()) ; PosUtil::hash_combine(seed, source.get_direction()) ;
if (source.get_reference_point() != NULL) if (source.get_reference_point())
PosUtil::hash_combine(seed, *source.get_reference_point()) ; PosUtil::hash_combine(seed, *source.get_reference_point()) ;
return seed ; return seed ;

View File

@ -147,7 +147,7 @@ const Request& Input::get_next_request() const
/* If the request is a calibration request, add it to the Stock */ /* If the request is a calibration request, add it to the Stock */
CalibrationRequest *calibration_request = CalibrationRequest *calibration_request =
dynamic_cast<CalibrationRequest*>(const_cast<Request*>(&request)) ; dynamic_cast<CalibrationRequest*>(const_cast<Request*>(&request)) ;
if (calibration_request != NULL) if (calibration_request)
{ {
if (Configuration::bool_value( if (Configuration::bool_value(
"positioning.accept-new-calibration-requests")) "positioning.accept-new-calibration-requests"))
@ -183,7 +183,7 @@ const Request& Input::get_next_request() const
bool Input::eof() const bool Input::eof() const
{ {
if (medium == NULL) if (!medium)
throw null_input_medium() ; throw null_input_medium() ;
return medium->eof() ; return medium->eof() ;
} }

View File

@ -255,7 +255,7 @@ void InputDataReader::read_from_reference_points_media()
CalibrationRequest *calibration_request = CalibrationRequest *calibration_request =
dynamic_cast<CalibrationRequest*>( dynamic_cast<CalibrationRequest*>(
const_cast<Request*>(&request)) ; const_cast<Request*>(&request)) ;
if (calibration_request == NULL) if (!calibration_request)
cerr << "Warning! Invalid calibration request at line " cerr << "Warning! Invalid calibration request at line "
<< (*i)->get_current_line_nb() << endl ; << (*i)->get_current_line_nb() << endl ;
else else

View File

@ -73,7 +73,7 @@ const Request& InputMedium::get_next_request()
void InputMedium::clear_current_request() void InputMedium::clear_current_request()
{ {
if (dynamic_cast<CalibrationRequest*>(current_request) == NULL) if (! dynamic_cast<CalibrationRequest*>(current_request))
current_request->clear() ; current_request->clear() ;
else else
{ {
@ -164,7 +164,7 @@ void InputMedium::current_request_to_calibration_request(
{ {
CalibrationRequest *calibration_request = CalibrationRequest *calibration_request =
dynamic_cast<CalibrationRequest*>(current_request) ; dynamic_cast<CalibrationRequest*>(current_request) ;
if (calibration_request != NULL) if (calibration_request)
{ {
calibration_request->set_reference_point( calibration_request->set_reference_point(
const_cast<ReferencePoint*>(reference_point)) ; const_cast<ReferencePoint*>(reference_point)) ;

View File

@ -241,7 +241,7 @@ inline bool Measurement::operator!=(const Measurement &m) const
inline Measurement::operator bool() const inline Measurement::operator bool() const
{ {
return return
cp != NULL || cp ||
! ss_list.empty() ; ! ss_list.empty() ;
} }

View File

@ -117,7 +117,7 @@ int OutputTCPSocketEvAAL::
area_of_interest_number(const Point3D &position) const area_of_interest_number(const Point3D &position) const
{ {
const Area *const area = Stock::in_which_area_is(position) ; const Area *const area = Stock::in_which_area_is(position) ;
if (area == NULL) if (!area)
return 0 ; return 0 ;
int aoi_number = 0 ; int aoi_number = 0 ;

View File

@ -25,7 +25,7 @@ Result RealPosition::compute(const Request &request)
const CalibrationRequest *calibration_request = const CalibrationRequest *calibration_request =
dynamic_cast<const CalibrationRequest*>(&request) ; dynamic_cast<const CalibrationRequest*>(&request) ;
if (calibration_request != NULL) if (calibration_request)
coordinates = static_cast<Point3D*>( coordinates = static_cast<Point3D*>(
calibration_request->get_reference_point()) ; calibration_request->get_reference_point()) ;
else else

View File

@ -163,7 +163,7 @@ bool ReferencePoint::delete_generated_requests(void)
assert(*r) ; assert(*r) ;
unordered_map<std::string, CapturePoint>::const_iterator cp ; unordered_map<std::string, CapturePoint>::const_iterator cp ;
if ((*r)->get_mobile() == NULL) if (! (*r)->get_mobile())
goto delete_request ; goto delete_request ;
// Check if the request was sent by a CP // Check if the request was sent by a CP

View File

@ -131,7 +131,7 @@ std::vector<CalibrationRequest*>& ReferencePoint::get_requests() const
*/ */
inline void ReferencePoint::add_request(const CalibrationRequest *r) inline void ReferencePoint::add_request(const CalibrationRequest *r)
{ {
if (r != NULL) if (r)
requests.push_back(const_cast<CalibrationRequest*>(r)) ; requests.push_back(const_cast<CalibrationRequest*>(r)) ;
} }

View File

@ -219,7 +219,7 @@ const string Request::to_csv() const
csv_line << aggregation_csv_format << ';' ; csv_line << aggregation_csv_format << ';' ;
if (mobile != NULL) if (mobile)
csv_line << mobile->get_mac_addr() ; csv_line << mobile->get_mac_addr() ;
csv_line csv_line
@ -230,7 +230,7 @@ const string Request::to_csv() const
const CalibrationRequest *calibration_request = const CalibrationRequest *calibration_request =
dynamic_cast<const CalibrationRequest*>(this) ; dynamic_cast<const CalibrationRequest*>(this) ;
if (calibration_request == NULL) if (!calibration_request)
csv_line << "0;0;0;0" ; csv_line << "0;0;0;0" ;
else else
{ {
@ -262,7 +262,7 @@ ostream& operator<<(ostream &os, const Request &r)
os << "Type: " << static_cast<uint_fast16_t>(r.type) os << "Type: " << static_cast<uint_fast16_t>(r.type)
<< ", Number of packets sent: " << r.nb_packets << ", Number of packets sent: " << r.nb_packets
<< ", Mobile: " << ", Mobile: "
<< (r.mobile != NULL ? r.mobile->get_mac_addr() : "Unknown_Mobile") << (r.mobile ? r.mobile->get_mac_addr() : "Unknown_Mobile")
<< ":" ; << ":" ;
// List of Measurements // List of Measurements

View File

@ -245,7 +245,7 @@ inline bool Request::operator!=(const Request &comp) const
inline Request::operator bool() const inline Request::operator bool() const
{ {
return return
mobile != NULL || mobile ||
time_sent || time_sent ||
! measurements.empty() ; ! measurements.empty() ;
} }

View File

@ -48,7 +48,7 @@ Result::Result(const Request *const _request,
string Result::in_which_area() const string Result::in_which_area() const
{ {
const Area *area = Stock::in_which_area_is(position) ; const Area *area = Stock::in_which_area_is(position) ;
if (area == NULL) if (!area)
return "" ; return "" ;
return area->get_name() ; return area->get_name() ;
@ -118,7 +118,7 @@ const string Result::to_csv() const
<< ';' ; << ';' ;
const Area *const area = Stock::in_which_area_is(position) ; const Area *const area = Stock::in_which_area_is(position) ;
if (area != NULL) if (area)
csv_line << area->get_name() ; csv_line << area->get_name() ;
return csv_line.str() ; return csv_line.str() ;

View File

@ -89,9 +89,9 @@ const string ResultList::to_csv() const
{ {
ostringstream csv_line ; ostringstream csv_line ;
if (request != NULL) if (request)
{ {
if (request->get_mobile() != NULL) if (request->get_mobile())
csv_line << request->get_mobile()->get_mac_addr() ; csv_line << request->get_mobile()->get_mac_addr() ;
csv_line csv_line
<< ';' << static_cast<uint_fast16_t>(request->get_type()) << ';' << static_cast<uint_fast16_t>(request->get_type())
@ -110,7 +110,7 @@ const string ResultList::to_csv() const
ostream& operator<<(ostream &os, const ResultList &r) ostream& operator<<(ostream &os, const ResultList &r)
{ {
if (r.request == NULL) if (!r.request)
os << "For an unknown request:\n" ; os << "For an unknown request:\n" ;
else else
os << "For the following request: " << *(r.request) << '\n' ; os << "For the following request: " << *(r.request) << '\n' ;

View File

@ -138,7 +138,7 @@ void Stock::waypoint_remove_building(const Waypoint &point,
// If the Waypoint is not linked to any Building any more, we // If the Waypoint is not linked to any Building any more, we
// delete it // delete it
if (waypoint->get_1st_building() == NULL) if (! waypoint->get_1st_building())
waypoints.erase(i) ; waypoints.erase(i) ;
} }

View File

@ -146,7 +146,7 @@ void TestUtil::create_request_list()
CalibrationRequest *calibration_request = CalibrationRequest *calibration_request =
dynamic_cast<CalibrationRequest*>(requests.at(1)) ; dynamic_cast<CalibrationRequest*>(requests.at(1)) ;
if (calibration_request != NULL) if (calibration_request)
calibration_request->reference_point_backward_link() ; calibration_request->reference_point_backward_link() ;
requests.push_back(new Request(&mobiles[0], timestamps[2], requests.push_back(new Request(&mobiles[0], timestamps[2],
@ -162,7 +162,7 @@ void TestUtil::create_result_list()
CalibrationRequest *calibration_request = CalibrationRequest *calibration_request =
dynamic_cast<CalibrationRequest*>(*i) ; dynamic_cast<CalibrationRequest*>(*i) ;
Result result ; Result result ;
if (calibration_request != NULL) if (calibration_request)
result = algo.compute(*calibration_request) ; result = algo.compute(*calibration_request) ;
else else
result = algo.compute(**i) ; result = algo.compute(**i) ;
@ -350,9 +350,9 @@ bool TestUtil::request_equals(const Request &first,
return false ; return false ;
// Compare mobile values // Compare mobile values
if (first.get_mobile() == NULL || second.get_mobile() == NULL) if (! (first.get_mobile() && second.get_mobile()))
{ {
if (first.get_mobile() != NULL || second.get_mobile() != NULL) if (first.get_mobile() || second.get_mobile())
return false ; return false ;
} }
else if (*first.get_mobile() != *second.get_mobile()) else if (*first.get_mobile() != *second.get_mobile())
@ -406,9 +406,9 @@ bool TestUtil::measurement_equals(const Measurement &first,
return false ; return false ;
// Compare ap values // Compare ap values
if (first.get_cp() == NULL || second.get_cp() == NULL) if (! (first.get_cp() && second.get_cp()))
{ {
if (first.get_cp() != NULL || second.get_cp() != NULL) if (first.get_cp() || second.get_cp())
return false ; return false ;
} }
else if (*first.get_cp() != *second.get_cp()) else if (*first.get_cp() != *second.get_cp())

View File

@ -35,7 +35,7 @@ Waypoint::Waypoint(Building *const _b,
const float _x, const float _y, const float _z): const float _x, const float _y, const float _z):
Point3D(_x, _y, _z) Point3D(_x, _y, _z)
{ {
if (_b != NULL) if (_b)
buildings.insert(_b) ; buildings.insert(_b) ;
} }
@ -47,7 +47,7 @@ Waypoint::Waypoint(Building *const _b,
*/ */
Waypoint::Waypoint(Building *const _b, const Point3D &p): Point3D(p) Waypoint::Waypoint(Building *const _b, const Point3D &p): Point3D(p)
{ {
if (_b != NULL) if (_b)
buildings.insert(_b) ; buildings.insert(_b) ;
} }

View File

@ -115,7 +115,7 @@ Waypoint::get_buildings() const
*/ */
inline void Waypoint::add_building(Building *const _b) inline void Waypoint::add_building(Building *const _b)
{ {
if (_b != NULL) if (_b)
buildings.insert(_b) ; buildings.insert(_b) ;
} }
@ -128,7 +128,7 @@ inline void Waypoint::add_buildings(const Waypoint &source)
inline void Waypoint::remove_building(Building *const _b) inline void Waypoint::remove_building(Building *const _b)
{ {
if (_b != NULL) if (_b)
buildings.erase(_b) ; buildings.erase(_b) ;
} }