-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogparser.cpp
More file actions
108 lines (89 loc) · 3.38 KB
/
logparser.cpp
File metadata and controls
108 lines (89 loc) · 3.38 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
/*******************************************************************
*
* DESCRIPTION: Utilities to parse the simulation log
*
* AUTHOR: Alejandro Troccoli
*
* EMAIL: mailto://atroccol@dc.uba.ar
*
* DATE: 19/04/2001
*
*******************************************************************/
#include "logparser.h"
using namespace std;
/********************************************************************
* parseLine:
* Returns True if line pointed by l contains an output message from a cell in modelName.
* VTime current will be filled with the message time, posi with the CellPosition and value with the output value
********************************************************************/
bool parseLine( const char *l, VTime ¤t, const string &modelName, CellPosition &posi, Real &value, const string &portName )
{
istrstream line( l ) ;
istream_iterator<string> cursor( line ) ;
string tokens[ 15 ];
register long pos( 0 ) ;
while( cursor != istream_iterator<string>() && pos < 15 )
tokens[ pos++ ] = *cursor++ ;
if( pos == 15 && tokens[2] == "L" && tokens[4] == "Y" && \
tokens[8].find( modelName ) == 0 && tokens[14].find( modelName ) == 0 && \
(tokens[10].empty() || tokens[10] == portName))
{
// the time of the message
current = tokens[ 6 ] ;
CellPosition pos( tokens[8] ) ;
posi = pos ;
value = Real( str2Real(tokens[ 12 ]) ) ;
return true ;
}
return false ;
}
/********************************************************************
* isMessageLine:
* Returns True if line pointed by l contains a valid message
* msgTime wil lbe filled with the time of the message, and LP with the number of the LP that receives the message
********************************************************************/
bool isMessageLine( const char* l, int& LP, VTime &msgTime)
{
istrstream line( l ) ;
istream_iterator<string> cursor( line ) ;
string tokens[ 15 ];
register long pos( 0 ) ;
while( cursor != istream_iterator<string>() && pos < 15 )
tokens[ pos++ ] = *cursor++ ;
if( (tokens[4] == "*" && pos == 11 ) || (tokens[4] == "@" && pos == 11) || (tokens[4] == "$" && pos == 11)
|| (tokens[4] == "Y" && pos == 15 ) || (tokens[4] == "X" && pos == 15)
|| (tokens[4] == "I" && pos == 11) ||( tokens[4] == "D" && pos == 13))
{
// the time of the message
msgTime= tokens[ 6 ] ;
LP = str2Int( tokens[0]);
return true ;
}
return false ;
}
/********************************************************************
* isMessageLine:
* Returns True if line pointed by l contains a valid message
* msgTime will be filled with the time of the message, LP with the number of the LP that receives the message
* msgType gets the message type
********************************************************************/
bool isMessageLine( const char* l, int& LP, VTime &msgTime, string& msgType)
{
istrstream line( l ) ;
istream_iterator<string> cursor( line ) ;
string tokens[ 15 ];
register long pos( 0 ) ;
while( cursor != istream_iterator<string>() && pos < 15 )
tokens[ pos++ ] = *cursor++ ;
msgType = tokens[4] ;
if( (tokens[4] == "*" && pos == 11 ) || (tokens[4] == "@" && pos == 11) || (tokens[4] == "$" && pos == 11)
|| (tokens[4] == "Y" && pos == 15 ) || (tokens[4] == "X" && pos == 15)
|| (tokens[4] == "I" && pos == 11) ||( tokens[4] == "D" && pos == 13))
{
// the time of the message
msgTime= tokens[ 6 ] ;
LP = str2Int( tokens[0]);
return true ;
}
return false ;
}