From 6ad31f9af4cc4d85a03a2ef7df5780c83b6ed8f0 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 17 Feb 2010 17:33:26 +0100 Subject: [PATCH] [Positioning] InputCSV: prepare handling CalibrationRequest InputMedium: - Split into two files (inputmedium.{hh,cc}). - Add polymorphic handling of CalibrationRequest. - Write unit tests. InputCSV: - Use new code of InputMedium to handle calibration requests. - We detect if the read request is a calibration request, but specific attributes are not initialised. --- owlps-positioning/Makefile | 10 +++---- owlps-positioning/inputcsv.cc | 26 +++++++----------- owlps-positioning/inputmedium.cc | 47 ++++++++++++++++++++++++++++++++ owlps-positioning/inputmedium.hh | 22 ++++----------- 4 files changed, 67 insertions(+), 38 deletions(-) create mode 100644 owlps-positioning/inputmedium.cc diff --git a/owlps-positioning/Makefile b/owlps-positioning/Makefile index cdb77af..43096a1 100644 --- a/owlps-positioning/Makefile +++ b/owlps-positioning/Makefile @@ -33,8 +33,8 @@ OBJ = posutil.o stock.o timestamp.o point3d.o referencepoint.o \ mobile.o measurement.o request.o calibrationrequest.o \ configuration.o userinterface.o input.o \ inputcsv.o inputlogcsv.o -OBJ_NOTEST = posexcept.o -INTERFACES = inputmedium.hh inputlogmedium.hh +OBJ_NOTEST = posexcept.o inputmedium.o +INTERFACES = inputlogmedium.hh TESTS_XX = $(TESTS_DIR)/tests.cc TESTS_OBJ = $(TESTS_DIR)/tests.o @@ -68,7 +68,7 @@ mobile.o: wifidevice.o measurement.o: accesspoint.o request.o: timestamp.o measurement.o calibrationrequest.o: request.o referencepoint.o -inputcsv.o: inputmedium.hh request.o stock.o +inputcsv.o: inputmedium.o request.o stock.o inputlogcsv.o: inputlogmedium.hh request.o input.o: posexcept.o @@ -81,7 +81,7 @@ $(TESTS_XX): $(SOURCE_TESTS) --include=$(TESTUTIL_OBJ:.o=.hh) \ -o $@ $^ -$(TESTS_OBJ): $(TESTS_XX) $(OBJ) $(INCLUDES_TESTS) +$(TESTS_OBJ): $(TESTS_XX) $(OBJ) $(OBJ_NOTEST) $(INCLUDES_TESTS) $(GXX) $(GXXFLAGS) $(TESTSGXXFLAGS) -o $@ -c $< $(TESTS_TARGET): $(TESTS_OBJ) $(OBJ_TESTS) @@ -125,4 +125,4 @@ check: @$(CPPCHECK) \ $(OBJ:.o=.hh) $(OBJ:.o=.cc) \ $(OBJ_NOTEST:.o=.hh) $(OBJ_NOTEST:.o=.cc) \ - $(INTERFACES) + $(INTERFACES) $(TARGET).cc diff --git a/owlps-positioning/inputcsv.cc b/owlps-positioning/inputcsv.cc index de282bc..2f09146 100644 --- a/owlps-positioning/inputcsv.cc +++ b/owlps-positioning/inputcsv.cc @@ -116,12 +116,10 @@ void InputCSV::read_next_line() */ const Request& InputCSV::get_next_request() { - if (eof_close()) - { - // End of file or error: blank current request - current_request->clear() ; - return *current_request ; - } + clear_current_request() ; + + if (eof_close()) // End of file or error + return *current_request ; // Split read string into fields (semicolon-separated) tokenizer > tok( @@ -130,12 +128,8 @@ const Request& InputCSV::get_next_request() tokenizer >::const_iterator ti(tok.begin()) ; // Read Mobile MAC field - if (ti == tok.end()) - { - // Wrong number of fields: blank current request - current_request->clear() ; - return *current_request ; - } + if (ti == tok.end()) // Wrong number of fields + return *current_request ; // If the mobile did not exist, we create it try @@ -167,7 +161,7 @@ const Request& InputCSV::get_next_request() << *ti << " » at line " << current_line_nb << ", field « Timestamp », of input file « " << input_file_name << " »!" << endl ; - current_request->clear() ; // Blank current request + current_request->clear() ; return *current_request ; } @@ -196,7 +190,7 @@ const Request& InputCSV::get_next_request() << current_line_nb << ", position field #" << i << ", of input file « " << input_file_name << " »!" << endl ; - current_request->clear() ; // Blank current request + current_request->clear() ; return *current_request ; } } @@ -222,7 +216,7 @@ const Request& InputCSV::get_next_request() << *ti << " » at line " << current_line_nb << ", field « Direction », of input file « " << input_file_name << " »!" << endl ; - current_request->clear() ; // Blank current request + current_request->clear() ; return *current_request ; } @@ -277,7 +271,7 @@ const Request& InputCSV::get_next_request() read_next_line() ; if (is_calibration_request) - {} // TODO + current_request_to_calibration_request() ; return *current_request ; } diff --git a/owlps-positioning/inputmedium.cc b/owlps-positioning/inputmedium.cc new file mode 100644 index 0000000..5eee7cb --- /dev/null +++ b/owlps-positioning/inputmedium.cc @@ -0,0 +1,47 @@ +#include "inputmedium.hh" +#include "calibrationrequest.hh" + + + +/* *** Constructors *** */ + + +InputMedium::InputMedium() +{ + current_request = new Request() ; + current_line_nb = 0 ; +} + + +InputMedium::~InputMedium() +{ + delete current_request ; +} + + + +/* *** Operations *** */ + +void InputMedium::current_request_to_calibration_request() +{ + if (dynamic_cast(current_request) != NULL) + return ; + + Request *tmp = current_request ; + current_request = NULL ; + current_request = new CalibrationRequest(*tmp) ; + delete tmp ; +} + + +void InputMedium::clear_current_request() +{ + if (dynamic_cast(current_request) == NULL) + current_request->clear() ; + else + { + delete current_request ; + current_request = NULL ; + current_request = new Request() ; + } +} diff --git a/owlps-positioning/inputmedium.hh b/owlps-positioning/inputmedium.hh index a921a9c..6fc5afa 100644 --- a/owlps-positioning/inputmedium.hh +++ b/owlps-positioning/inputmedium.hh @@ -52,28 +52,16 @@ public: */ virtual const Request& get_next_request(void) = 0 ; + /// Converts #current_request into a CalibrationRequest + void current_request_to_calibration_request(void) ; + /// Clears (reallocates to Request if needed) #current_request + void clear_current_request(void) ; + //@} // End Operations } ; -/* *** Constructors *** */ - - -inline InputMedium::InputMedium() -{ - current_request = new Request() ; - current_line_nb = 0 ; -} - - -inline InputMedium::~InputMedium() -{ - delete current_request ; -} - - - /* *** Read accessors *** */