[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 ?
|
- Accesseurs par références ?
|
||||||
getref_mon_attribut() (cf. l'ancien clientinfo.hh)
|
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_
|
#ifndef _OWLPS_POSITIONING_AREA_HH_
|
||||||
#define _OWLPS_POSITIONING_AREA_HH_
|
#define _OWLPS_POSITIONING_AREA_HH_
|
||||||
|
|
||||||
class Area ;
|
class Building ;
|
||||||
|
|
||||||
#include "building.hh"
|
|
||||||
#include "point3d.hh"
|
#include "point3d.hh"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
|
@ -31,18 +31,18 @@ Building::Building(const Building &b)
|
||||||
*/
|
*/
|
||||||
Building::~Building()
|
Building::~Building()
|
||||||
{
|
{
|
||||||
cout << "Building "<< name <<" area size : " << areas.size() << endl;
|
|
||||||
// Empty Area list
|
// Empty Area list
|
||||||
for (unsigned int i = 0 ; i < areas.size() ; i++)
|
for (vector<Area*>::iterator i = areas.begin() ; i != areas.end() ; i++)
|
||||||
delete areas[i] ;
|
delete *i ;
|
||||||
areas.clear() ;
|
areas.clear() ;
|
||||||
|
|
||||||
// Empty Waypoint list
|
// 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
|
// Delete current waypoint only if it is not linked to another building
|
||||||
if (waypoints[i]->get_buildings().size() <= 1)
|
if ((*i)->get_buildings().size() <= 1)
|
||||||
delete waypoints[i] ;
|
delete *i ;
|
||||||
}
|
}
|
||||||
waypoints.clear() ;
|
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 ;
|
os << b.name ;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public :
|
||||||
bool operator==(const Building &p) const ;
|
bool operator==(const Building &p) const ;
|
||||||
inline 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_
|
#endif // _OWLPS_POSITIONING_REFERENCEPOINT_HH_
|
||||||
|
|
|
@ -74,10 +74,10 @@ void Measurement::update_average_ss()
|
||||||
{
|
{
|
||||||
average_ss = 0 ;
|
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 =
|
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)) ;
|
(ss_list.size() * pow(10, average_ss / 10.0)) ;
|
||||||
average_ss = 10 * log10(ss_mwatts / ss_list.size()) ;
|
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)
|
ostream &operator<<(ostream &os, const Measurement &m)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
// MAC addresses
|
||||||
|
|
||||||
os << m.mobile->get_mac_addr() << "->" << m.ap->get_mac_addr() << ": " ;
|
os << m.mobile->get_mac_addr() << "->" << m.ap->get_mac_addr() << ": " ;
|
||||||
|
|
||||||
|
// List of SS
|
||||||
if (m.ss_list.size() == 0)
|
if (m.ss_list.size() == 0)
|
||||||
os << "No values" ;
|
os << "No values" ;
|
||||||
else
|
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];
|
os << *i ;
|
||||||
if (i < m.ss_list.size() - 1)
|
if (i != m.ss_list.end() - 1)
|
||||||
os << ";" ;
|
os << ";" ;
|
||||||
}
|
}
|
||||||
os << " [AVG=" << m.average_ss << "]" ;
|
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 ;
|
os << (Point3D) rp << endl ;
|
||||||
|
|
||||||
|
// List of measurements
|
||||||
if (rp.measurements.size() == 0)
|
if (rp.measurements.size() == 0)
|
||||||
os << "No measurement." << endl ;
|
os << "No measurement." << endl ;
|
||||||
else
|
else
|
||||||
for (i = 0 ; i < rp.measurements.size() ; i++)
|
for (vector<CalibrationMeasurement*>::const_iterator
|
||||||
os << endl << *rp.measurements[i] ;
|
i = rp.measurements.begin() ;
|
||||||
|
i < rp.measurements.end() ; i++)
|
||||||
|
os << endl << *i ;
|
||||||
|
|
||||||
return os ;
|
return os ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
bool operator==(const ReferencePoint &rp) const ;
|
bool operator==(const ReferencePoint &rp) const ;
|
||||||
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_
|
#endif // _OWLPS_POSITIONING_REFERENCEPOINT_HH_
|
||||||
|
|
|
@ -31,10 +31,14 @@ Waypoint::~Waypoint()
|
||||||
|
|
||||||
Building* Waypoint::get_1st_building() const
|
Building* Waypoint::get_1st_building() const
|
||||||
{
|
{
|
||||||
if (buildings.size() > 0)
|
try
|
||||||
return buildings[0] ;
|
{
|
||||||
|
return buildings.at(0) ;
|
||||||
return NULL ;
|
}
|
||||||
|
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 ;
|
os << (Point3D) wp ;
|
||||||
|
|
||||||
|
// List of buildings
|
||||||
if (wp.buildings.size() == 0)
|
if (wp.buildings.size() == 0)
|
||||||
os << endl << "Belongs to no building!" ;
|
os << endl << "Belongs to no building!" ;
|
||||||
else
|
else
|
||||||
for (i = 0 ; i < wp.buildings.size() ; i++)
|
for (vector<Building*>::const_iterator i = wp.buildings.begin() ;
|
||||||
os << endl << *wp.buildings[i] ;
|
i < wp.buildings.end() ; i++)
|
||||||
|
os << endl << *i ;
|
||||||
|
|
||||||
return os ;
|
return os ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
class Waypoint: public Point3D
|
class Waypoint: public Point3D
|
||||||
{
|
{
|
||||||
|
@ -30,7 +31,7 @@ public:
|
||||||
bool operator==(const Waypoint &wp) const ;
|
bool operator==(const Waypoint &wp) const ;
|
||||||
inline 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_
|
#endif // _OWLPS_POSITIONING_WAYPOINT_HH_
|
||||||
|
|
Loading…
Reference in New Issue