[Positioning] Use new exceptions in posexcept
Replace use of standard exceptions (std::out_of_range, std::runtime_error) by new exceptions in posexcept.
This commit is contained in:
parent
fc1ceb25c7
commit
b6ab3c841d
|
@ -1,5 +1,6 @@
|
||||||
#include "inputcsv.hh"
|
#include "inputcsv.hh"
|
||||||
#include "posutil.hh"
|
#include "posutil.hh"
|
||||||
|
#include "posexcept.hh"
|
||||||
#include "stock.hh"
|
#include "stock.hh"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -23,7 +24,7 @@ using namespace boost ;
|
||||||
/**
|
/**
|
||||||
* Prepares the InputCSV to read a CSV file.
|
* Prepares the InputCSV to read a CSV file.
|
||||||
* @param filename The name of the file to open.
|
* @param filename The name of the file to open.
|
||||||
* @throw runtime_error if the file cannot be opened.
|
* @throw error_opening_input_file if the file cannot be opened.
|
||||||
*/
|
*/
|
||||||
InputCSV::InputCSV(const string &filename)
|
InputCSV::InputCSV(const string &filename)
|
||||||
{
|
{
|
||||||
|
@ -31,8 +32,7 @@ InputCSV::InputCSV(const string &filename)
|
||||||
|
|
||||||
input_file.open(input_file_name.c_str()) ;
|
input_file.open(input_file_name.c_str()) ;
|
||||||
if (! input_file)
|
if (! input_file)
|
||||||
throw runtime_error("Error opening input file « " +
|
throw error_opening_input_file(input_file_name) ;
|
||||||
input_file_name + " »!") ;
|
|
||||||
|
|
||||||
read_next_line() ;
|
read_next_line() ;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ const Request& InputCSV::get_next_request()
|
||||||
{
|
{
|
||||||
Stock::get_mobile(*ti) ;
|
Stock::get_mobile(*ti) ;
|
||||||
}
|
}
|
||||||
catch (out_of_range e)
|
catch (element_not_found e)
|
||||||
{
|
{
|
||||||
Stock::getw_mobile(*ti).set_mac_addr(*ti) ;
|
Stock::getw_mobile(*ti).set_mac_addr(*ti) ;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ const Request& InputCSV::get_next_request()
|
||||||
{
|
{
|
||||||
Stock::get_ap(mac_ap) ;
|
Stock::get_ap(mac_ap) ;
|
||||||
}
|
}
|
||||||
catch (out_of_range e)
|
catch (element_not_found e)
|
||||||
{
|
{
|
||||||
Stock::getw_ap(mac_ap).set_mac_addr(mac_ap) ;
|
Stock::getw_ap(mac_ap).set_mac_addr(mac_ap) ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,24 @@
|
||||||
using namespace std ;
|
using namespace std ;
|
||||||
|
|
||||||
|
|
||||||
|
element_not_found::
|
||||||
|
element_not_found(const string &_explanation) throw():
|
||||||
|
explanation(_explanation) {}
|
||||||
|
|
||||||
|
|
||||||
|
const char* element_not_found::what() const throw()
|
||||||
|
{
|
||||||
|
string message = "Element not found in collection: " + explanation ;
|
||||||
|
return message.c_str() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param _medium_name The medium that is unknown
|
* @param _medium_name The medium that is unknown
|
||||||
*/
|
*/
|
||||||
input_medium_type_unknown::
|
input_medium_type_unknown::
|
||||||
input_medium_type_unknown(const string &_medium_name) throw()
|
input_medium_type_unknown(const string &_medium_name) throw():
|
||||||
{
|
medium_name(_medium_name) {}
|
||||||
medium_name = _medium_name ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char* input_medium_type_unknown::what() const throw()
|
const char* input_medium_type_unknown::what() const throw()
|
||||||
|
@ -37,3 +47,16 @@ const char* no_input_csv_file::what() const throw()
|
||||||
{
|
{
|
||||||
return "No input CSV file specified in the configuration!" ;
|
return "No input CSV file specified in the configuration!" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
error_opening_input_file::
|
||||||
|
error_opening_input_file(const string &_file_name) throw():
|
||||||
|
file_name(_file_name) {}
|
||||||
|
|
||||||
|
|
||||||
|
const char* error_opening_input_file::what() const throw()
|
||||||
|
{
|
||||||
|
string message = "Error opening input file « " +
|
||||||
|
file_name + " »!" ;
|
||||||
|
return message.c_str() ;
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,18 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
class element_not_found: public std::exception
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::string explanation ;
|
||||||
|
|
||||||
|
public:
|
||||||
|
element_not_found(const std::string &_explanation) throw() ;
|
||||||
|
~element_not_found(void) throw() {}
|
||||||
|
const char* what(void) const throw() ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
class input_medium_type_unknown: public std::exception
|
class input_medium_type_unknown: public std::exception
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -37,4 +49,17 @@ public:
|
||||||
const char* what() const throw() ;
|
const char* what() const throw() ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
class error_opening_input_file: public std::exception
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::string file_name ;
|
||||||
|
|
||||||
|
public:
|
||||||
|
error_opening_input_file(const std::string &_file_name) throw() ;
|
||||||
|
~error_opening_input_file(void) throw() {}
|
||||||
|
const char* what(void) const throw() ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
#endif // _OWLPS_POSITIONING_POSEXCEPT_HH_
|
#endif // _OWLPS_POSITIONING_POSEXCEPT_HH_
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "stock.hh"
|
#include "stock.hh"
|
||||||
|
#include "posexcept.hh"
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
using namespace std ;
|
using namespace std ;
|
||||||
using std::tr1::unordered_map ;
|
using std::tr1::unordered_map ;
|
||||||
|
@ -22,7 +21,7 @@ unordered_map<string, AccessPoint> Stock::aps ;
|
||||||
* @param mac The MAC address of the Mobile to search for.
|
* @param mac The MAC address of the Mobile to search for.
|
||||||
* It must be a valid MAC address, as no check is performed.
|
* It must be a valid MAC address, as no check is performed.
|
||||||
* @return A const reference to the Mobile.
|
* @return A const reference to the Mobile.
|
||||||
* @throw std::out_of_range is thrown if the Mobile corresponding
|
* @throw element_not_found is thrown if the Mobile corresponding
|
||||||
* to \em mac does not exist.
|
* to \em mac does not exist.
|
||||||
*/
|
*/
|
||||||
const Mobile& Stock::get_mobile(const string &mac)
|
const Mobile& Stock::get_mobile(const string &mac)
|
||||||
|
@ -30,7 +29,7 @@ const Mobile& Stock::get_mobile(const string &mac)
|
||||||
unordered_map<string, Mobile>::const_iterator i = mobiles.find(mac) ;
|
unordered_map<string, Mobile>::const_iterator i = mobiles.find(mac) ;
|
||||||
if (i != mobiles.end())
|
if (i != mobiles.end())
|
||||||
return i->second ;
|
return i->second ;
|
||||||
throw out_of_range("No Mobile with MAC address « " + mac + " »!") ;
|
throw element_not_found("No Mobile with MAC address « " + mac + " »!") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,7 +37,7 @@ const Mobile& Stock::get_mobile(const string &mac)
|
||||||
* @param mac The MAC address of the AccessPoint to search for.
|
* @param mac The MAC address of the AccessPoint to search for.
|
||||||
* It must be a valid MAC address, as no check is performed.
|
* It must be a valid MAC address, as no check is performed.
|
||||||
* @return A const reference to the AccessPoint.
|
* @return A const reference to the AccessPoint.
|
||||||
* @throw std::out_of_range is thrown if the AccessPoint corresponding
|
* @throw element_not_found is thrown if the AccessPoint corresponding
|
||||||
* to \em mac does not exist.
|
* to \em mac does not exist.
|
||||||
*/
|
*/
|
||||||
const AccessPoint& Stock::get_ap(const string &mac)
|
const AccessPoint& Stock::get_ap(const string &mac)
|
||||||
|
@ -46,7 +45,8 @@ const AccessPoint& Stock::get_ap(const string &mac)
|
||||||
unordered_map<string, AccessPoint>::const_iterator i = aps.find(mac) ;
|
unordered_map<string, AccessPoint>::const_iterator i = aps.find(mac) ;
|
||||||
if (i != aps.end())
|
if (i != aps.end())
|
||||||
return i->second ;
|
return i->second ;
|
||||||
throw out_of_range("No AccessPoint with MAC address « " + mac + " »!") ;
|
throw element_not_found("No AccessPoint with MAC address « " +
|
||||||
|
mac + " »!") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <cxxtest/TestSuite.h>
|
#include <cxxtest/TestSuite.h>
|
||||||
|
|
||||||
#include "stock.hh"
|
#include "stock.hh"
|
||||||
|
#include "posexcept.hh"
|
||||||
|
|
||||||
class Stock_test: public CxxTest::TestSuite
|
class Stock_test: public CxxTest::TestSuite
|
||||||
{
|
{
|
||||||
|
@ -13,9 +14,9 @@ public:
|
||||||
|
|
||||||
// Non-existing elements
|
// Non-existing elements
|
||||||
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
|
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
|
||||||
std::out_of_range) ;
|
element_not_found) ;
|
||||||
TS_ASSERT_THROWS(Stock::get_ap("aa:bb:cc:dd:ee:ff"),
|
TS_ASSERT_THROWS(Stock::get_ap("aa:bb:cc:dd:ee:ff"),
|
||||||
std::out_of_range) ;
|
element_not_found) ;
|
||||||
|
|
||||||
// Creation of empty elements
|
// Creation of empty elements
|
||||||
Mobile m1 ;
|
Mobile m1 ;
|
||||||
|
@ -38,17 +39,17 @@ public:
|
||||||
// clear()
|
// clear()
|
||||||
Stock::clear() ;
|
Stock::clear() ;
|
||||||
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
|
TS_ASSERT_THROWS(Stock::get_mobile("aa:bb:cc:dd:ee:ff"),
|
||||||
std::out_of_range) ;
|
element_not_found) ;
|
||||||
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:01"),
|
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:01"),
|
||||||
std::out_of_range) ;
|
element_not_found) ;
|
||||||
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:02"),
|
TS_ASSERT_THROWS(Stock::get_mobile("00:00:00:00:01:02"),
|
||||||
std::out_of_range) ;
|
element_not_found) ;
|
||||||
TS_ASSERT_THROWS(Stock::get_ap("aa:bb:cc:dd:ee:ff"),
|
TS_ASSERT_THROWS(Stock::get_ap("aa:bb:cc:dd:ee:ff"),
|
||||||
std::out_of_range) ;
|
element_not_found) ;
|
||||||
TS_ASSERT_THROWS(Stock::get_ap("00:00:00:00:02:01"),
|
TS_ASSERT_THROWS(Stock::get_ap("00:00:00:00:02:01"),
|
||||||
std::out_of_range) ;
|
element_not_found) ;
|
||||||
TS_ASSERT_THROWS(Stock::get_ap("00:00:00:00:02:02"),
|
TS_ASSERT_THROWS(Stock::get_ap("00:00:00:00:02:02"),
|
||||||
std::out_of_range) ;
|
element_not_found) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
Loading…
Reference in New Issue