[Positioning] const_cast & other minor enhancements
- In all classes where we used a C-style cast to suppress const, we now use a const_cast. - Area: Add operator=(). - InputCSV: - Document get_next_request(). - Handle exception when using Stock::get_{ap,mobile}(). - In constructor, throw an exception in case of error when opening the input file. - CalibrationMeasurement: Remove operator<<() which is useless (it is a simple call to Measurement operator<<()). - Makefile: Add target 'check'.
This commit is contained in:
parent
1f1d7de4f5
commit
f4c825c2d9
|
@ -1,4 +1,4 @@
|
|||
.PHONY : all obj doc clean purge install uninstall style
|
||||
.PHONY : all obj doc clean purge install uninstall style check
|
||||
|
||||
DOXYGEN_DIR = doc
|
||||
DOXYFILE = Doxyfile
|
||||
|
@ -14,6 +14,7 @@ CP = cp -v
|
|||
|
||||
# Autres outils
|
||||
STYLE = astyle --style=gnu
|
||||
CPPCHECK = cppcheck --enable=all
|
||||
DOXYGEN = doxygen
|
||||
|
||||
GXX = g++-4.4
|
||||
|
@ -81,3 +82,6 @@ uninstall:
|
|||
|
||||
style:
|
||||
@$(STYLE) $(OBJ:.o=.hh) $(OBJ:.o=.cc) inputmedium.hh
|
||||
|
||||
check:
|
||||
@$(CPPCHECK) $(OBJ:.o=.hh) $(OBJ:.o=.cc) inputmedium.hh
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
- InputCSV
|
||||
° Lancer une exception si l'ouverture du fichier d'entrée échoue.
|
||||
° Expliquer ce que fait get_next_request().
|
||||
° Différencier une requête normale d'une requête de calibration, en
|
||||
utilisant les champs de direction.
|
||||
° Lire la direction en tant qu'entier plutôt que float ?
|
||||
|
@ -32,16 +30,9 @@
|
|||
les Waypoint. Si oui, faut-il aussi les enlever des listes dans
|
||||
Stock ? (Pour l'instant ils ne sont pas dans Stock.)
|
||||
|
||||
- CalibrationMeasurement
|
||||
Vérifier que l'operator<<() est utile (puisqu'il y a celui de
|
||||
Measurement).
|
||||
|
||||
- Request
|
||||
Constructeur par recopie, operator==(), etc.
|
||||
|
||||
- Area
|
||||
operator=()
|
||||
|
||||
- AccessPoint
|
||||
Attribut float friis_index ?
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ Area::Area(const Building *_building, const string &_name,
|
|||
const float &_x1, const float &_y1, const float &_z1,
|
||||
const float &_x2, const float &_y2, const float &_z2)
|
||||
{
|
||||
building = (Building *) _building ;
|
||||
building = const_cast<Building*>(_building) ;
|
||||
name = _name ;
|
||||
|
||||
float x_min, x_max, y_min, y_max, z_min, z_max ;
|
||||
|
@ -106,6 +106,20 @@ bool Area::contains_point(const Point3D &p) const
|
|||
/* *** Operators *** */
|
||||
|
||||
|
||||
const Area& Area::operator=(const Area &a)
|
||||
{
|
||||
if (this == &a)
|
||||
return *this ;
|
||||
|
||||
building = a.building ;
|
||||
name = a.name ;
|
||||
p_min = a.p_min ;
|
||||
p_max = a.p_max ;
|
||||
|
||||
return *this ;
|
||||
}
|
||||
|
||||
|
||||
bool Area::operator==(const Area &a) const
|
||||
{
|
||||
if (this == &a)
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
|
||||
/** @name Operators */
|
||||
//@{
|
||||
const Area& operator=(const Area &a) ;
|
||||
bool operator==(const Area &a) const ;
|
||||
bool operator!=(const Area &a) const ;
|
||||
//@}
|
||||
|
@ -112,7 +113,7 @@ inline const Point3D& Area::get_p_max() const
|
|||
|
||||
inline void Area::set_building(const Building *_building)
|
||||
{
|
||||
building = (Building *) _building ;
|
||||
building = const_cast<Building*>(_building) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ inline void Building::set_name(const std::string &_name)
|
|||
inline void Building::add_area(const Area *a)
|
||||
{
|
||||
if (a != NULL)
|
||||
areas.push_back((Area *) a) ;
|
||||
areas.push_back(const_cast<Area*>(a)) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,7 +106,7 @@ inline void Building::add_area(const Area *a)
|
|||
inline void Building::add_waypoint(const Waypoint *wp)
|
||||
{
|
||||
if (wp != NULL)
|
||||
waypoints.push_back((Waypoint *) wp) ;
|
||||
waypoints.push_back(const_cast<Waypoint*>(wp)) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,19 +27,3 @@ bool CalibrationMeasurement::operator==(const CalibrationMeasurement &cm)
|
|||
this->Measurement::operator==(cm) &&
|
||||
reference_point == cm.reference_point ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Because a ReferencePoint displays its list of CalibrationMeasurement,
|
||||
* the ReferencePoint associated with a CalibrationMeasurement is not
|
||||
* displayed. Therefore, this is a simple mapping to
|
||||
* operator<<(std::ostream&, const Measurement&)
|
||||
*/
|
||||
std::ostream &operator<<(std::ostream &os, const CalibrationMeasurement &cm)
|
||||
{
|
||||
os
|
||||
<< (Measurement) cm ;
|
||||
|
||||
return os ;
|
||||
}
|
||||
|
|
|
@ -46,10 +46,6 @@ public:
|
|||
bool operator==(const CalibrationMeasurement &cm) ;
|
||||
bool operator!=(const CalibrationMeasurement &cm) ;
|
||||
//@}
|
||||
|
||||
/// Displays a CalibrationMeasurement
|
||||
friend std::ostream &operator<<(std::ostream &os,
|
||||
const CalibrationMeasurement &cm) ;
|
||||
} ;
|
||||
|
||||
|
||||
|
@ -70,7 +66,7 @@ inline ReferencePoint* CalibrationMeasurement::get_reference_point(void) const
|
|||
inline void CalibrationMeasurement::set_reference_point(
|
||||
const ReferencePoint *_rp)
|
||||
{
|
||||
reference_point = (ReferencePoint *) _rp ;
|
||||
reference_point = const_cast<ReferencePoint*>(_rp) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ using namespace boost ;
|
|||
/**
|
||||
* Prepares the InputCSV to read a CSV file.
|
||||
* @param filename The name of the file to open.
|
||||
* @throw FIXME if the file cannot be opened.
|
||||
* @throw runtime_error if the file cannot be opened.
|
||||
*/
|
||||
InputCSV::InputCSV(const string &filename)
|
||||
{
|
||||
|
@ -31,9 +31,8 @@ InputCSV::InputCSV(const string &filename)
|
|||
|
||||
input_file.open(input_file_name.c_str()) ;
|
||||
if (! input_file)
|
||||
cerr
|
||||
<< "InputCSV::InputCSV(): Error opening input file « "
|
||||
<< input_file_name << " »!" << endl ;
|
||||
throw runtime_error("Error opening input file « " +
|
||||
input_file_name + " »!") ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,12 +41,25 @@ InputCSV::InputCSV(const string &filename)
|
|||
|
||||
|
||||
/**
|
||||
* FIXME Detailed description comming soon…
|
||||
* This function reads the next Request in the CSV input file. Blank
|
||||
* lines and lines containing only spaces are skipped.
|
||||
*
|
||||
* #input_file should be opened before proceeding requests; otherwise,
|
||||
* #current_request is \link Request::clear() cleared\endlink and a
|
||||
* blank Request is returned. The file must be valid,
|
||||
* semicolon-separated (\em not comma-separated).
|
||||
*
|
||||
* @return The read Request, or a blank Request in case of error (file
|
||||
* not opened, end of file, invalid field or wrong number of fields in
|
||||
* the line).
|
||||
*/
|
||||
const Request& InputCSV::get_next_request()
|
||||
{
|
||||
if (! input_file)
|
||||
return current_request ;
|
||||
{
|
||||
current_request.clear() ;
|
||||
return current_request ;
|
||||
}
|
||||
|
||||
string line ;
|
||||
|
||||
|
@ -82,8 +94,14 @@ const Request& InputCSV::get_next_request()
|
|||
}
|
||||
|
||||
// If the mobile did not exist, we create it
|
||||
if (Stock::get_mobile(*ti).get_mac_addr().size() == 0)
|
||||
Stock::getw_mobile(*ti).set_mac_addr(*ti) ;
|
||||
try
|
||||
{
|
||||
Stock::get_mobile(*ti) ;
|
||||
}
|
||||
catch (out_of_range e)
|
||||
{
|
||||
Stock::getw_mobile(*ti).set_mac_addr(*ti) ;
|
||||
}
|
||||
current_request.set_mobile(&Stock::get_mobile(*ti)) ;
|
||||
|
||||
// Read Timestamp field
|
||||
|
@ -168,8 +186,14 @@ const Request& InputCSV::get_next_request()
|
|||
}
|
||||
|
||||
// If the AP did not exist, we create it
|
||||
if (Stock::get_ap(mac_ap).get_mac_addr().size() == 0)
|
||||
Stock::getw_ap(mac_ap).set_mac_addr(mac_ap) ;
|
||||
try
|
||||
{
|
||||
Stock::get_ap(mac_ap) ;
|
||||
}
|
||||
catch (out_of_range e)
|
||||
{
|
||||
Stock::getw_ap(mac_ap).set_mac_addr(mac_ap) ;
|
||||
}
|
||||
measurements[mac_ap].set_ap(&Stock::get_ap(mac_ap)) ;
|
||||
|
||||
// Adding value
|
||||
|
|
|
@ -11,7 +11,7 @@ using namespace std ;
|
|||
Measurement::Measurement(const AccessPoint *_ap,
|
||||
const vector<int> &_ss_list)
|
||||
{
|
||||
ap = (AccessPoint *) _ap ;
|
||||
ap = const_cast<AccessPoint*>(_ap) ;
|
||||
ss_list = _ss_list ;
|
||||
ss_list.reserve(10) ;
|
||||
update_average_ss() ;
|
||||
|
|
|
@ -101,7 +101,7 @@ inline float Measurement::get_average_ss() const
|
|||
|
||||
inline void Measurement::set_ap(const AccessPoint *_ap)
|
||||
{
|
||||
ap = (AccessPoint *) _ap ;
|
||||
ap = const_cast<AccessPoint*>(_ap) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ std::vector<CalibrationMeasurement*>& ReferencePoint::get_measurements() const
|
|||
inline void ReferencePoint::add_measurement(const CalibrationMeasurement *cm)
|
||||
{
|
||||
if (cm != NULL)
|
||||
measurements.push_back((CalibrationMeasurement *) cm) ;
|
||||
measurements.push_back(const_cast<CalibrationMeasurement*>(cm)) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ Request::Request(const struct timespec &_timestamp,
|
|||
Request::Request(const Mobile *_mobile, const struct timespec &_timestamp,
|
||||
const unordered_map<string, Measurement> &_measurements)
|
||||
{
|
||||
mobile = (Mobile*) _mobile ;
|
||||
mobile = const_cast<Mobile*>(_mobile) ;
|
||||
timestamp = _timestamp ;
|
||||
measurements = _measurements ;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ inline const struct timespec& Request::get_timestamp() const
|
|||
|
||||
inline void Request::set_mobile(const Mobile *_mobile)
|
||||
{
|
||||
mobile = (Mobile *) _mobile ;
|
||||
mobile = const_cast<Mobile*>(_mobile) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ using namespace std ;
|
|||
Waypoint::Waypoint(const Building *_b, const Point3D &p): Point3D(p)
|
||||
{
|
||||
if (_b != NULL)
|
||||
buildings.push_back((Building *) _b) ;
|
||||
buildings.push_back(const_cast<Building*>(_b)) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ Waypoint::Waypoint(const Building *_b,
|
|||
): Point3D(_x, _y, _z)
|
||||
{
|
||||
if (_b != NULL)
|
||||
buildings.push_back((Building *) _b) ;
|
||||
buildings.push_back(const_cast<Building*>(_b)) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ inline const std::vector<Building*>& Waypoint::get_buildings() const
|
|||
inline void Waypoint::add_building(const Building *_b)
|
||||
{
|
||||
if (_b != NULL)
|
||||
buildings.push_back((Building *) _b) ;
|
||||
buildings.push_back(const_cast<Building*>(_b)) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue