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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*
__________
_____ __ __\______ \_____ _______ ______ ____ _______
/ \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
| Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
|__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
\/ \/ \/ \/
Copyright (C) 2004-2006 Ingo Berg
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "muParserCallback.h"
namespace mu
{
ParserCallback::ParserCallback(fun_type1 a_pFun, bool a_bAllowOpti, int a_iPrec, ECmdCode a_iCode)
:m_pFun((void*)a_pFun)
,m_iArgc(1)
,m_iPri(a_iPrec)
,m_iCode(a_iCode)
,m_iType(tpDBL)
,m_bAllowOpti(a_bAllowOpti)
{}
ParserCallback::ParserCallback( fun_type2 a_pFun, bool a_bAllowOpti, int a_iPrec, ECmdCode a_iCode)
:m_pFun((void*)a_pFun)
,m_iArgc(2)
,m_iPri(a_iPrec)
,m_iCode(a_iCode)
,m_iType(tpDBL)
,m_bAllowOpti(a_bAllowOpti)
{}
ParserCallback::ParserCallback(fun_type3 a_pFun, bool a_bAllowOpti)
:m_pFun((void*)a_pFun)
,m_iArgc(3)
,m_iPri(-1)
,m_iCode(cmFUNC)
,m_iType(tpDBL)
,m_bAllowOpti(a_bAllowOpti)
{}
ParserCallback::ParserCallback(fun_type4 a_pFun, bool a_bAllowOpti)
:m_pFun((void*)a_pFun)
,m_iArgc(4)
,m_iPri(-1)
,m_iCode(cmFUNC)
,m_iType(tpDBL)
,m_bAllowOpti(a_bAllowOpti)
{}
ParserCallback::ParserCallback(fun_type5 a_pFun, bool a_bAllowOpti)
:m_pFun((void*)a_pFun)
,m_iArgc(5)
,m_iPri(-1)
,m_iCode(cmFUNC)
,m_iType(tpDBL)
,m_bAllowOpti(a_bAllowOpti)
{}
ParserCallback::ParserCallback(multfun_type a_pFun, bool a_bAllowOpti)
:m_pFun((void*)a_pFun)
,m_iArgc(-1)
,m_iPri(-1)
,m_iCode(cmFUNC)
,m_iType(tpDBL)
,m_bAllowOpti(a_bAllowOpti)
{}
ParserCallback::ParserCallback(strfun_type1 a_pFun, bool a_bAllowOpti)
:m_pFun((void*)a_pFun)
,m_iArgc(0)
,m_iPri(-1)
,m_iCode(cmFUNC_STR)
,m_iType(tpSTR)
,m_bAllowOpti(a_bAllowOpti)
{}
ParserCallback::ParserCallback(strfun_type2 a_pFun, bool a_bAllowOpti)
:m_pFun((void*)a_pFun)
,m_iArgc(1)
,m_iPri(-1)
,m_iCode(cmFUNC_STR)
,m_iType(tpSTR)
,m_bAllowOpti(a_bAllowOpti)
{}
ParserCallback::ParserCallback(strfun_type3 a_pFun, bool a_bAllowOpti)
:m_pFun((void*)a_pFun)
,m_iArgc(2)
,m_iPri(-1)
,m_iCode(cmFUNC_STR)
,m_iType(tpSTR)
,m_bAllowOpti(a_bAllowOpti)
{}
/** \brief Default constructor.
\throw nothrow
*/
ParserCallback::ParserCallback()
:m_pFun(0)
,m_iArgc(0)
,m_iCode(cmUNKNOWN)
,m_iType(tpVOID)
,m_bAllowOpti(0)
{}
/** \brief Copy constructor.
\throw nothrow
*/
ParserCallback::ParserCallback(const ParserCallback &a_Fun)
{
m_pFun = a_Fun.m_pFun;
m_iArgc = a_Fun.m_iArgc;
m_bAllowOpti = a_Fun.m_bAllowOpti;
m_iCode = a_Fun.m_iCode;
m_iType = a_Fun.m_iType;
m_iPri = a_Fun.m_iPri;
}
/** \brief Clone this instance and return a pointer to the new instance. */
ParserCallback* ParserCallback::Clone() const
{
return new ParserCallback(*this);
}
/** \brief Return tru if the function is conservative.
Conservative functions return always the same result for the same argument.
\throw nothrow
*/
bool ParserCallback::IsOptimizable() const
{
return m_bAllowOpti;
}
/** \brief Get the callback address for the parser function.
The type of the address is void. It needs to be recasted according to the
argument number to the right type.
\throw nothrow
\return #pFun
*/
void* ParserCallback::GetAddr() const
{
return m_pFun;
}
/** \brief Return the callback code. */
ECmdCode ParserCallback::GetCode() const
{
return m_iCode;
}
ETypeCode ParserCallback::GetType() const
{
return m_iType;
}
/** \brief Return the operator priority.
Only valid if the callback token is an operator token (binary or infix).
*/
int ParserCallback::GetPri() const
{
return m_iPri;
}
/** \brief Returns the number of function Arguments. */
int ParserCallback::GetArgc() const
{
return m_iArgc;
}
} // namespace mu
|