1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef LUIDL_DISTRIB_HXX
21 #define LUIDL_DISTRIB_HXX
27 #include <s2_luidl/tokrecv.hxx>
28 #include <s2_dsapi/tokrecv.hxx>
29 #include <s2_luidl/tokproct.hxx>
62 typedef std::vector
< DYN Token
* > TokenQueue
;
63 typedef TokenQueue::iterator TokenIterator
;
65 class TokenParser_Uidl
;
70 class TokenDistributor
: private TokenProcessing_Types
75 ary::Repository
& io_rRepository
,
76 ParserInfo
& io_rParserInfo
);
77 void SetTokenProvider(
78 TokenParser_Uidl
& io_rTokenSource
);
79 void SetTopParseEnvironment(
80 UnoIDL_PE
& io_pTopParseEnvironment
);
84 void Reset() { aDocumentation
.Reset(); }
85 /** calls pTokenSource->GetNextToken() and checks the incoming tokens, until a
86 usable token is found. This token will be forwarded to
91 csi::uidl::Token_Receiver
&
92 CodeTokens_Receiver();
93 csi::dsapi::Token_Receiver
&
94 DocuTokens_Receiver();
96 /** Used from PE_File, if there is a docu to get without
97 an environment to push (this is the case for modules).
99 DYN
ary::doc::OldIdlDocu
*
100 ReleaseLastParsedDocu()
101 { return aDocumentation
.ReleaseLastParsedDocu(); }
103 /** Used from PE_File, if the term "published" was parsed.
104 The next opened parse environment will be set to be published
105 (call ->UnoIDL_PE::SetPublished()).
107 void Set_PublishedOn()
108 { aProcessingData
.Set_PublishedOn(); }
113 class ProcessingData
;
114 friend class ProcessingData
;
116 class ProcessingData
: public csi::uidl::Token_Receiver
,
117 private TokenProcessing_Types
121 ary::Repository
& io_rRepository
,
122 Documentation
& i_rDocuProcessor
,
123 ParserInfo
& io_rParserInfo
);
125 void SetTopParseEnvironment(
126 UnoIDL_PE
& io_pTopParseEnvironment
);
129 /** is called from pTokenSource before finishing a ::TokenParse2::GetNextToken()
130 call and passes the just parsed token to this class.
132 virtual void Receive(
133 DYN
csi::uidl::Token
&
135 virtual void Increment_CurLine();
137 void ProcessCurToken();
139 UnoIDL_PE
& CurEnvironment() const;
140 bool NextTokenExists() const;
141 void Set_PublishedOn()
142 { bPublishedRecentlyOn
= true; }
145 typedef uintt TokenQ_Position
;
146 typedef std::pair
< UnoIDL_PE
*, TokenQ_Position
> EnvironmentInfo
;
147 typedef std::vector
< EnvironmentInfo
> EnvironmentStack
;
149 void AcknowledgeResult();
150 const csi::uidl::Token
&
152 UnoIDL_PE
& CurEnv() const;
153 UnoIDL_PE
& PushEnv() const;
154 uintt
CurTokenPosition() const;
155 uintt
CurEnv_TriedTokenPosition() const;
156 void DecrementTryCount();
158 EnvironmentStack aEnvironments
;
159 TokenQueue aTokenQueue
;
160 TokenIterator itCurToken
;
161 TokenProcessing_Result
166 ParserInfo
& rParserInfo
;
167 Documentation
* pDocuProcessor
;
168 bool bPublishedRecentlyOn
;
171 class Documentation
: public csi::dsapi::Token_Receiver
175 ParserInfo
& io_rParserInfo
);
178 void Reset() { bIsPassedFirstDocu
= false; }
180 virtual void Receive(
181 DYN
csi::dsapi::Token
&
183 virtual void Increment_CurLine();
184 DYN
ary::doc::OldIdlDocu
*
185 ReleaseLastParsedDocu()
186 { return pMostRecentDocu
.Release(); }
188 Dyn
<csi::dsapi::SapiDocu_PE
>
190 ParserInfo
& rParserInfo
;
191 Dyn
<ary::doc::OldIdlDocu
>
193 bool bIsPassedFirstDocu
;
197 TokenParser_Uidl
* pTokenSource
;
198 Documentation aDocumentation
;
199 ProcessingData aProcessingData
;
207 TokenDistributor::SetTokenProvider( TokenParser_Uidl
& io_rTokenSource
)
208 { pTokenSource
= &io_rTokenSource
; }
211 TokenDistributor::SetTopParseEnvironment( UnoIDL_PE
& io_pTopParseEnvironment
)
212 { aProcessingData
.SetTopParseEnvironment(io_pTopParseEnvironment
); }
214 inline csi::uidl::Token_Receiver
&
215 TokenDistributor::CodeTokens_Receiver()
216 { return aProcessingData
; }
218 inline csi::dsapi::Token_Receiver
&
219 TokenDistributor::DocuTokens_Receiver()
220 { return aDocumentation
; }
222 inline const csi::uidl::Token
&
223 TokenDistributor::ProcessingData::CurToken() const
225 csv_assert( itCurToken
!= aTokenQueue
.end() );
226 csv_assert( *itCurToken
!= 0 );
227 return *(*itCurToken
);
231 TokenDistributor::ProcessingData::CurEnv() const
233 csv_assert( aEnvironments
.size() > 0 );
234 csv_assert( aEnvironments
.back().first
!= 0 );
235 return *aEnvironments
.back().first
;
239 TokenDistributor::ProcessingData::PushEnv() const
241 csv_assert( aCurResult
.pEnv2Push
!= 0 );
242 return *aCurResult
.pEnv2Push
;
246 TokenDistributor::ProcessingData::CurTokenPosition() const
248 return itCurToken
- aTokenQueue
.begin();
252 TokenDistributor::ProcessingData::CurEnv_TriedTokenPosition() const
254 csv_assert( aEnvironments
.size() > 0 );
255 return aEnvironments
.back().second
;
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */