-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread-chord-data.cc
87 lines (77 loc) · 1.68 KB
/
read-chord-data.cc
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
#include <fstream>
#include <iostream>
#include <sstream>
#include "tbl_counter.h"
using namespace std;
TBLCounter tbl_counter;
void read_branchleft(terminal_t terminal,string line)
{
size_t pos = line.find(":");
string blstr = line.substr( 0, pos );
string numstr = line.substr( pos+1, line.length() );
blv_t branch_left_vector;
stringstream ss;
ss << blstr;
int x;
int i = 1;
while( ss >> x )
{
cout << x << " ";
branch_left_vector.insert( pair<int,int>(i++,x) );
}
stringstream ss2;
ss2 << numstr;
cout << "|";
ss2 >> x;
// pair: branchleft_vector -> amount of occurence
tbl_counter.add( terminal, branch_left_vector, x);
cout << x << " ";
cout << endl;
}
void readfile(const char *file_name)
{
string line;
ifstream infile;
infile.open (file_name);
terminal_t terminal;
while(!infile.eof() ) // To get you all the lines.
{
getline(infile,line); // Saves the line in STRING.
if( line.size() > 1 )
{
if( line[0] == ' ' )
{
terminal.clear();
cout << "New terminal" << endl;
stringstream ss;
ss << line;
int x;
while(ss >> x)
{
cout << x << " " ;
terminal.push_back(x);
}
cout << endl;
}
if( line[0] == '0' )
{
read_branchleft(terminal, line);
}
}
else
{
}
}
infile.close();
}
int main(int argc, char const *argv[])
{
if( argc != 2 )
{
cout << "Usage read-chord-data [file_name]" << endl;
return 0;
}
tbl_counter.readfile( argv[1] );
tbl_counter.out();
return 0;
}