[Positioning] Class declarations, vector.at(), iterators
- Add section « C++ en action » in TODO. - Where possible, class declarations instead of #include. - Use of iterators and at() instead of operator[] for vectors. - Const arguments for operator<< where forgotten.
This commit is contained in:
parent
d257d08d8d
commit
40617901f6
|
@ -5,3 +5,12 @@
|
|||
|
||||
- Accesseurs par références ?
|
||||
getref_mon_attribut() (cf. l'ancien clientinfo.hh)
|
||||
|
||||
- C++ en action
|
||||
[OK] Pré-déclaration de classes plutôt que #include. 108
|
||||
Espaces de noms ? 109
|
||||
Fonctions inline. 116
|
||||
[OK] Utilisation de vector.at() et des itérateurs plutôt que [] ? 210
|
||||
Réserver l'espace mémoire des vector avec reserve(). 217
|
||||
Utiliser hash_map plutôt que map s'il n'y a pas besoin de trier. 252
|
||||
Pas de using dans les en-têtes.
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#ifndef _OWLPS_POSITIONING_AREA_HH_
|
||||
#define _OWLPS_POSITIONING_AREA_HH_
|
||||
|
||||
class Area ;
|
||||
class Building ;
|
||||
|
||||
#include "building.hh"
|
||||
#include "point3d.hh"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -31,18 +31,18 @@ Building::Building(const Building &b)
|
|||
*/
|
||||
Building::~Building()
|
||||
{
|
||||
cout << "Building "<< name <<" area size : " << areas.size() << endl;
|
||||
// Empty Area list
|
||||
for (unsigned int i = 0 ; i < areas.size() ; i++)
|
||||
delete areas[i] ;
|
||||
for (vector<Area*>::iterator i = areas.begin() ; i != areas.end() ; i++)
|
||||
delete *i ;
|
||||
areas.clear() ;
|
||||
|
||||
// Empty Waypoint list
|
||||
for (unsigned int i = 0 ; i < waypoints.size() ; i++)
|
||||
for (vector<Waypoint*>::iterator i = waypoints.begin() ;
|
||||
i != waypoints.end() ; i++)
|
||||
{
|
||||
// Delete current waypoint only if it is not linked to another building
|
||||
if (waypoints[i]->get_buildings().size() <= 1)
|
||||
delete waypoints[i] ;
|
||||
if ((*i)->get_buildings().size() <= 1)
|
||||
delete *i ;
|
||||
}
|
||||
waypoints.clear() ;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ bool Building::operator!=(const Building &b) const
|
|||
|
||||
|
||||
|
||||
ostream& operator<<(ostream &os, Building &b)
|
||||
ostream& operator<<(ostream &os, const Building &b)
|
||||
{
|
||||
os << b.name ;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public :
|
|||
bool operator==(const Building &p) const ;
|
||||
inline bool operator!=(const Building &p) const ;
|
||||
|
||||
friend ostream& operator<<(ostream &os, Building &b) ;
|
||||
friend ostream& operator<<(ostream &os, const Building &b) ;
|
||||
} ;
|
||||
|
||||
#endif // _OWLPS_POSITIONING_REFERENCEPOINT_HH_
|
||||
|
|
|
@ -74,10 +74,10 @@ void Measurement::update_average_ss()
|
|||
{
|
||||
average_ss = 0 ;
|
||||
|
||||
for (unsigned int i=0 ; i < ss_list.size() ; i++)
|
||||
for (vector<int>::iterator i = ss_list.begin() ; i < ss_list.end() ; i++)
|
||||
{
|
||||
float ss_mwatts =
|
||||
pow(10, (float) ss_list[i] / 10.0) +
|
||||
pow(10, (float) *i / 10.0) +
|
||||
(ss_list.size() * pow(10, average_ss / 10.0)) ;
|
||||
average_ss = 10 * log10(ss_mwatts / ss_list.size()) ;
|
||||
}
|
||||
|
@ -146,19 +146,21 @@ bool Measurement::operator!=(const Measurement &m)
|
|||
|
||||
ostream &operator<<(ostream &os, const Measurement &m)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
// MAC addresses
|
||||
os << m.mobile->get_mac_addr() << "->" << m.ap->get_mac_addr() << ": " ;
|
||||
|
||||
// List of SS
|
||||
if (m.ss_list.size() == 0)
|
||||
os << "No values" ;
|
||||
else
|
||||
for (i = 0 ; i < m.ss_list.size() ; i++)
|
||||
for (vector<int>::const_iterator i = m.ss_list.begin() ;
|
||||
i < m.ss_list.end() ; i++)
|
||||
{
|
||||
os << m.ss_list[i];
|
||||
if (i < m.ss_list.size() - 1)
|
||||
os << *i ;
|
||||
if (i != m.ss_list.end() - 1)
|
||||
os << ";" ;
|
||||
}
|
||||
os << " [AVG=" << m.average_ss << "]" ;
|
||||
|
||||
return os;
|
||||
return os ;
|
||||
}
|
||||
|
|
|
@ -172,16 +172,19 @@ bool ReferencePoint::operator!=(const ReferencePoint &rp) const
|
|||
|
||||
|
||||
|
||||
ostream &operator<<(ostream &os, ReferencePoint &rp)
|
||||
ostream &operator<<(ostream &os, const ReferencePoint &rp)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
// Coordinates
|
||||
os << (Point3D) rp << endl ;
|
||||
|
||||
// List of measurements
|
||||
if (rp.measurements.size() == 0)
|
||||
os << "No measurement." << endl ;
|
||||
else
|
||||
for (i = 0 ; i < rp.measurements.size() ; i++)
|
||||
os << endl << *rp.measurements[i] ;
|
||||
for (vector<CalibrationMeasurement*>::const_iterator
|
||||
i = rp.measurements.begin() ;
|
||||
i < rp.measurements.end() ; i++)
|
||||
os << endl << *i ;
|
||||
|
||||
return os ;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
bool operator==(const ReferencePoint &rp) const ;
|
||||
bool operator!=(const ReferencePoint &rp) const ;
|
||||
|
||||
friend ostream &operator<<(ostream &os, ReferencePoint &rp) ;
|
||||
friend ostream &operator<<(ostream &os, const ReferencePoint &rp) ;
|
||||
} ;
|
||||
|
||||
#endif // _OWLPS_POSITIONING_REFERENCEPOINT_HH_
|
||||
|
|
|
@ -31,10 +31,14 @@ Waypoint::~Waypoint()
|
|||
|
||||
Building* Waypoint::get_1st_building() const
|
||||
{
|
||||
if (buildings.size() > 0)
|
||||
return buildings[0] ;
|
||||
|
||||
return NULL ;
|
||||
try
|
||||
{
|
||||
return buildings.at(0) ;
|
||||
}
|
||||
catch (out_of_range &e)
|
||||
{
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,16 +92,18 @@ bool Waypoint::operator!=(const Waypoint &wp) const
|
|||
|
||||
|
||||
|
||||
ostream &operator<<(ostream &os, Waypoint &wp)
|
||||
ostream &operator<<(ostream &os, const Waypoint &wp)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
// Coordinates
|
||||
os << (Point3D) wp ;
|
||||
|
||||
// List of buildings
|
||||
if (wp.buildings.size() == 0)
|
||||
os << endl << "Belongs to no building!" ;
|
||||
else
|
||||
for (i = 0 ; i < wp.buildings.size() ; i++)
|
||||
os << endl << *wp.buildings[i] ;
|
||||
for (vector<Building*>::const_iterator i = wp.buildings.begin() ;
|
||||
i < wp.buildings.end() ; i++)
|
||||
os << endl << *i ;
|
||||
|
||||
return os ;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
class Waypoint: public Point3D
|
||||
{
|
||||
|
@ -30,7 +31,7 @@ public:
|
|||
bool operator==(const Waypoint &wp) const ;
|
||||
inline bool operator!=(const Waypoint &wp) const ;
|
||||
|
||||
friend ostream& operator<<(ostream &os, Waypoint &wp) ;
|
||||
friend ostream& operator<<(ostream &os, const Waypoint &wp) ;
|
||||
} ;
|
||||
|
||||
#endif // _OWLPS_POSITIONING_WAYPOINT_HH_
|
||||
|
|
Loading…
Reference in New Issue