-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogbuffer.cpp
More file actions
131 lines (105 loc) · 2.51 KB
/
logbuffer.cpp
File metadata and controls
131 lines (105 loc) · 2.51 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************************************************
*
* DESCRIPTION: Buffers and sorts the log output from different LPs and produces
* an ordered list of events.
*
* AUTHOR: Alejandro Troccoli
*
* EMAIL: mailto://atroccol@dc.uba.ar
*
* DATE: 19/04/2001
*
*******************************************************************/
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <cstring>
#include "VTime.hh"
#include "logparser.h"
using namespace std;
/******************************************************************
* class LogLine
******************************************************************/
class LogLine
{
public:
friend class PrioritizeLogLine;
LogLine( VTime t, char* l ) {
line = new char[128];
strcpy(line,l);
time = t;
}
char *getLine() const
{ return line; }
~LogLine()
{
delete line;
}
private:
char *line;
VTime time;
};
/******************************************************************
* class PrioritizeLogLine
******************************************************************/
class PrioritizeLogLine
{
public :
int operator()( const LogLine *x, const LogLine *y )
{
return y->time < x->time;
}
};
/******************************************************************
* Main
******************************************************************/
int main( int argc, char* argv[] )
{
char buffer[2048];
unsigned int bufferSize = 200;
string strBufferSize;
// parameter parsing
while( --argc )
if( *argv[ argc ] == '-' )
switch( argv[ argc ][ 1 ] )
{
case 'b': /* file .ma */
strBufferSize = argv[ argc ] + 2;
bufferSize = str2Int( strBufferSize );
break;
default:
cout << "Warning... invalid parameter " << argv[ argc ] << "!" << endl ;
}
else
cout << "Warning... invalid parameter " << argv[ argc ] << "!" << endl ;
priority_queue<LogLine*, vector< LogLine* >, PrioritizeLogLine> q;
istream* in = &cin;
//istream* in = new fstream ( "calor2.log", ios::in) ;
while( !in->eof() && in->good() )
{
int LP;
VTime time;
bool valid;
in->getline( buffer, 2048 );
valid = isMessageLine( buffer, LP, time);
//cout << " Analizando: " << buffer;
if ( valid )
{
//cout << " valida! Time:" << time << endl;
q.push( new LogLine( time, buffer) );
if ( q.size() == bufferSize )
{
cout << q.top()->getLine() << endl;
delete q.top();
q.pop();
}
}
} //while
while ( !q.empty() )
{
cout << q.top()->getLine() << endl;
delete q.top();
q.pop();
}//while
}