AsciiReader.hh 1.68 KB
/*
 * AsciiReader.hh
 *
 *  Created on: 5 août 2013
 *      Author: CS
 */

#ifndef ASCIIREADER_HH_
#define ASCIIREADER_HH_

#include "AbstractReader.hh"
#include <memory>

namespace TimeTableCatalog {

/**
 * Reads a TimeTable from an ASCII formated file.
 * Something like :
 * #Time Table generated by AMDA @ CDPP;
 * #Name: testTable_M_lll;
 * #Description: ;
 * #Historic: Union between testTable lll ;
 * #Creation Date :  2012-09-05T19:15:47;
 * #
 * 2001-02-07T18:39:11 2001-02-07T18:59:11
 * 2001-02-07T19:49:11 2001-02-07T19:59:11
 * 2001-02-08T02:29:11 2001-02-08T03:04:11
 */
class AsciiReader: public AbstractReader {
public:

	static const std::string FORMAT;

	AsciiReader(const std::string& ppath);
	virtual ~AsciiReader();

	/**
	 * Reads a TimeTable from an ASCII formated file.
	 */
	void read(TimeTable& ptt);

	/**
	 * Checks the TT format to know if the reader is the good one.
	 */
	bool canRead(const std::string& pPath);


	/**
	 * Creates an instance of this.
	 */
	std::unique_ptr<AbstractReader> createInstance(const std::string& pPath);

private:

	/**
	 * Reads an interval from ASCII formated file and creates a TimeInterval.
	 */
	std::unique_ptr<TimeInterval> readInterval(const std::string& pline,
			TimeTable& pTT, int pcrtIndex);
	/**
	 * Reads metadata as name, description etc. from ASCII formated file.
	 */
	void readMetadata(const std::string& pline, TimeTable& ptimeTable);

	/**
	 * Adds a line to TT description.
	 */
	void addDescription(const std::string & pline, TimeTable& ptt);

	/**
	 * Adds a parameter description to a time table.
	 */
	void addParameter(const std::string & pline, TimeTable& ptt);
};

} /* namespace TimeTableCatalog */
#endif /* ASCIIREADER_HH_ */