FileReaderVOTable.hh 4.57 KB
/*
 * FileReaderVOTable.hh
 *
 *  Created on: Nov 24, 2014
 *  Author: AKKA
 */

#ifndef FILEREADERVOTABLE_HH_
#define FILEREADERVOTABLE_HH_

#include "FileReaderAbstract.hh"

namespace AMDA {
namespace LocalFileInterface {

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

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

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

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

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

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

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

	/*
	 * @brief Get a param type and a param size in the VOTable 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 VOTable file
	 */
	virtual int getRecordIndex(std::string& timeId, double time);

	/*
	 * @brief Get a param packet from the VOTable 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);

	private:

	class FieldInfo
	{
	public:
		FieldInfo() : _id(), _name(), _xtype(), _size("1"), _type("double"), _ucd(), _unit()
		{
		}

		const std::string& getId() const {
			return _id;
		}

		void setId(const std::string& id) {
			_id = id;
		}

		const std::string& getName() const {
			return _name;
		}

		void setName(const std::string& name) {
			_name = name;
		}

		const std::string& getXtype() const {
			return _xtype;
		}

		void setXtype(const std::string& xtype) {
			_xtype = xtype;
		}

		const std::string& getSize() const {
			return _size;
		}

		void setSize(const std::string& size) {
			_size = size;
		}

		const std::string& getType() const {
			return _type;
		}

		void setType(const std::string& type) {
			_type = type;
		}

		const std::string& getUCD() const {
			return _ucd;
		}

		void setUCD(const std::string& ucd) {
			_ucd = ucd;
		}

		const std::string& getUnit() const {
			return _unit;
		}

		void setUnit(const std::string& unit) {
			_unit = unit;
		}

	private:
		std::string _id;
		std::string _name;
		std::string _xtype;
		std::string _size;
		std::string _type;
		std::string _ucd;
		std::string _unit;
	};

	class ParamInfo
	{
		public:
			ParamInfo() : _groupId(), _name(), _value(), _size("1")
			{
			}

			const std::string& getGroupId() const {
				return _groupId;
			}

			void setGroupId(const std::string& groupId) {
				_groupId = groupId;
			}

			const std::string& getName() const {
				return _name;
			}

			void setName(const std::string& name) {
				_name = name;
			}

			const std::string& getValue() const {
				return _value;
			}

			void setValue(const std::string& value) {
				_value = value;
			}

			const std::string& getSize() const {
				return _size;
			}

			void setSize(const std::string& size) {
				_size = size;
			}

		private:
			std::string _groupId;
			std::string _name;
			std::string _value;
			std::string _size;
		};

	/*
	 * @brief Retrieve fields and params informations in the VOTable file
	 */
	void getVOTableInfo(void);

	/*
	 * @brief Retrieve TR line position in the VOTable file where time >= timeStart
	 */
	int getStartTimePos(int timeColumn, double timeStart);

	/*
	 * @brief Splits a string using the specified delimiter
	 */
	std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);

	/*
	 * @brief Get a param packet from the VOTable file
	 */
	FileReaderStatus getParamPacketData (int timeColumn, int paramColumn, int recordIndex,
											double stopTime, LocalParamDataPacket *packet);

	/*
	 * @brief VOTable filename
	 */
	std::string		_votFilePath;

	/*
	 * @brief Ordered list of fields name in the VOTable
	 */
	std::vector<boost::shared_ptr<FieldInfo>> _fieldsInfo;

	/*
	 * @brief Ordered list of params in the VOTable
	 */
	std::vector<boost::shared_ptr<ParamInfo>> _paramsInfo;

	/*
	 * @brief Working buffers used to set PacketData
	 */
	float 	*_dataFloat;
	double 	*_dataDouble;
	short 	*_dataShort;
	int 	*_dataInt;
	void 	*_data;
};

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

#endif /* FILEREADERVOTABLE_HH_ */