FileWriterASCIITabular.cc 4.03 KB
/**
 * FileWriterASCIIATabular.cc
 *  Created on: 21 oct. 2014
 *      Author: AKKA
 */

#include "FileWriterASCIITabular.hh"

namespace AMDA {
namespace ParamOutputImpl {
namespace Download {
namespace FileWriter {

FileWriterASCIITabular::FileWriterASCIITabular(AMDA::Parameters::ParameterManager& pParameterManager) :
		FileWriterASCIIAbstract(pParameterManager)
{
}

FileWriterASCIITabular::~FileWriterASCIITabular(void)
{
}

std::string FileWriterASCIITabular::getExtension(void)
{
	return "txt";
}

std::string FileWriterASCIITabular::getDataFillCharacter(void)
{
	return " ";
}

void FileWriterASCIITabular::writeBeginFile(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeEndFile(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeBeginGeneralDescription(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeEndGeneralDescription(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeErrorInfo(std::string msg)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << msg;
}

void FileWriterASCIITabular::writeBeginInfoGroup(std::string title, int level)
{
	if (!_outputFile.is_open())
		return;

	if (title.empty() || level > 0)
	{
		_outputFile << "#" << std::endl;
		return;
	}

	std::string fullTitle = title;
	fullTitle += " :";

	std::string separatorLine;
	for (unsigned int i = 0; i < fullTitle.size(); ++i)
		separatorLine += "-";

	_outputFile << "# " << separatorLine << std::endl;
	_outputFile << "# " << fullTitle << std::endl;
	_outputFile << "# " << separatorLine << std::endl;
}

void FileWriterASCIITabular::writeEndInfoGroup(int level)
{
	if (!_outputFile.is_open())
		return;
	if (level == 0)
		_outputFile << "#" << std::endl;
}

void FileWriterASCIITabular::writeSingleInfo(std::string key, std::string value, int level)
{
	if (!_outputFile.is_open())
		return;
	std::string prefix;
	for (int i = 0; i < level; ++i)
		prefix += "  ";
	std::stringstream ss(value);
	std::string info_line;
	bool first_line = true;
	while(std::getline(ss,info_line,'\n')){
		_outputFile << "# " << prefix;
		if (first_line) {
			_outputFile << key << " : ";
			first_line = false;
		}
		else {
			for (int i = 0; i < (int)key.size()+3; ++i)
				_outputFile << " ";
		}
		_outputFile << info_line << std::endl;
	}
}

void FileWriterASCIITabular::writeBeginInfoList(std::string /*title*/, int /*level*/)
{
	//nothing to do
}

void FileWriterASCIITabular::writeEndInfoList(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeBeginFieldsDescription(void)
{
	if (!_outputFile.is_open())
		return;
	writeBeginInfoGroup("DATA", 0);
	_outputFile << "# DATA_COLUMNS : ";
}

void FileWriterASCIITabular::writeEndFieldsDescription(void)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << std::endl;
	_outputFile << "#" << std::endl;
}

void FileWriterASCIITabular::writeFieldDescription(std::string paramId)
{
	if (!_outputFile.is_open())
		return;

	if (_fieldInfoMap[paramId].type != DT_TIME)
		_outputFile << ", ";

	if (_fieldInfoMap[paramId].dimSize1 * _fieldInfoMap[paramId].dimSize2 == 1)
	{
		//it's a scalar
		_outputFile << paramId;
	}
	else
	{
		bool isfirstComponent = true;
		for (auto component : _fieldInfoMap[paramId].componentsList)
		{
			if (!isfirstComponent)
				_outputFile << ", ";
			_outputFile << paramId << "[" << component.getDim1Index();
			if (_fieldInfoMap[paramId].dimSize2 > 1)
				_outputFile << "," << component.getDim2Index();
			_outputFile << "]";
			isfirstComponent = false;
		}
	}
}

void FileWriterASCIITabular::writeBeginData(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeEndData(void)
{
	//nothing to do
}

std::string FileWriterASCIITabular::getDataStartTag(bool /* isTimeData */)
{
	return "";
}

std::string FileWriterASCIITabular::getDataStopTag(void)
{
	return "";
}

void FileWriterASCIITabular::writeDataRecord(std::string record)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << record << std::endl;
}

std::string FileWriterASCIITabular::getDataValueSeparator(void)
{
	return "";
}

} /* namespace FileWriter */
} /* namespace Download */
} /* namespace ParamOutputImpl */
} /* namespace AMDA */