1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef LUIDL_DISTRIB_HXX
25 #define LUIDL_DISTRIB_HXX
26 
27 
28 
29 // USED SERVICES
30 	// BASE CLASSES
31 #include <s2_luidl/tokrecv.hxx>
32 #include <s2_dsapi/tokrecv.hxx>
33 #include <s2_luidl/tokproct.hxx>
34 	// COMPONENTS
35 	// PARAMETERS
36 
37 
38 class ParserInfo;
39 
40 namespace ary
41 {
42     class Repository;
43 
44 namespace doc
45 {
46     class OldIdlDocu;
47 }   // namespace inf
48 }   // namespace ary)
49 
50 
51 
52 namespace csi
53 {
54 namespace dsapi
55 {
56     class Token_Receiver;
57     class SapiDocu_PE;
58 }
59 
60 
61 
62 namespace uidl
63 {
64 
65 
66 typedef std::vector< DYN Token * >	TokenQueue;
67 typedef TokenQueue::iterator	    TokenIterator;
68 
69 class TokenParser_Uidl;
70 class UnoIDL_PE;
71 class Token;
72 
73 
74 class TokenDistributor : private TokenProcessing_Types
75 
76 {
77   public:
78 						TokenDistributor(
79 							ary::Repository &	io_rRepository,
80 							ParserInfo &            io_rParserInfo );
81 	void				SetTokenProvider(
82 							TokenParser_Uidl &	io_rTokenSource );
83 	void				SetTopParseEnvironment(
84 							UnoIDL_PE &			io_pTopParseEnvironment );
85 						~TokenDistributor();
86 
87 
Reset()88 	void				Reset()					{ aDocumentation.Reset(); }
89 	/**	calls pTokenSource->GetNextToken() and checks the incoming tokens, until a
90 		usable token is found. This token will be forwarded to
91 		pTopParseEnv;
92 	*/
93 	void				TradeToken();
94 
95 	csi::uidl::Token_Receiver &
96 						CodeTokens_Receiver();
97 	csi::dsapi::Token_Receiver &
98 						DocuTokens_Receiver();
99 
100     /** Used from PE_File, if there is a docu to get without
101         an environment to push (this is the case for modules).
102     */
103 	DYN ary::doc::OldIdlDocu *
ReleaseLastParsedDocu()104                         ReleaseLastParsedDocu()
105                             { return aDocumentation.ReleaseLastParsedDocu(); }
106 
107     /** Used from PE_File, if the term "published" was parsed.
108         The next opened parse environment will be set to be published
109         (call ->UnoIDL_PE::SetPublished()).
110     */
Set_PublishedOn()111     void                Set_PublishedOn()
112                             { aProcessingData.Set_PublishedOn(); }
113 
114 
115   private:
116     class Documentation;
117     class ProcessingData;
118     friend class ProcessingData;
119 
120 	class  ProcessingData : public 	csi::uidl::Token_Receiver,
121 							private TokenProcessing_Types
122 	{
123 	  public:
124 							ProcessingData(
125 								ary::Repository &	io_rRepository,
126 								Documentation &		    i_rDocuProcessor,
127 							    ParserInfo &            io_rParserInfo );
128 							~ProcessingData();
129 		void				SetTopParseEnvironment(
130 								UnoIDL_PE &			io_pTopParseEnvironment );
131 
132 
133 		/**	is called from pTokenSource before finishing a ::TokenParse2::GetNextToken()
134 			call and passes the just parsed token to this class.
135 		*/
136 		virtual void		Receive(
137 								DYN csi::uidl::Token &
138 												let_drToken );
139         virtual void        Increment_CurLine();
140 
141 		void				ProcessCurToken();
142 
143 		UnoIDL_PE &			CurEnvironment() const;
144 		bool				NextTokenExists() const;
Set_PublishedOn()145         void                Set_PublishedOn()
146                                 { bPublishedRecentlyOn = true; }
147 
148 	  private:
149 		typedef uintt	TokenQ_Position;
150 		typedef std::pair< UnoIDL_PE *, TokenQ_Position >	EnvironmentInfo;
151 		typedef std::vector< EnvironmentInfo >              EnvironmentStack;
152 
153 		void				AcknowledgeResult();
154 		const csi::uidl::Token &
155 							CurToken() const;
156 		UnoIDL_PE &			CurEnv() const;
157 		UnoIDL_PE &			PushEnv() const;
158 		uintt				CurTokenPosition() const;
159 		uintt               CurEnv_TriedTokenPosition() const;
160 		void				DecrementTryCount();
161 
162 		EnvironmentStack	aEnvironments;
163 		TokenQueue			aTokenQueue;
164 		TokenIterator		itCurToken;
165 		TokenProcessing_Result
166 							aCurResult;
167 		uintt				nTryCount;
168 		bool				bFinished;
169 		ary::Repository &
170                             rRepository;
171         ParserInfo &        rParserInfo;
172 		Documentation *		pDocuProcessor;
173     	bool                bPublishedRecentlyOn;
174 	};
175 
176 	class Documentation : public csi::dsapi::Token_Receiver
177 	{
178 	  public:
179 							Documentation(
180 							    ParserInfo &    io_rParserInfo);
181 							~Documentation();
182 
Reset()183 		void				Reset()				{ bIsPassedFirstDocu = false; }
184 
185 		virtual void		Receive(
186 								DYN csi::dsapi::Token &
187 												let_drToken );
188         virtual void        Increment_CurLine();
189 		DYN ary::doc::OldIdlDocu *
ReleaseLastParsedDocu()190 							ReleaseLastParsedDocu()
191 							                    { return pMostRecentDocu.Release(); }
192 	  private:
193 		Dyn<csi::dsapi::SapiDocu_PE>
194 							pDocuParseEnv;
195 		ParserInfo &        rParserInfo;
196 		Dyn<ary::doc::OldIdlDocu>
197 							pMostRecentDocu;
198 		bool				bIsPassedFirstDocu;
199 	};
200 
201 	// DATA
202 	TokenParser_Uidl *	pTokenSource;
203 	Documentation		aDocumentation;
204 	ProcessingData		aProcessingData;
205 };
206 
207 
208 
209 // IMPLEMENTATION
210 
211 inline void
SetTokenProvider(TokenParser_Uidl & io_rTokenSource)212 TokenDistributor::SetTokenProvider( TokenParser_Uidl &	io_rTokenSource )
213 	{ pTokenSource = &io_rTokenSource; }
214 
215 inline void
SetTopParseEnvironment(UnoIDL_PE & io_pTopParseEnvironment)216 TokenDistributor::SetTopParseEnvironment( UnoIDL_PE & io_pTopParseEnvironment )
217 	{ aProcessingData.SetTopParseEnvironment(io_pTopParseEnvironment); }
218 
219 inline csi::uidl::Token_Receiver &
CodeTokens_Receiver()220 TokenDistributor::CodeTokens_Receiver()
221 	{ return aProcessingData; }
222 
223 inline csi::dsapi::Token_Receiver &
DocuTokens_Receiver()224 TokenDistributor::DocuTokens_Receiver()
225 	{ return aDocumentation; }
226 
227 inline const csi::uidl::Token &
CurToken() const228 TokenDistributor::ProcessingData::CurToken() const
229 {
230 	csv_assert( itCurToken != aTokenQueue.end() );
231 	csv_assert( *itCurToken != 0 );
232 	return *(*itCurToken);
233 }
234 
235 inline UnoIDL_PE &
CurEnv() const236 TokenDistributor::ProcessingData::CurEnv() const
237 {
238 	csv_assert( aEnvironments.size() > 0 );
239 	csv_assert( aEnvironments.back().first != 0 );
240 	return *aEnvironments.back().first;
241 }
242 
243 inline UnoIDL_PE &
PushEnv() const244 TokenDistributor::ProcessingData::PushEnv() const
245 {
246 	csv_assert( aCurResult.pEnv2Push != 0 );
247 	return *aCurResult.pEnv2Push;
248 }
249 
250 inline uintt
CurTokenPosition() const251 TokenDistributor::ProcessingData::CurTokenPosition() const
252 {
253 	return itCurToken - aTokenQueue.begin();
254 }
255 
256 inline uintt
CurEnv_TriedTokenPosition() const257 TokenDistributor::ProcessingData::CurEnv_TriedTokenPosition() const
258 {
259 	csv_assert( aEnvironments.size() > 0 );
260 	return aEnvironments.back().second;
261 }
262 
263 
264 }   // namespace uidl
265 }   // namespace csi
266 
267 #endif
268 
269