-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDatabase_Technology_Project.cpp
More file actions
88 lines (67 loc) · 2.48 KB
/
Database_Technology_Project.cpp
File metadata and controls
88 lines (67 loc) · 2.48 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
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
#include <iostream>
#include <fstream>
#include <vector>
#include "rapidxml-1.13/rapidxml.hpp"
#include "Record.cpp"
#include <string>
#define blockSize 32762
using namespace std;
using namespace rapidxml;
class XMLReader{
public:
XMLReader(){
cout << "XML parser created!"<<endl;
}
~XMLReader(){
cout << "XML parser destroyed!"<<endl;
}
void getData(){
int j = 1;
xml_document<> doc;
xml_node<> *root_node = NULL;
ifstream theFile("map.osm");
vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
buffer.push_back('\0');
doc.parse<0>(&buffer[0]);
root_node = doc.first_node("osm");
ofstream myfile;
myfile.open("datafile.dat", ios::out | ios::binary);
int currSize = 0;
short int i = 1;
myfile.write((char *) &i, sizeof(short));
currSize += 2;
i++;
int cnt = 0;
for (xml_node<> * node = root_node->first_node("node"); node; node = node->next_sibling())
{
if(node && string(node->name()) == "node"){
vector<double> latLon(2);
latLon[0] = strtod(node->first_attribute("lat")->value(), NULL);
latLon[1] = strtod(node->first_attribute("lon")->value(), NULL);
long long id = atoll(node->first_attribute("id")->value());
Record record(id, latLon);
currSize += sizeof(Record);
myfile.write((char *) &record, sizeof(Record));
if(currSize == blockSize){
cout<<"The size of the block is "<<currSize<<endl;
currSize = 0;
myfile.write((char *) &i, sizeof(short));
currSize += 2;
i++;
}
}
}
cout << "Offset: " << currSize << endl;
myfile.close();
}
};
class DatafileLoader {
public:
DatafileLoader() {
init();
}
void init() {
XMLReader r;
r.getData();
}
};