-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace_reader.hpp
96 lines (84 loc) · 2.08 KB
/
trace_reader.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
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2009 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
*
* Author(s): Torsten Hoefler <[email protected]>
* Timo Schneider <[email protected]>
*
*/
#include "schedgen.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string.h>
#include <unistd.h>
//#define HAVE_BOOST_IO
#ifdef HAVE_BOOST_IO
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/char_traits.hpp>
#endif
class TraceReader {
private:
std::ifstream trace;
enum {BZ2, NORM} type;
#ifdef HAVE_BOOST_IO
boost::iostreams::filtering_streambuf<boost::iostreams::input> inbz2;
#endif
public:
TraceReader(std::string fname) {
trace.open(fname.c_str(),std::ios::in);
//boost::cmatch m;
//static const boost::regex e(".*\\.bz2$");
//if(regex_match(fname.c_str(), m, e)) type = BZ2;
if(NULL!=strstr(fname.c_str(), ".bz2")) {
#ifdef HAVE_BOOST_IO
type = BZ2;
#else
std::cerr << "bz2 not supported (anymore)\n";
_exit(10);
#endif
} else type=NORM;
#ifdef HAVE_BOOST_IO
if(type == BZ2) {
inbz2.push(boost::iostreams::bzip2_decompressor());
inbz2.push(trace);
}
#endif
}
bool is_open() {
return trace.is_open();
}
std::streampos tellg() {
return trace.tellg();
}
void seekg(std::streampos pos) {
trace.seekg(pos);
}
bool getline(char* s, int n) {
bool eof=0;
if(type == BZ2) {
#ifdef HAVE_BOOST_IO
int pos = 0;
while(1) {
std::string line;
char z = boost::iostreams::get(inbz2);
if(z == '\n') break;
if(z == EOF) { eof=1; break; }
s[pos++] = z;
}
s[pos]='\0';
#endif
} else {
trace.getline(s,n);
eof = trace.eof();
}
//std::cout << "getline " << s << "\n";
return eof;
}
};