ParameterInfoFileWriter.cc 1.58 KB
/*
 * ParameterInfoFileWriter.cc
 *
 *  Created on: 18 mar. 2016
 *      Author: AKKA
 */

#include "ParameterInfoFileWriter.hh"

namespace AMDA
{
namespace ParameterInfo
{


ParameterInfoFileWriter::ParameterInfoFileWriter() : _writer(NULL) {

}

ParameterInfoFileWriter::~ParameterInfoFileWriter() {
	closeWriter();
}

bool ParameterInfoFileWriter::initWriter(const char* filePath) {
	if (_writer != NULL)
		return false;

	LIBXML_TEST_VERSION

	_writer = xmlNewTextWriterFilename(filePath, 0);
	if (_writer == NULL) {
		return false;
	}

	int rc;
	rc = xmlTextWriterStartDocument(_writer, "1.0", "UTF-8", NULL);

	if (rc < 0) {
		return false;
	}

	return startElement("paraminfo");
}

bool ParameterInfoFileWriter::closeWriter() {
	if (_writer == NULL)
		return false;

	int rc = xmlTextWriterEndDocument(_writer);
	if (rc < 0)
		return false;

	xmlFreeTextWriter(_writer);

	_writer = NULL;

	return true;
}

bool ParameterInfoFileWriter::startElement(const char* name) {
	if (_writer == NULL)
		return false;

	int rc = xmlTextWriterStartElement(_writer, BAD_CAST name);
	if (rc < 0) {
		return false;
	}

	return true;
}

bool ParameterInfoFileWriter::endElement() {
	if (_writer == NULL)
		return false;

	int rc = xmlTextWriterEndElement(_writer);
	if (rc < 0) {
		return false;
	}

	return true;
}

bool ParameterInfoFileWriter::addAttribute(const char* name, const char* value) {
	if (_writer == NULL)
		return false;

	int rc = xmlTextWriterWriteAttribute(_writer, BAD_CAST name, BAD_CAST value);
	if (rc < 0) {
		return false;
	}

	return false;
}

} /* namespace ParameterInfo */
} /* namespace AMDA */