1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: callf.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef ADC_CPP_CALLF_HXX
32 #define ADC_CPP_CALLF_HXX
39 /** This represents a function to be called, if a specific kind of token
40 arrives in the semantic parser.
42 @descr This class is only to be used as member of PeStatus<PE>.
44 The owning ParseEnvironment.
45 @see PeStatus, ParseEnvironment
51 typedef void (PE::*F_Tok
)(const char *);
58 INT16
TokType() const;
67 /** One state within a ParseEnvironment.
70 The owning ParseEnvironment.
76 typedef typename CallFunction
<PE
>::F_Tok F_Tok
;
82 INT16
* i_pTokTypeArray
,
86 virtual void Call_Handler(
88 const char * i_sTokenText
) const;
94 const char * i_sTokenText
) const;
97 std::vector
< CallFunction
<PE
> >
107 typedef typename
PE::E_State State
;
112 DYN PeStatus
<PE
> & let_drState
);
117 State i_ePosition
) const;
125 DYN PeStatus
<PE
> * aStati
[PE::size_of_states
];
137 CallFunction
<PE
>::CallFunction( F_Tok i_f2Call
,
145 inline typename CallFunction
<PE
>::F_Tok
146 CallFunction
<PE
>::GetF() const
153 CallFunction
<PE
>::TokType() const
163 PeStatus
<PE
>::PeStatus( PE
& i_rMyPE
,
165 F_Tok
* i_pFuncArray
,
166 INT16
* i_pTokTypeArray
,
171 aBranches
.reserve(i_nSize
);
172 for ( uintt i
= 0; i
< i_nSize
; ++i
)
174 // csv_assert(i > 0 ? i_pTokTypeArray[i] > i_pTokTypeArray[i-1] : true);
175 aBranches
.push_back( CallFunction
<PE
>( i_pFuncArray
[i
], i_pTokTypeArray
[i
]) );
180 PeStatus
<PE
>::~PeStatus()
187 PeStatus
<PE
>::Call_Handler( INT16 i_nTokTypeId
,
188 const char * i_sTokenText
) const
190 uintt nSize
= aBranches
.size();
191 uintt nPos
= nSize
/ 2;
193 if ( i_nTokTypeId
< aBranches
[nPos
].TokType() )
195 for ( --nPos
; intt(nPos
) >= 0; --nPos
)
197 if (CheckForCall(nPos
, i_nTokTypeId
, i_sTokenText
))
203 for ( ; nPos
< nSize
; ++nPos
)
205 if (CheckForCall(nPos
, i_nTokTypeId
, i_sTokenText
))
210 (pMyPE
->*fDefault
)(i_sTokenText
);
215 PeStatus
<PE
>::CheckForCall( uintt i_nPos
,
217 const char * i_sTokenText
) const
219 if ( aBranches
[i_nPos
].TokType() == i_nTokTypeId
)
221 (pMyPE
->*aBranches
[i_nPos
].GetF())(i_sTokenText
);
230 PeStatusArray
<PE
>::PeStatusArray()
231 : eState(PE::size_of_states
)
233 memset(aStati
, 0, sizeof aStati
);
238 PeStatusArray
<PE
>::InsertState( State i_ePosition
,
239 DYN PeStatus
<PE
> & let_drState
)
241 csv_assert(aStati
[i_ePosition
] == 0);
242 aStati
[i_ePosition
] = &let_drState
;
246 PeStatusArray
<PE
>::~PeStatusArray()
248 int i_max
= PE::size_of_states
;
249 for (int i
= 0; i
< i_max
; i
++)
256 inline const PeStatus
<PE
> &
257 PeStatusArray
<PE
>::operator[]( State i_ePosition
) const
259 csv_assert( uintt(i_ePosition
) < PE::size_of_states
);
260 csv_assert( aStati
[i_ePosition
] != 0 );
261 return *aStati
[i_ePosition
];
266 PeStatusArray
<PE
>::SetCur( State i_eCurState
)
268 eState
= i_eCurState
;
274 PeStatusArray
<PE
>::Cur() const
276 return (*this)[eState
];
279 #define SEMPARSE_CREATE_STATUS(penv, state, default_function) \
280 pStati->InsertState( state, \
281 *new PeStatus<penv>( \
283 sizeof( stateT_##state ) / sizeof (INT16), \
286 &penv::default_function ) )