FileReaderASCII.hh 2.09 KB
/*
 * FileReaderASCII.hh
 *
 *  Created on: Nov 24, 2014
 *  Author: AKKA
 */

#ifndef FILEREADERASCII_HH_
#define FILEREADERASCII_HH_

#include <fstream>

#include "FileReaderAbstract.hh"

namespace AMDA {
namespace LocalFileInterface {

/*
 * @brief Implementation of the class FileReaderAbstract to load a ASCII file format
 */
class FileReaderASCII : public FileReaderAbstract
{
public:
	static int MaxLineSize;

	static std::string ClbKey;

	/*
	 * @brief Constructor
	 */
	FileReaderASCII();

	/*
	 * @brief Destructor
	 */
	virtual ~FileReaderASCII();

	/*
	 * @brief Open a ASCII file
	 */
	virtual bool open(std::string filePath);

	/*
	 * @brief Close the ASCII file
	 */
	virtual bool close(void);

	/*
	 * @brief Test if a ASCII file is currently opened
	 */
	virtual bool isOpened(void);

	/*
	 * @brief Get the id of the time param to use. For the ASCII format, it's the first column
	 */
	virtual std::string getTimeParamId(void);

	/*
	 * @brief Get a param type and a param size in the ASCII file
	 */
	virtual bool getParamInfo(std::string& paramId, LocalParamType& paramType, int& dim1Size, int& dim2Size);

	/*
	 * @brief Get the index of the nearest record of time (the higher one) in the ASCII file
	 */
	virtual int getRecordIndex(std::string& timeId, double time);

	/*
	 * @brief Get a param packet from the ASCII file
	 */
	virtual FileReaderStatus getParamPacketData(std::string& timeId, std::string& paramId,
			int recordIndex, double stopTime, LocalParamDataPacket *packet);

	/*
	 * @brief Get an information
	 */
	virtual bool getInfo(const char* pInfoName, std::vector<double>& res);

	/*
	 * @brief Set time format
	 */
	void setTimeFormat(LocalTimeFormat timeFormat)
	{
		_timeFormat = timeFormat;
	}

	private:

	/*
	 * @brief Split line
	 */
	bool split (const char *line, std::vector<std::string> &lineFields);

	/*
	 * @brief Get time from string
	 */
	double getTime(std::string& timeString);

	/*
	 * @brief ASCII identifier
	 */
	std::ifstream _asciiStream;

	/*
	 * @brief Time format
	 */
	LocalTimeFormat _timeFormat;

};

} /* LocalFileInterface */
} /* AMDA */

#endif /* FILEREADERASCII_HH_ */