[Positioning] Check code with cppcheck

- Replace occurences of `container.size() == 0` with
  `container.empty()`.
- Fix an allocation in posexcept.cc (false positive?).
- UserInterface: in constructor, handle bad_alloc exception possibly
  thrown by `new`.
This commit is contained in:
Matteo Cypriani 2010-02-26 13:09:45 +01:00
parent bc46fc1af2
commit 7264080536
6 changed files with 19 additions and 9 deletions

View File

@ -95,7 +95,7 @@ void Measurement::clear()
void Measurement::update_average_ss()
{
if (ss_list.size() == 0)
if (ss_list.empty())
{
average_ss = 0 ;
return ;
@ -151,7 +151,7 @@ ostream &operator<<(ostream &os, const Measurement &m)
<< ": " ;
// List of SS
if (m.ss_list.size() == 0)
if (m.ss_list.empty())
os << "No values" ;
else
for (vector<int>::const_iterator i = m.ss_list.begin() ;

View File

@ -5,8 +5,10 @@
using namespace std ;
bad_direction::bad_direction(const char _direction) throw():
direction(_direction) {}
bad_direction::bad_direction(const char _direction) throw()
{
direction = _direction ;
}
const char* bad_direction::what() const throw()

View File

@ -159,7 +159,7 @@ ostream &operator<<(ostream &os, const ReferencePoint &rp)
os << (Point3D) rp << '\n' ;
// List of requests
if (rp.requests.size() == 0)
if (rp.requests.empty())
os << "No request." << '\n' ;
else
for (vector<CalibrationRequest*>::const_iterator

View File

@ -112,7 +112,7 @@ ostream &operator<<(ostream &os, const Request &r)
<< ":" ;
// List of Measurements
if (r.measurements.size() == 0)
if (r.measurements.empty())
os << " No values" ;
else
for (unordered_map<string, Measurement>::const_iterator i

View File

@ -26,8 +26,16 @@ UserInterface::UserInterface(const int argc, char **argv)
cli_argument_values = argv ;
config_file_name = DEFAULT_CONFIG_FILE_NAME ;
cli_options = new po::options_description("General options") ;
file_options = new po::options_description("Parameters") ;
try
{
cli_options = new po::options_description("General options") ;
file_options = new po::options_description("Parameters") ;
}
catch (bad_alloc e)
{
throw ;
}
fill_options() ;
parse_options() ;

View File

@ -80,7 +80,7 @@ ostream &operator<<(ostream &os, const Waypoint &wp)
os << (Point3D) wp ;
// List of buildings
if (wp.buildings.size() == 0)
if (wp.buildings.empty())
os << '\n' << "Belongs to no building!" ;
else
for (vector<Building*>::const_iterator i = wp.buildings.begin() ;