-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtagfile.hpp
86 lines (75 loc) · 1.78 KB
/
tagfile.hpp
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
// tag file
class TagFileEntry
{
public:
long int id;
string key;
string value;
//const char * key;
//const char * value;
public:
TagFileEntry(const long int & id,const string & k,const string & v ):
id(id),
key(k),
value(v) { }
void write (ostream & os) {
os << id << "\t"
<< key << "\t"
<< value << endl;
}
};
class TagFile {
public:
vector< TagFileEntry > data;
ofstream txtfile;
string filename;
long long total_count;
const char * dirname;
long blockcount;
TagFile(const char * dirname,long blockcount,const char * filename)
:total_count(0),
filename(filename),
dirname(dirname),
blockcount(blockcount)
{
string outputbase(string (dirname) + string(filename));
txtfile.open(string(outputbase+ ".txt").c_str());
}
~TagFile()
{
int count =data.size();
write(count);
txtfile.close();
cout << "Closing file " << dirname << filename << ", wrote " << total_count << endl;
}
void flush()
{
write(data.size());
}
long long count()
{
return total_count;
}
void write(int count)
{
// append the data to the file
// file.write((const char*)&data[0], count * sizeof(T)); // skip the binary file now
vector< TagFileEntry >::iterator i;
for(i=data.begin();i!=data.end();i++)
{
i->write (txtfile);
}
data.clear(); // erase the data
}
void push_back (long int pos, const string & key, const string & val){
total_count++;
//cerr << "tag:"<< key << " = "<< val << endl;
TagFileEntry v (pos,key,val);
data.push_back(v);
int count =data.size();
if (count > 100) {
//cerr << "wrote tags count " << total_count << endl;
write(count);
}
}
};