diff --git a/TODO.t2t b/TODO.t2t index 2747396..0814465 100644 --- a/TODO.t2t +++ b/TODO.t2t @@ -45,11 +45,6 @@ Work to do in OwlPS information. This will make easier to develop clients in other languages than C and over other protocols than UDP. -- Mark arguments as const in function headers if needed - - Mostly done in the Positioner C++ code (to be checked). - //Done in lib* and other C modules.// - - Use struct ether_addr to store MAC addresses? We could use the struct ether_addr to store binary MAC addresses, and diff --git a/owlps-positioner/area.cc b/owlps-positioner/area.cc index a7928ca..db4c1e1 100644 --- a/owlps-positioner/area.cc +++ b/owlps-positioner/area.cc @@ -23,9 +23,9 @@ using namespace std ; /* *** Constructors *** */ -Area::Area(const Building *_building, const string &_name, +Area::Area(const Building *const _building, const string &_name, const Point3D &p1, const Point3D &p2): - building(const_cast(_building)), name(_name) + building(_building), name(_name) { set_coordinates(p1, p2) ; } diff --git a/owlps-positioner/area.hh b/owlps-positioner/area.hh index 2478ee5..0ba78b0 100644 --- a/owlps-positioner/area.hh +++ b/owlps-positioner/area.hh @@ -26,15 +26,16 @@ class Building ; class Area { protected: - Building *building ; ///< The Building in which the Area is - std::string name ; + const Building *building ; ///< Building in which the Area is + std::string name ; ///< Name of the Area Point3D p_min ; ///< First coordinate of the Area Point3D p_max ; ///< Second coordinate of the Area - void reorder_coordinates(void) ; ///< Reorders #p_min and #p_max + /// Reorders #p_min and #p_max + void reorder_coordinates(void) ; public: - Area(const Building *_building = NULL, + Area(const Building *const _building = NULL, const std::string &_name = "Unnamed area", const Point3D &p1 = Point3D(0,0,0), const Point3D &p2 = Point3D(0,0,0)) ; @@ -47,7 +48,7 @@ public: /** @name Read accessors */ //@{ - Building* get_building(void) const ; + const Building* get_building(void) const ; const std::string& get_name(void) const ; const Point3D& get_p_min(void) const ; const Point3D& get_p_max(void) const ; @@ -55,7 +56,7 @@ public: /** @name Write accessors */ //@{ - void set_building(const Building *_building) ; + void set_building(const Building *const _building) ; void set_name(const std::string &_name) ; /// Sets the coordinates of the Area and reorder them void set_coordinates(const Point3D &p1, const Point3D &p2) ; @@ -83,7 +84,7 @@ public: /* *** Read accessors *** */ -inline Building* Area::get_building() const +inline const Building* Area::get_building() const { return building ; } @@ -111,9 +112,9 @@ inline const Point3D& Area::get_p_max() const /* *** Write accessors *** */ -inline void Area::set_building(const Building *_building) +inline void Area::set_building(const Building *const _building) { - building = const_cast(_building) ; + building = _building ; } diff --git a/owlps-positioner/autocalibration.cc b/owlps-positioner/autocalibration.cc index 4bb6596..e086e75 100644 --- a/owlps-positioner/autocalibration.cc +++ b/owlps-positioner/autocalibration.cc @@ -81,7 +81,7 @@ void Autocalibration::generate_reference_point() cr.set_time_sent(cr.get_time_received()) ; cr.set_mobile(&mobile) ; cr.set_measurements(measurements) ; - cr.set_reference_point(¤t_rp) ; + cr.set_reference_point(const_cast(¤t_rp)) ; Stock::store_calibration_request(cr) ; } diff --git a/owlps-positioner/autocalibrationline.cc b/owlps-positioner/autocalibrationline.cc index e774bbf..023b0df 100644 --- a/owlps-positioner/autocalibrationline.cc +++ b/owlps-positioner/autocalibrationline.cc @@ -31,6 +31,7 @@ using namespace std ; /** + * @param _point The coordinates of the reference point to generate. * @param _cp1 The first capture point (receiver) to use the measurements * of to generate the reference points; it cannot be NULL. * @param _cp2 The second receiver capture point (optional). @@ -227,7 +228,7 @@ bool AutocalibrationLine::compute_single_packet_ss(pkt_id_t pkt_id) double AutocalibrationLine:: -compute_single_ss(pkt_id_t pkt_id, float point_dst) +compute_single_ss(const pkt_id_t pkt_id, const float point_dst) { /* Friis index */ const string &rx_mac = rx->second.get_mac_addr() ; diff --git a/owlps-positioner/autocalibrationline.hh b/owlps-positioner/autocalibrationline.hh index fc5bb7f..d8154a3 100644 --- a/owlps-positioner/autocalibrationline.hh +++ b/owlps-positioner/autocalibrationline.hh @@ -44,7 +44,7 @@ protected: /// Computes a SS with only one packet in it bool compute_single_packet_ss(pkt_id_t pkt_id) ; /// Actually computes a SS - double compute_single_ss(pkt_id_t pkt_id, float point_dst) ; + double compute_single_ss(const pkt_id_t pkt_id, const float point_dst) ; public: AutocalibrationLine(const Point3D &_point, diff --git a/owlps-positioner/autocalibrationmesh.cc b/owlps-positioner/autocalibrationmesh.cc index b9f0dfe..9475e7c 100644 --- a/owlps-positioner/autocalibrationmesh.cc +++ b/owlps-positioner/autocalibrationmesh.cc @@ -145,7 +145,7 @@ void AutocalibrationMesh::weight_cps() void AutocalibrationMesh::init_cp( - map::const_iterator> >::const_iterator s) { struct cp ref ; @@ -266,7 +266,7 @@ bool AutocalibrationMesh::compute_single_packet_ss(pkt_id_t pkt_id) * @returns The weighted SS value in dBm, or 128 in case of error. */ double AutocalibrationMesh::compute_weighted_ss( - unsigned int cp_idx, pkt_id_t pkt_id, float point_dst) + const unsigned int cp_idx, const pkt_id_t pkt_id, const float point_dst) { const cp &ref = ref_cps[cp_idx] ; const ReferencePoint &rp = diff --git a/owlps-positioner/autocalibrationmesh.hh b/owlps-positioner/autocalibrationmesh.hh index 70bae40..aada94a 100644 --- a/owlps-positioner/autocalibrationmesh.hh +++ b/owlps-positioner/autocalibrationmesh.hh @@ -57,7 +57,7 @@ protected: /// Initialises a struct cp with the values from `s` void init_cp( - std::map::const_iterator> >::const_iterator s) ; /// Generates the SSs for the current CP @@ -73,8 +73,9 @@ protected: /// Computes a SS with only one packet in it bool compute_single_packet_ss(pkt_id_t pkt_id) ; /// Computes a SS according to the weight of the CP - double compute_weighted_ss( - unsigned int cp_idx, pkt_id_t pkt_id, float point_dst) ; + double compute_weighted_ss(const unsigned int cp_idx, + const pkt_id_t pkt_id, + const float point_dst) ; public: AutocalibrationMesh(const Point3D &_point): Autocalibration(_point) {} diff --git a/owlps-positioner/building.cc b/owlps-positioner/building.cc index cfa6689..f93bbd7 100644 --- a/owlps-positioner/building.cc +++ b/owlps-positioner/building.cc @@ -51,10 +51,11 @@ Building::~Building() /** - * @param area A pointer to the Area to add. If it is NULL, nothing - * will be added. If the Area it points to already exist in #areas, it is - * deleted and nullified, unless it is the same pointer (see the code to - * understand!); hmm, maybe we should handle that with exceptions… + * @param[in,out] area A pointer to the Area to add. If it is NULL, + * nothing will be added. If the Area it points to already exists in + * #areas, it is deleted and set to NULL, unless it is the same pointer + * (see the code to understand!); hmm, maybe we should handle that with + * exceptions… */ void Building::add_area(Area *&area) { diff --git a/owlps-positioner/building.hh b/owlps-positioner/building.hh index bf7bca3..a30bf3f 100644 --- a/owlps-positioner/building.hh +++ b/owlps-positioner/building.hh @@ -33,7 +33,7 @@ protected: /// List of Waypoint in the Building std::unordered_set waypoints ; -public : +public: Building(const std::string &_name = "Unnamed building"): name(_name) {} @@ -46,8 +46,7 @@ public : /** @name Read accessors */ //@{ const std::string& get_name(void) const ; - const std::unordered_map& - get_areas(void) const ; + const std::unordered_map& get_areas(void) const ; const std::unordered_set& get_waypoints(void) const ; //@} @@ -55,9 +54,9 @@ public : //@{ void set_name(const std::string &_name) ; /// Adds an Area to the [list of areas](@ref #areas) - void add_area(Area *&a) ; + void add_area(Area *&area) ; /// Adds a Waypoint to the [list of waypoints](@ref #waypoints) - void add_waypoint(const Waypoint *wp) ; + void add_waypoint(Waypoint *const wp) ; //@} /** @name Operators */ @@ -110,10 +109,10 @@ inline void Building::set_name(const std::string &_name) * @param wp A pointer to the Waypoint to add. If `wp` is NULL, * nothing will be added. */ -inline void Building::add_waypoint(const Waypoint *wp) +inline void Building::add_waypoint(Waypoint *const wp) { if (wp != NULL) - waypoints.insert(const_cast(wp)) ; + waypoints.insert(wp) ; } diff --git a/owlps-positioner/calibrationrequest.cc b/owlps-positioner/calibrationrequest.cc index 91cb1de..5683202 100644 --- a/owlps-positioner/calibrationrequest.cc +++ b/owlps-positioner/calibrationrequest.cc @@ -19,8 +19,7 @@ /* *** Constructors *** */ -CalibrationRequest:: -CalibrationRequest(uint_fast8_t _type): +CalibrationRequest::CalibrationRequest(const uint_fast8_t _type): reference_point(NULL), direction(Direction()) { type = _type ; @@ -29,9 +28,9 @@ CalibrationRequest(uint_fast8_t _type): CalibrationRequest:: CalibrationRequest(const Request &source, - ReferencePoint *_reference_point, + ReferencePoint *const _reference_point, const Direction &_direction, - uint_fast8_t _type): + const uint_fast8_t _type): Request(source), reference_point(_reference_point), direction(_direction) { diff --git a/owlps-positioner/calibrationrequest.hh b/owlps-positioner/calibrationrequest.hh index 2325087..5c74ce5 100644 --- a/owlps-positioner/calibrationrequest.hh +++ b/owlps-positioner/calibrationrequest.hh @@ -30,16 +30,16 @@ protected: Direction direction ; public: - CalibrationRequest(uint_fast8_t _type = OWL_REQUEST_AUTOCALIBRATION) ; + CalibrationRequest(const uint_fast8_t _type = OWL_REQUEST_AUTOCALIBRATION) ; CalibrationRequest(const CalibrationRequest &source): Request(source), reference_point(source.reference_point), direction(source.direction) {} CalibrationRequest(const Request &source, - ReferencePoint *_reference_point = NULL, + ReferencePoint *const _reference_point = NULL, const Direction &_direction = Direction(), - uint_fast8_t _type = OWL_REQUEST_AUTOCALIBRATION) ; + const uint_fast8_t _type = OWL_REQUEST_AUTOCALIBRATION) ; ~CalibrationRequest(void) {} @@ -52,7 +52,7 @@ public: /** @name Write accessors */ //@{ void set_direction(const Direction &_direction) ; - void set_reference_point(const ReferencePoint *_rp) ; + void set_reference_point(ReferencePoint *const _rp) ; /// Adds the CalibrationRequest to the #reference_point list of requests void reference_point_backward_link(void) const ; /// Deletes all the requests of #reference_point @@ -89,10 +89,10 @@ inline const Direction& CalibrationRequest::get_direction(void) const /* *** Write accessors *** */ -inline void CalibrationRequest::set_reference_point( - const ReferencePoint *_rp) +inline void CalibrationRequest:: +set_reference_point(ReferencePoint *const _rp) { - reference_point = const_cast(_rp) ; + reference_point = _rp ; } diff --git a/owlps-positioner/cartographyalgorithm.hh b/owlps-positioner/cartographyalgorithm.hh index 655b763..b367549 100644 --- a/owlps-positioner/cartographyalgorithm.hh +++ b/owlps-positioner/cartographyalgorithm.hh @@ -28,8 +28,7 @@ public: /** @name Operations */ //@{ Result compute(const Request &request) ; - virtual const ReferencePoint& select_point( - const Request &request) = 0 ; + virtual const ReferencePoint& select_point(const Request &request) = 0 ; //@} } ; diff --git a/owlps-positioner/inputmedium.cc b/owlps-positioner/inputmedium.cc index 8c1571b..bd54a6d 100644 --- a/owlps-positioner/inputmedium.cc +++ b/owlps-positioner/inputmedium.cc @@ -85,11 +85,13 @@ void InputMedium::clear_current_request() /** - * The `position` argument can be changed by this function. + * The `position` argument can be modified by this function. */ void InputMedium:: -fill_calibration_request_data(const string &mac_mobile, Point3D &position, - const Direction &direction, uint8_t type) +fill_calibration_request_data(const string &mac_mobile, + Point3D &position, + const Direction &direction, + const uint8_t type) { // We set the real coordinates (if found) for non-calibration requests if (type != OWL_REQUEST_CALIBRATION && @@ -155,8 +157,7 @@ fill_calibration_request_data(const string &mac_mobile, Point3D &position, } -void InputMedium:: -current_request_to_calibration_request( +void InputMedium::current_request_to_calibration_request( const ReferencePoint *const reference_point, const Direction &direction, const uint_fast8_t request_type) @@ -165,7 +166,8 @@ current_request_to_calibration_request( dynamic_cast(current_request) ; if (calibration_request != NULL) { - calibration_request->set_reference_point(reference_point) ; + calibration_request->set_reference_point( + const_cast(reference_point)) ; calibration_request->set_direction(direction) ; calibration_request->set_type(request_type) ; return ; diff --git a/owlps-positioner/inputmedium.hh b/owlps-positioner/inputmedium.hh index 68b0dee..bee3b3f 100644 --- a/owlps-positioner/inputmedium.hh +++ b/owlps-positioner/inputmedium.hh @@ -43,7 +43,7 @@ protected: void fill_calibration_request_data(const std::string &mac_mobile, Point3D &position, const Direction &direction, - uint8_t type) ; + const uint8_t type) ; //@} public: @@ -77,7 +77,7 @@ public: void current_request_to_calibration_request( const ReferencePoint *const reference_point, const Direction &direction, - uint_fast8_t request_type) ; + const uint_fast8_t request_type) ; /// Clears (reallocates to Request if needed) #current_request void clear_current_request(void) ; diff --git a/owlps-positioner/measurement.cc b/owlps-positioner/measurement.cc index 2b3a102..a271d06 100644 --- a/owlps-positioner/measurement.cc +++ b/owlps-positioner/measurement.cc @@ -43,7 +43,7 @@ Measurement::~Measurement() * @returns The SS of the packet number `pkt_id.` * @returns 0 if the packet ID does not exist in the SS list. */ -ss_t Measurement::get_ss(pkt_id_t pkt_id) const +ss_t Measurement::get_ss(const pkt_id_t pkt_id) const { std::map::const_iterator ss = ss_list.find(pkt_id) ; if (ss == ss_list.end()) @@ -194,7 +194,7 @@ float Measurement::similarity(const Measurement &source) const unsigned int Measurement:: -nb_in_interval(const Measurement &source, float bound) const +nb_in_interval(const Measurement &source, const float bound) const { unsigned int nb_values = 0 ; @@ -223,7 +223,7 @@ void Measurement::recalculate_average() } -void Measurement::update_average(ss_t ss_dbm) +void Measurement::update_average(const ss_t ss_dbm) { ++variance_size ; assert(variance_size <= ss_list.size()) ; diff --git a/owlps-positioner/measurement.hh b/owlps-positioner/measurement.hh index 54522d4..58c0970 100644 --- a/owlps-positioner/measurement.hh +++ b/owlps-positioner/measurement.hh @@ -29,7 +29,7 @@ class Measurement { protected: /// The CapturePoint that performed the measurement - CapturePoint *cp ; + const CapturePoint *cp ; /// List of signal strengths captured (in dBm) std::map ss_list ; /// Average of all the captured signal strengths (dBm) @@ -56,17 +56,17 @@ protected: /// Recalculates entirely the average and variance from #ss_list void recalculate_average(void) ; /// Update the average and variance with a new SS - void update_average(ss_t ss_dbm) ; + void update_average(const ss_t ss_dbm) ; /// Counts the number of SS of source that are within the interval /// [average_dbm-bound;average_dbm+bound] unsigned int nb_in_interval( - const Measurement &source, float bound) const ; + const Measurement &source, const float bound) const ; //@} public: - Measurement(const CapturePoint *_cp = NULL): - cp(const_cast(_cp)), average_dbm(0), + Measurement(const CapturePoint *const _cp = NULL): + cp(_cp), average_dbm(0), average_mw(0), variance_mw(0), variance_dbm(0), variance_mw_m2(0), variance_dbm_m2(0), variance_size(0) {} @@ -81,25 +81,25 @@ public: /** @name Read accessors */ //@{ /// Returns the CapturePoint associated with the Measurement - CapturePoint* get_cp() const ; + const CapturePoint* get_cp(void) const ; /// Returns the packet number `pkt_id` - ss_t get_ss(pkt_id_t pkt_id) const ; + ss_t get_ss(const pkt_id_t pkt_id) const ; /// Returns the mean of the SS list, in dBm - float get_average_dbm() const ; + float get_average_dbm(void) const ; /// Returns the variance of the SS list - float get_variance_mw() const ; + float get_variance_mw(void) const ; /// Returns the standard deviation of the SS list (mW) - float get_std_deviation_mw() const ; + float get_std_deviation_mw(void) const ; /// Returns the standard deviation of the SS list (dBm) - float get_std_deviation_dbm() const ; + float get_std_deviation_dbm(void) const ; /// Returns the number of SS in the SS list - int get_nb_ss() const ; + int get_nb_ss(void) const ; //@} /** @name Write accessors */ //@{ /// Associate the Measurement with a CapturePoint - void set_cp(const CapturePoint *_cp) ; + void set_cp(const CapturePoint *const _cp) ; /// Adds a signal strength (in dBm) to #ss_list void add_ss(const pkt_id_t packet_id, const ss_t ss_dbm) ; /// Adds several signal strengths (in dBm) to #ss_list @@ -147,7 +147,7 @@ public: /* *** Read accessors *** */ -inline CapturePoint* Measurement::get_cp() const +inline const CapturePoint* Measurement::get_cp() const { return cp ; } @@ -187,9 +187,9 @@ inline int Measurement::get_nb_ss() const /* *** Write accessors *** */ -inline void Measurement::set_cp(const CapturePoint *_cp) +inline void Measurement::set_cp(const CapturePoint *const _cp) { - cp = const_cast(_cp) ; + cp = _cp ; } diff --git a/owlps-positioner/minmax.cc b/owlps-positioner/minmax.cc index cdd1ec7..1954c40 100644 --- a/owlps-positioner/minmax.cc +++ b/owlps-positioner/minmax.cc @@ -20,7 +20,7 @@ using namespace std ; Point3D MinMax::trilaterate( - const unordered_map &_cp_distances) + const unordered_map &_cp_distances) { min = INFINITE ; centre = start ; @@ -36,7 +36,7 @@ Point3D MinMax::trilaterate( Point3D MinMax::trilaterate_2d( - const unordered_map &_cp_distances, float z) + const unordered_map &_cp_distances, float z) { min = INFINITE ; centre = start ; @@ -50,11 +50,10 @@ Point3D MinMax::trilaterate_2d( } -void MinMax::iterate(float x, float y, float z) +void MinMax::iterate(const float x, const float y, const float z) { float d_max = 0 ; - for (unordered_map::const_iterator i = - cp_distances->begin() ; i != cp_distances->end() ; ++i) + for (auto i = cp_distances->begin() ; i != cp_distances->end() ; ++i) { float dist = Point3D(x, y, z).distance_to_sphere( diff --git a/owlps-positioner/minmax.hh b/owlps-positioner/minmax.hh index cdf7600..36a5dbb 100644 --- a/owlps-positioner/minmax.hh +++ b/owlps-positioner/minmax.hh @@ -23,9 +23,9 @@ class MinMax: public TrilaterationMethod private: float min ; Point3D centre ; - std::unordered_map const *cp_distances ; + std::unordered_map const *cp_distances ; - void iterate(float x, float y, float z) ; + void iterate(const float x, const float y, const float z) ; protected: const Point3D start ; @@ -45,9 +45,9 @@ public: ~MinMax(void) {} Point3D trilaterate( - const std::unordered_map &_cp_distances) ; + const std::unordered_map &_cp_distances) ; Point3D trilaterate_2d( - const std::unordered_map &_cp_distances, + const std::unordered_map &_cp_distances, float z) ; } ; diff --git a/owlps-positioner/outputcsv.hh b/owlps-positioner/outputcsv.hh index fe056a1..ff153f6 100644 --- a/owlps-positioner/outputcsv.hh +++ b/owlps-positioner/outputcsv.hh @@ -35,10 +35,4 @@ public: void write(const ResultList &results) ; } ; - - -/* *** Operations *** */ - - - #endif // _OWLPS_POSITIONING_OUTPUTCSV_HH_ diff --git a/owlps-positioner/posutil.hh b/owlps-positioner/posutil.hh index bf6f752..4bc66cb 100644 --- a/owlps-positioner/posutil.hh +++ b/owlps-positioner/posutil.hh @@ -41,7 +41,8 @@ public: /// Returns the degree value of `radians` static double rad2deg(const double &radians) ; /// Checks if `value` is in the interval [center-width;center+width] - static bool is_in_interval(float center, float bound, float value) ; + static bool is_in_interval(const float center, const float bound, + const float value) ; //@} /** @name Measurements */ @@ -98,7 +99,7 @@ hash_combine(std::size_t &seed, const T &v) * @returns `false` if value does not belong to the interval. */ inline bool PosUtil:: -is_in_interval(float center, float bound, float value) +is_in_interval(const float center, const float bound, const float value) { if (bound == 0) return value == center ; diff --git a/owlps-positioner/referencepoint.cc b/owlps-positioner/referencepoint.cc index 90ea6dd..b898295 100644 --- a/owlps-positioner/referencepoint.cc +++ b/owlps-positioner/referencepoint.cc @@ -124,7 +124,7 @@ get_requests(const string &mac_transmitter) const /* *** Write accessors *** */ -void ReferencePoint::delete_request(const CalibrationRequest *r) +void ReferencePoint::delete_request(const CalibrationRequest *const r) { for (vector::iterator i = requests.begin() ; i != requests.end() ; ++i) @@ -255,9 +255,9 @@ friis_index_for_cp(const string &cp_mac) const * ReferencePoint. To obtain the real (averaged) Friis index, one * has to divide the returned sum by the number of indexes. * - * @param cp The CapturePoint to work on. - * @param const_term The "constant" part of the computation. - * @param nb_indexes (result) The number of indexes computed. + * @param[in] cp The CapturePoint to work on. + * @param[in] const_term The "constant" part of the computation. + * @param[out] nb_indexes The number of indexes computed. * * @returns The sum of all Friis indexes for the CapturePoint. * @returns 0 if the CP is unknown at this ReferencePoint. @@ -319,7 +319,7 @@ float ReferencePoint::friis_indexes_for_cp( * is no packet with the wanted ID. */ float ReferencePoint:: -friis_index_for_cp(const string &cp_mac, pkt_id_t pkt_id) const +friis_index_for_cp(const string &cp_mac, const pkt_id_t pkt_id) const { const CapturePoint &cp = Stock::get_cp(cp_mac) ; double const_term = cp.friis_constant_term() ; diff --git a/owlps-positioner/referencepoint.hh b/owlps-positioner/referencepoint.hh index 6bccd1e..1361b63 100644 --- a/owlps-positioner/referencepoint.hh +++ b/owlps-positioner/referencepoint.hh @@ -70,9 +70,9 @@ public: /** @name Write accessors */ //@{ /// Adds a Request to the [requests' list](@ref #requests) - void add_request(const CalibrationRequest *r) ; + void add_request(const CalibrationRequest *const r) ; /// Deletes a Request from the [requests' list](@ref #requests) - void delete_request(const CalibrationRequest *r) ; + void delete_request(const CalibrationRequest *const r) ; /// Deletes all the requests contained in #requests void delete_requests(void) ; /// Deletes the requests that are not sent by a CP @@ -91,7 +91,7 @@ public: int &nb_indexes) const ; /// Computes the Friis index for the given CapturePoint and packet ID float friis_index_for_cp( - const std::string &cp_mac, pkt_id_t pkt_id) const ; + const std::string &cp_mac, const pkt_id_t pkt_id) const ; //@} /** @name Operators */ diff --git a/owlps-positioner/request.cc b/owlps-positioner/request.cc index dc7e7a4..b7ce604 100644 --- a/owlps-positioner/request.cc +++ b/owlps-positioner/request.cc @@ -31,7 +31,7 @@ Request::Request( const unordered_map &_measurements ): type(OWL_REQUEST_UNDEFINED), nb_packets(1), - mobile(const_cast(_mobile)), time_sent(_time_sent), + mobile(_mobile), time_sent(_time_sent), measurements(_measurements), real_position(NULL) { received_now() ; diff --git a/owlps-positioner/request.hh b/owlps-positioner/request.hh index 3e41c20..de7b352 100644 --- a/owlps-positioner/request.hh +++ b/owlps-positioner/request.hh @@ -36,7 +36,7 @@ protected: /// Number of packets sent by the mobile for this request pkt_id_t nb_packets ; /// The mobile that sent the request - Mobile *mobile ; + const Mobile *mobile ; /// Local date of the request on the mobile Timestamp time_sent ; /// Date at which we received the request from the aggregator @@ -66,7 +66,7 @@ protected: typedef std::unordered_map measurements_list ; public: - Request(const Mobile *_mobile = NULL, + Request(const Mobile *const _mobile = NULL, const Timestamp &_time_sent = Timestamp(), const std::unordered_map &_measurements = measurements_list()) ; @@ -86,7 +86,7 @@ public: //@{ uint_fast8_t get_type(void) const ; uint_fast16_t get_nb_packets(void) const ; - Mobile* get_mobile(void) const ; + const Mobile* get_mobile(void) const ; const Timestamp& get_time_sent(void) const ; const Timestamp& get_time_received(void) const ; /// Returns all the measurements @@ -102,7 +102,7 @@ public: //@{ void set_type(const uint_fast8_t _type) ; void set_nb_packets(const uint_fast16_t _nb_packets) ; - void set_mobile(const Mobile *_mobile) ; + void set_mobile(const Mobile *const _mobile) ; void set_time_sent(const Timestamp &_time_sent) ; void received_now(void) ; void set_measurements(const std::unordered_map @@ -154,7 +154,7 @@ inline uint_fast16_t Request::get_nb_packets() const } -inline Mobile* Request::get_mobile() const +inline const Mobile* Request::get_mobile() const { return mobile ; } @@ -201,9 +201,9 @@ inline void Request::set_nb_packets(const uint_fast16_t _nb_packets) } -inline void Request::set_mobile(const Mobile *_mobile) +inline void Request::set_mobile(const Mobile *const _mobile) { - mobile = const_cast(_mobile) ; + mobile = _mobile ; } diff --git a/owlps-positioner/result.cc b/owlps-positioner/result.cc index c20669e..743c25f 100644 --- a/owlps-positioner/result.cc +++ b/owlps-positioner/result.cc @@ -31,7 +31,7 @@ using namespace std ; * The error (distance between _position and _real_position) is * computed automatically. */ -Result::Result(const Request *_request, +Result::Result(const Request *const _request, const std::string &_algorithm, const Point3D &_position, const Point3D &real_position): diff --git a/owlps-positioner/result.hh b/owlps-positioner/result.hh index d427d91..3765b8f 100644 --- a/owlps-positioner/result.hh +++ b/owlps-positioner/result.hh @@ -36,14 +36,14 @@ protected: float error ; public: - Result(const Request *_request = NULL, + Result(const Request *const _request = NULL, const std::string &_algorithm = "UnknownAlgorithm"): request(_request), algorithm(_algorithm), error(-1) {} - Result(const Request *_request, const std::string &_algorithm, + Result(const Request *const _request, const std::string &_algorithm, const Point3D &_position): request(_request), algorithm(_algorithm), position(_position), error(-1) {} - Result(const Request *_request, const std::string &_algorithm, + Result(const Request *const _request, const std::string &_algorithm, const Point3D &_position, const Point3D &real_position) ; ~Result(void) {} diff --git a/owlps-positioner/resultlist.hh b/owlps-positioner/resultlist.hh index b398693..8d0bb03 100644 --- a/owlps-positioner/resultlist.hh +++ b/owlps-positioner/resultlist.hh @@ -26,13 +26,13 @@ class Request ; class ResultList { protected: - Request *request ; + const Request *request ; std::vector results ; public: - ResultList(const Request *_request = NULL, + ResultList(const Request *const _request = NULL, const std::vector &_results = std::vector()): - request(const_cast(_request)), results(_results) {} + request(_request), results(_results) {} ResultList(const ResultList &source): request(source.request), results(source.results) {} ~ResultList(void) ; diff --git a/owlps-positioner/stock.cc b/owlps-positioner/stock.cc index 2c6bd3e..c6573e8 100644 --- a/owlps-positioner/stock.cc +++ b/owlps-positioner/stock.cc @@ -133,7 +133,7 @@ find_create_waypoint(const Point3D &point) void Stock::waypoint_remove_building(const Waypoint &point, - const Building *building) + Building *const building) { unordered_map::iterator i = waypoints.find(point) ; @@ -721,7 +721,7 @@ delete_calibration_request(const CalibrationRequest &request) /** * @param timeout The maximum age of the calibration requests (seconds). */ -void Stock::delete_calibration_requests_older_than(int timeout) +void Stock::delete_calibration_requests_older_than(const int timeout) { assert(timeout > 0) ; diff --git a/owlps-positioner/stock.hh b/owlps-positioner/stock.hh index 5581a26..42e129b 100644 --- a/owlps-positioner/stock.hh +++ b/owlps-positioner/stock.hh @@ -108,7 +108,7 @@ public: /// Deletes a Building from the building list of a Waypoint; deletes /// the Waypoint if it is not linked to any Building any more static void waypoint_remove_building(const Waypoint &point, - const Building *building) ; + Building *const building) ; //@} /** @name Mobile operations */ @@ -192,7 +192,7 @@ public: const CalibrationRequest &request) ; /// Deletes the calibration requests that are older than `timeout` /// seconds - static void delete_calibration_requests_older_than(int timeout) ; + static void delete_calibration_requests_older_than(const int timeout) ; /// Searches for a CalibrationRequest and adds it if it does not exist static const CalibrationRequest& find_create_calibration_request(const CalibrationRequest &request) ; diff --git a/owlps-positioner/tests/building_test.hh b/owlps-positioner/tests/building_test.hh index 531c293..6bcfd21 100644 --- a/owlps-positioner/tests/building_test.hh +++ b/owlps-positioner/tests/building_test.hh @@ -56,8 +56,8 @@ public: Stock::find_create_waypoint(Waypoint(&b2, 43,45,909)) ; const Waypoint &wp2 = Stock::find_create_waypoint(Waypoint(&b2, 12,78,2)) ; - b2.add_waypoint(&wp1) ; - b2.add_waypoint(&wp2) ; + b2.add_waypoint(const_cast(&wp1)) ; + b2.add_waypoint(const_cast(&wp2)) ; waypoints1.insert(const_cast(&wp1)) ; waypoints1.insert(const_cast(&wp2)) ; TS_ASSERT_EQUALS(b2.get_waypoints(), waypoints1) ; diff --git a/owlps-positioner/tests/minmax_test.hh b/owlps-positioner/tests/minmax_test.hh index 6d72be6..3424a02 100644 --- a/owlps-positioner/tests/minmax_test.hh +++ b/owlps-positioner/tests/minmax_test.hh @@ -30,7 +30,7 @@ public: ap2(Point3D(10,0,0)), ap3(Point3D(0,10,0)), ap4(Point3D(5,5,4)) ; - std::unordered_map ap_distances ; + std::unordered_map ap_distances ; ap_distances[&ap1] = 7.071 ; ap_distances[&ap2] = 7.071 ; ap_distances[&ap3] = 7.071 ; diff --git a/owlps-positioner/tests/stock_test.hh b/owlps-positioner/tests/stock_test.hh index 7cd72f5..d8b932e 100644 --- a/owlps-positioner/tests/stock_test.hh +++ b/owlps-positioner/tests/stock_test.hh @@ -53,13 +53,14 @@ public: { Point3D coordinates(42,21,98) ; const Building &building = Stock::find_create_building("Build") ; - Waypoint wp1(&building, coordinates) ; + Waypoint wp1(const_cast(&building), coordinates) ; const Waypoint &wp1_ref1 = Stock::find_create_waypoint(wp1), &wp1_ref2 = Stock::find_create_waypoint(coordinates) ; TS_ASSERT_EQUALS(&wp1_ref1, &wp1_ref2) ; - Stock::waypoint_remove_building(wp1_ref1, &building) ; + Stock::waypoint_remove_building(wp1_ref1, + const_cast(&building)) ; // TODO: test if the waypoint was removed (needs a function // Stock::get_waypoint()). } diff --git a/owlps-positioner/textfilereader.cc b/owlps-positioner/textfilereader.cc index e657a90..7247be8 100644 --- a/owlps-positioner/textfilereader.cc +++ b/owlps-positioner/textfilereader.cc @@ -63,7 +63,7 @@ TextFileReader::~TextFileReader() * Tabs and spaces at the begining of a line are deleted. * If the first non-blank character of a line is a #, then the line is * skipped (note that comments at the end of a line are *not* handled). - * @param text Output argument; unchanged in case of error. + * @param[out] text Output argument; unchanged in case of error. * @returns `false` in case of error, `true` else. */ bool TextFileReader::read_nonblank_line(string &text) @@ -85,7 +85,8 @@ bool TextFileReader::read_nonblank_line(string &text) /** - * @returns The string read, or an empty string in case of error. + * @param[out] text The string read. + * @returns `true` in case of success, `false` in case of error. */ bool TextFileReader::read_line(string &text) { diff --git a/owlps-positioner/trilaterationalgorithm.hh b/owlps-positioner/trilaterationalgorithm.hh index da33805..e4ff9c3 100644 --- a/owlps-positioner/trilaterationalgorithm.hh +++ b/owlps-positioner/trilaterationalgorithm.hh @@ -24,15 +24,15 @@ class TrilaterationAlgorithm: public virtual PositioningAlgorithm protected: const Request *request ; - std::unordered_map cp_distances ; + std::unordered_map cp_distances ; TrilaterationMethod *trilateration_method ; /** @name Operations */ //@{ double make_constant_term(const Measurement &measurement) ; - void compute_cp_distance_circles() ; - Point3D trilaterate() ; - Point3D trilaterate_2d(float z) ; + void compute_cp_distance_circles(void) ; + Point3D trilaterate(void) ; + Point3D trilaterate_2d(const float z) ; //@} public: @@ -55,7 +55,7 @@ inline Point3D TrilaterationAlgorithm::trilaterate() } -inline Point3D TrilaterationAlgorithm::trilaterate_2d(float z) +inline Point3D TrilaterationAlgorithm::trilaterate_2d(const float z) { return trilateration_method->trilaterate_2d(cp_distances, z) ; } diff --git a/owlps-positioner/trilaterationmethod.hh b/owlps-positioner/trilaterationmethod.hh index 479693d..0a7d341 100644 --- a/owlps-positioner/trilaterationmethod.hh +++ b/owlps-positioner/trilaterationmethod.hh @@ -35,12 +35,12 @@ public: /// Selects a point in 3D space virtual Point3D trilaterate( - const std::unordered_map &cp_distances) = 0 ; + const std::unordered_map &cp_distances) = 0 ; /// Selects a point in 2D space, given its vertical coordinate (z) virtual Point3D trilaterate_2d( - const std::unordered_map &cp_distances, - float z) = 0 ; + const std::unordered_map &cp_distances, + const float z) = 0 ; } ; #endif // _OWLPS_POSITIONING_TRILATERATIONMETHOD_HH_ diff --git a/owlps-positioner/userinterface.cc b/owlps-positioner/userinterface.cc index 6203d53..f62a760 100644 --- a/owlps-positioner/userinterface.cc +++ b/owlps-positioner/userinterface.cc @@ -54,7 +54,8 @@ namespace po = boost::program_options ; * @param argc Number of arguments passed to the program. * @param argv Values of the arguments. */ -UserInterface::UserInterface(const int argc, const char **const argv): +UserInterface::UserInterface(const int argc, + const char *const *const argv): cli_argument_count(argc), cli_argument_values(argv) { assert(cli_argument_values) ; diff --git a/owlps-positioner/userinterface.hh b/owlps-positioner/userinterface.hh index b93c833..7528297 100644 --- a/owlps-positioner/userinterface.hh +++ b/owlps-positioner/userinterface.hh @@ -23,7 +23,7 @@ class UserInterface { protected: const int cli_argument_count ; - const char **const cli_argument_values ; + const char *const *const cli_argument_values ; boost::program_options::options_description *cli_options ; boost::program_options::options_description *file_options ; @@ -55,7 +55,7 @@ protected: //@} public: - UserInterface(const int argc, const char **const argv) ; + UserInterface(const int argc, const char *const *const argv) ; ~UserInterface(void) ; } ; diff --git a/owlps-positioner/waypoint.cc b/owlps-positioner/waypoint.cc index 34a6c77..681231f 100644 --- a/owlps-positioner/waypoint.cc +++ b/owlps-positioner/waypoint.cc @@ -31,12 +31,12 @@ using namespace std ; * @param _y Y coordinate. * @param _z Z coordinate. */ -Waypoint::Waypoint(const Building *_b, +Waypoint::Waypoint(Building *const _b, const float &_x, const float &_y, const float &_z ): Point3D(_x, _y, _z) { if (_b != NULL) - buildings.insert(const_cast(_b)) ; + buildings.insert(_b) ; } @@ -45,10 +45,10 @@ Waypoint::Waypoint(const Building *_b, * If it is NULL, #buildings will remain empty. * @param p Coordinates of the Waypoint. */ -Waypoint::Waypoint(const Building *_b, const Point3D &p): Point3D(p) +Waypoint::Waypoint(Building *const _b, const Point3D &p): Point3D(p) { if (_b != NULL) - buildings.insert(const_cast(_b)) ; + buildings.insert(_b) ; } diff --git a/owlps-positioner/waypoint.hh b/owlps-positioner/waypoint.hh index ef5bb17..5b29d07 100644 --- a/owlps-positioner/waypoint.hh +++ b/owlps-positioner/waypoint.hh @@ -37,10 +37,10 @@ protected: std::unordered_set buildings ; public: - Waypoint(const Building *_b = NULL, const float &_x = 0, + Waypoint(Building *const _b = NULL, const float &_x = 0, const float &_y = 0, const float &_z = 0) ; - Waypoint(const Building *_b, const Point3D &p) ; + Waypoint(Building *const _b, const Point3D &p) ; Waypoint(const Point3D &p): Point3D(p) {} @@ -58,11 +58,11 @@ public: /** @name Write accessors */ //@{ /// Adds a Building to the [buildings' list](@ref #buildings) - void add_building(const Building *_b) ; + void add_building(Building *const _b) ; /// Adds the Building list of `source` to #buildings void add_buildings(const Waypoint &source) ; /// Removes a Building from #buildings - void remove_building(const Building *_b) ; + void remove_building(Building *const _b) ; //@} /** @name Operators */ @@ -113,17 +113,10 @@ Waypoint::get_buildings() const * the Waypoint destruction (do *not* pass a pointer to a local * variable!). */ -inline void Waypoint::add_building(const Building *_b) +inline void Waypoint::add_building(Building *const _b) { if (_b != NULL) - buildings.insert(const_cast(_b)) ; -} - - -inline void Waypoint::remove_building(const Building *_b) -{ - if (_b != NULL) - buildings.erase(const_cast(_b)) ; + buildings.insert(_b) ; } @@ -133,6 +126,13 @@ inline void Waypoint::add_buildings(const Waypoint &source) } +inline void Waypoint::remove_building(Building *const _b) +{ + if (_b != NULL) + buildings.erase(_b) ; +} + + /* *** Operators *** */ diff --git a/owlps-positioner/wifidevice.hh b/owlps-positioner/wifidevice.hh index e5e2cc4..b72c5ce 100644 --- a/owlps-positioner/wifidevice.hh +++ b/owlps-positioner/wifidevice.hh @@ -60,8 +60,8 @@ public: //@{ void set_ip_addr(const std::string &_ip_addr) ; void set_mac_addr(const std::string &_mac_addr) ; - void set_antenna_gain(float _antenna_gain) ; - void set_trx_power(float _trx_power) ; + void set_antenna_gain(const float _antenna_gain) ; + void set_trx_power(const float _trx_power) ; //@} /** @name Operators */ @@ -140,13 +140,13 @@ inline void WifiDevice::set_mac_addr(const std::string &_mac_addr) } -inline void WifiDevice::set_antenna_gain(float _antenna_gain) +inline void WifiDevice::set_antenna_gain(const float _antenna_gain) { antenna_gain = _antenna_gain ; } -inline void WifiDevice::set_trx_power(float _trx_power) +inline void WifiDevice::set_trx_power(const float _trx_power) { trx_power = _trx_power ; }