AsciiWriter.hh 1.62 KB
/*
 * AsciiWriter.hh
 *
 *  Created on: 6 août 2013
 *      Author: CS
 */

#ifndef ASCIIWRITER_HH_
#define ASCIIWRITER_HH_

#include "AbstractWriter.hh"
#include <iostream>

namespace TimeTableCatalog {

/**
 * Writes a TimeTable into 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 AsciiWriter: public AbstractWriter {
public:
	AsciiWriter(const std::string& pPath, const std::string& pName = "");
	virtual ~AsciiWriter();

	static const std::string FORMAT;

	/**
	 * Writes a TimeTable into an ASCII formated file.
	 */
	std::string write(const TimeTable& pTT);

	/**
	 * Creates an instance of this.
	 */
	std::unique_ptr<AbstractWriter> createInstance(const std::string& pPath,
			const std::string& pName = "");

	/**
	 * Gets the tt file expected extension, starting with .
	 */
	const std::string getExtension() const;

private:

	/**
	 * Writes all metadata as name, description etc. into an ASCII formated file.
	 */
	void writeMetaData(const TimeTable& pTT, std::ostream& pout);

	/**
	 * Writes all TT intervals into an ASCII formated file.
	 */
	void writeIntervals(const TimeTable& pTT, std::ostream& pout);
};

/**
 * Splits a string around a given delimiter.
 */
std::vector<std::string> &split(const std::string &s, char delim,
		std::vector<std::string> &elems);

} /* namespace TimeTableCatalog */
#endif /* ASCIIWRITER_HH_ */