2012-02-06 16:44:09 +01:00
|
|
|
/*
|
2013-05-29 18:43:35 +02:00
|
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
|
|
* It is subject to the copyright notice and license terms in the
|
|
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
|
|
* distribution and at
|
|
|
|
* http://code.lm7.fr/p/owlps/source/tree/master/COPYRIGHT.t2t
|
|
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms
|
|
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
|
|
* distributed along with this file, either separately or by replacing
|
2013-06-22 23:30:17 +02:00
|
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-01-07 16:34:31 +01:00
|
|
|
#ifndef _OWLPS_POSITIONING_INPUTCSV_HH_
|
|
|
|
#define _OWLPS_POSITIONING_INPUTCSV_HH_
|
|
|
|
|
|
|
|
#include "inputmedium.hh"
|
2010-04-01 11:15:48 +02:00
|
|
|
#include "csvfilereader.hh"
|
2013-06-14 19:12:50 +02:00
|
|
|
#include "configuration.hh"
|
2010-01-07 16:34:31 +01:00
|
|
|
|
|
|
|
#include <string>
|
2013-06-14 19:12:50 +02:00
|
|
|
#include <iostream>
|
2010-01-07 16:34:31 +01:00
|
|
|
|
2013-05-30 21:23:05 +02:00
|
|
|
/// Reads [requests](@ref Request) from a CSV file
|
2010-03-08 17:23:20 +01:00
|
|
|
/**
|
|
|
|
* CSV format is:
|
2013-06-14 18:42:07 +02:00
|
|
|
* Format_version;Mobile_MAC;Request_type;Number_of_packets;
|
2013-06-14 21:54:26 +02:00
|
|
|
* Timestamp;X;Y;Z;Direction;CP_MAC_1;Packet_ID_1;SS_1;…;
|
|
|
|
* CP_MAC_n;Packet_ID_n;SS_n
|
2010-03-08 17:23:20 +01:00
|
|
|
*/
|
2010-01-07 16:34:31 +01:00
|
|
|
class InputCSV: public InputMedium
|
|
|
|
{
|
|
|
|
protected:
|
2010-04-01 11:15:48 +02:00
|
|
|
CSVFileReader file ;
|
2010-01-07 16:34:31 +01:00
|
|
|
|
2011-08-01 12:03:41 +02:00
|
|
|
/** @name Operations */
|
|
|
|
//@{
|
|
|
|
/// Reads data & fills the current request
|
|
|
|
bool fill_current_request(void) ;
|
2013-06-14 19:12:50 +02:00
|
|
|
/// Reads a field and handle error message printing
|
|
|
|
template<class T> bool read_field(T &field,
|
|
|
|
const std::string &message) ;
|
2011-08-01 12:03:41 +02:00
|
|
|
//@}
|
|
|
|
|
2010-01-07 16:34:31 +01:00
|
|
|
public:
|
2010-04-01 11:15:48 +02:00
|
|
|
InputCSV(const std::string &filename):
|
|
|
|
file(filename) {}
|
2010-03-05 17:24:18 +01:00
|
|
|
|
2010-03-23 11:32:05 +01:00
|
|
|
~InputCSV(void) {}
|
2010-01-07 16:34:31 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/** @name Read accessors */
|
|
|
|
//@{
|
|
|
|
/// Checks if the end of the CSV file has been reached
|
2010-01-07 16:34:31 +01:00
|
|
|
bool eof(void) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2010-01-07 16:34:31 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/** @name Operators */
|
|
|
|
//@{
|
2010-01-07 16:34:31 +01:00
|
|
|
operator bool(void) const ;
|
2010-01-16 12:23:07 +01:00
|
|
|
//@}
|
2010-01-07 16:34:31 +01:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Read accessors *** */
|
2010-01-07 16:34:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
inline bool InputCSV::eof() const
|
|
|
|
{
|
2010-03-23 11:32:05 +01:00
|
|
|
return file.eof() ;
|
2010-01-07 16:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-14 19:12:50 +02:00
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This functions tries to read `field` from the input CSV file; if it
|
|
|
|
* fails and the verbose mode is active, a message is displayed on the
|
|
|
|
* standard error.
|
|
|
|
*
|
|
|
|
* @param field The variable in which the read field will be stored.
|
|
|
|
* @param message The name of the field to be displayed in case of error.
|
|
|
|
*
|
|
|
|
* @returns `true` in case of success.
|
|
|
|
* @returns `false` in case of error.
|
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
inline bool InputCSV::read_field(T &field, const std::string &message)
|
|
|
|
{
|
|
|
|
if (file.read_field(field))
|
|
|
|
return true ;
|
|
|
|
|
|
|
|
// Wrong number of fields
|
|
|
|
if (Configuration::is_configured("verbose"))
|
|
|
|
std::cerr << "InputCSV: cannot read " << message << ".\n" ;
|
|
|
|
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Operators *** */
|
2010-01-07 16:34:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
inline InputCSV::operator bool() const
|
|
|
|
{
|
2010-03-23 11:32:05 +01:00
|
|
|
return ! eof() ;
|
2010-01-07 16:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _OWLPS_POSITIONING_INPUTCSV_HH_
|