-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathXMLTag.cpp
More file actions
57 lines (44 loc) · 1.21 KB
/
Copy pathXMLTag.cpp
File metadata and controls
57 lines (44 loc) · 1.21 KB
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
/*
Author: ESGonzalez
Date: 02/09/18
*/
#include "XMLTag.h"
XMLTag::XMLTag( int leveli, std::string tagNamei ) : tagName(tagNamei), level(leveli) {}
void XMLTag::addAttribute( std::string name, std::string value ) {
std::pair< std::string, std::string > attribute;
attribute = std::make_pair( name, value );
attributes.push_back( attribute );
}
void XMLTag::addDataArray( std::vector< double > newDataArray ) {
dataArray = newDataArray;
}
void XMLTag::arrayToFile( std::ofstream &outStream, int perLine, bool isInt ) {
int i = 0;
outStream << std::string( 2*level+2, ' ');
for ( auto element : dataArray ) {
if (i==perLine) {
i = 0;
outStream << "\n" << std::string( 2*level+2, ' ');
}
if (isInt) {
element = round(element);
}
outStream << element << " ";
i++;
}
outStream << std::endl;
}
std::string XMLTag::getTagOpen() {
std::string tagOpen;
tagOpen = std::string( 2*level, ' ' ) + "<" + tagName;
for ( auto attribute : attributes ) {
tagOpen += " " + attribute.first + "=\"" + attribute.second + "\"";
}
tagOpen += ">";
return tagOpen;
}
std::string XMLTag::getTagClose() {
std::string tagClose;
tagClose = std::string( 2*level, ' ' ) + "</" + tagName + ">";
return tagClose;
}