This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
forked from Mac2/libiwparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParserMsgBaseC.php
165 lines (133 loc) · 4.51 KB
/
ParserMsgBaseC.php
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <martin@martimeo.de> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some
* day, and you think this stuff is worth it, you can buy me a beer in return.
* Martin Martimeo
* ----------------------------------------------------------------------------
*/
/**
* @author Martin Martimeo <martin@martimeo.de>
* @package libIwParsers
* @subpackage parsers
*/
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/**
* Base class for msgparsers
*
* This class provides attributes and methods, needed by many concrete
* parsers. By collecting them in this base class, we reduce redundant
* code.
*/
class ParserMsgBaseC extends ParserFunctionC
{
/**
* @var string identifier of the concrete parser
*/
private $_strIdentifier = '';
/**
* @var string representing the type
*/
private $_reCanParseMsg = '';
/**
* @var object msg to be parsed
*/
private $_strMsg = '';
/////////////////////////////////////////////////////////////////////////////
/**
* protected constructor
*
* As this class isn't meant to do anything on its own,
* we protect it from beeing instantiated.
*
* Only deriving classes shall be able to instantiate it.
*/
protected function __construct()
{
}
/////////////////////////////////////////////////////////////////////////////
/**
* @see ParserI::canParseMsg()
*/
public function canParseMsg($msg)
{
if ($msg->eParserType == $this->_reCanParseMsg) {
$this->setMsg($msg);
return true;
} else {
$e = get_class($this) . '::canParseMsg - ERROR in equation of...';
throw new Exception($e);
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* @see ParserI::getIdentifier()
*/
public function getIdentifier()
{
return $this->_strIdentifier;
}
/////////////////////////////////////////////////////////////////////////////
protected function getMsg()
{
return $this->_strMsg;
}
/////////////////////////////////////////////////////////////////////////////
protected function setIdentifier($value)
{
$this->_strIdentifier = PropertyValueC::ensureString($value);
}
/////////////////////////////////////////////////////////////////////////////
protected function setCanParseMsg($value)
{
$this->_reCanParseMsg = PropertyValueC::ensureString($value);
}
/////////////////////////////////////////////////////////////////////////////
public function setMsg($value)
{
//set msg
$this->_strMsg = $value;
}
/////////////////////////////////////////////////////////////////////////////
/**
* matches a Resource Line
*
* Resource Count
*/
protected function getRegularExpressionResources()
{
$reResourceName = $this->getRegExpResource();
$reResourceCount = $this->getRegExpDecimalNumber();
#Just even don't think to ask anything about this regexp, fu!
$regExp = '/';
$regExp .= '(?P<resource_name>' . $reResourceName . ')';
$regExp .= '\s+';
$regExp .= '(?P<resource_count>' . $reResourceCount . ')';
$regExp .= '[\s\n]*';
$regExp .= '/mx';
return $regExp;
}
/////////////////////////////////////////////////////////////////////////////
/**
* matches a Schiffe Line
*
* Schiffe Count
*/
protected function getRegularExpressionSchiffe()
{
$reSchiffeName = $this->getRegExpSchiffe();
$reSchiffeCount = $this->getRegExpDecimalNumber();
#Just even don't think to ask anything about this regexp, fu!
$regExp = '/';
$regExp .= '(?P<schiff_name>' . $reSchiffeName . ')';
$regExp .= '\s+';
$regExp .= '(?P<schiffe_count>' . $reSchiffeCount . ')';
$regExp .= '[\s\n]*';
$regExp .= '/mx';
return $regExp;
}
}