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: distrib.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 LUIDL_DISTRIB_HXX
32 #define LUIDL_DISTRIB_HXX
38 #include <s2_luidl/tokrecv.hxx>
39 #include <s2_dsapi/tokrecv.hxx>
40 #include <s2_luidl/tokproct.hxx>
73 typedef std::vector
< DYN Token
* > TokenQueue
;
74 typedef TokenQueue::iterator TokenIterator
;
76 class TokenParser_Uidl
;
81 class TokenDistributor
: private TokenProcessing_Types
86 ary::Repository
& io_rRepository
,
87 ParserInfo
& io_rParserInfo
);
88 void SetTokenProvider(
89 TokenParser_Uidl
& io_rTokenSource
);
90 void SetTopParseEnvironment(
91 UnoIDL_PE
& io_pTopParseEnvironment
);
95 void Reset() { aDocumentation
.Reset(); }
96 /** calls pTokenSource->GetNextToken() and checks the incoming tokens, until a
97 usable token is found. This token will be forwarded to
102 csi::uidl::Token_Receiver
&
103 CodeTokens_Receiver();
104 csi::dsapi::Token_Receiver
&
105 DocuTokens_Receiver();
107 /** Used from PE_File, if there is a docu to get without
108 an environment to push (this is the case for modules).
110 DYN
ary::doc::OldIdlDocu
*
111 ReleaseLastParsedDocu()
112 { return aDocumentation
.ReleaseLastParsedDocu(); }
114 /** Used from PE_File, if the term "published" was parsed.
115 The next opened parse environment will be set to be published
116 (call ->UnoIDL_PE::SetPublished()).
118 void Set_PublishedOn()
119 { aProcessingData
.Set_PublishedOn(); }
124 class ProcessingData
;
125 friend class ProcessingData
;
127 class ProcessingData
: public csi::uidl::Token_Receiver
,
128 private TokenProcessing_Types
132 ary::Repository
& io_rRepository
,
133 Documentation
& i_rDocuProcessor
,
134 ParserInfo
& io_rParserInfo
);
136 void SetTopParseEnvironment(
137 UnoIDL_PE
& io_pTopParseEnvironment
);
140 /** is called from pTokenSource before finishing a ::TokenParse2::GetNextToken()
141 call and passes the just parsed token to this class.
143 virtual void Receive(
144 DYN
csi::uidl::Token
&
146 virtual void Increment_CurLine();
148 void ProcessCurToken();
150 UnoIDL_PE
& CurEnvironment() const;
151 bool NextTokenExists() const;
152 void Set_PublishedOn()
153 { bPublishedRecentlyOn
= true; }
156 typedef uintt TokenQ_Position
;
157 typedef std::pair
< UnoIDL_PE
*, TokenQ_Position
> EnvironmentInfo
;
158 typedef std::vector
< EnvironmentInfo
> EnvironmentStack
;
160 void AcknowledgeResult();
161 const csi::uidl::Token
&
163 UnoIDL_PE
& CurEnv() const;
164 UnoIDL_PE
& PushEnv() const;
165 uintt
CurTokenPosition() const;
166 uintt
CurEnv_TriedTokenPosition() const;
167 void DecrementTryCount();
169 EnvironmentStack aEnvironments
;
170 TokenQueue aTokenQueue
;
171 TokenIterator itCurToken
;
172 TokenProcessing_Result
178 ParserInfo
& rParserInfo
;
179 Documentation
* pDocuProcessor
;
180 bool bPublishedRecentlyOn
;
183 class Documentation
: public csi::dsapi::Token_Receiver
187 ParserInfo
& io_rParserInfo
);
190 void Reset() { bIsPassedFirstDocu
= false; }
192 virtual void Receive(
193 DYN
csi::dsapi::Token
&
195 virtual void Increment_CurLine();
196 DYN
ary::doc::OldIdlDocu
*
197 ReleaseLastParsedDocu()
198 { return pMostRecentDocu
.Release(); }
200 Dyn
<csi::dsapi::SapiDocu_PE
>
202 ParserInfo
& rParserInfo
;
203 Dyn
<ary::doc::OldIdlDocu
>
205 bool bIsPassedFirstDocu
;
209 TokenParser_Uidl
* pTokenSource
;
210 Documentation aDocumentation
;
211 ProcessingData aProcessingData
;
219 TokenDistributor::SetTokenProvider( TokenParser_Uidl
& io_rTokenSource
)
220 { pTokenSource
= &io_rTokenSource
; }
223 TokenDistributor::SetTopParseEnvironment( UnoIDL_PE
& io_pTopParseEnvironment
)
224 { aProcessingData
.SetTopParseEnvironment(io_pTopParseEnvironment
); }
226 inline csi::uidl::Token_Receiver
&
227 TokenDistributor::CodeTokens_Receiver()
228 { return aProcessingData
; }
230 inline csi::dsapi::Token_Receiver
&
231 TokenDistributor::DocuTokens_Receiver()
232 { return aDocumentation
; }
234 inline const csi::uidl::Token
&
235 TokenDistributor::ProcessingData::CurToken() const
237 csv_assert( itCurToken
!= aTokenQueue
.end() );
238 csv_assert( *itCurToken
!= 0 );
239 return *(*itCurToken
);
243 TokenDistributor::ProcessingData::CurEnv() const
245 csv_assert( aEnvironments
.size() > 0 );
246 csv_assert( aEnvironments
.back().first
!= 0 );
247 return *aEnvironments
.back().first
;
251 TokenDistributor::ProcessingData::PushEnv() const
253 csv_assert( aCurResult
.pEnv2Push
!= 0 );
254 return *aCurResult
.pEnv2Push
;
258 TokenDistributor::ProcessingData::CurTokenPosition() const
260 return itCurToken
- aTokenQueue
.begin();
264 TokenDistributor::ProcessingData::CurEnv_TriedTokenPosition() const
266 csv_assert( aEnvironments
.size() > 0 );
267 return aEnvironments
.back().second
;