Blame view

src/amdaParameterInfo/ParameterInfoFileWriter.cc 1.58 KB
ad920fd6   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * 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 */