1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef LUIDL_DISTRIB_HXX 29 #define LUIDL_DISTRIB_HXX 30 31 32 33 // USED SERVICES 34 // BASE CLASSES 35 #include <s2_luidl/tokrecv.hxx> 36 #include <s2_dsapi/tokrecv.hxx> 37 #include <s2_luidl/tokproct.hxx> 38 // COMPONENTS 39 // PARAMETERS 40 41 42 class ParserInfo; 43 44 namespace ary 45 { 46 class Repository; 47 48 namespace doc 49 { 50 class OldIdlDocu; 51 } // namespace inf 52 } // namespace ary) 53 54 55 56 namespace csi 57 { 58 namespace dsapi 59 { 60 class Token_Receiver; 61 class SapiDocu_PE; 62 } 63 64 65 66 namespace uidl 67 { 68 69 70 typedef std::vector< DYN Token * > TokenQueue; 71 typedef TokenQueue::iterator TokenIterator; 72 73 class TokenParser_Uidl; 74 class UnoIDL_PE; 75 class Token; 76 77 78 class TokenDistributor : private TokenProcessing_Types 79 80 { 81 public: 82 TokenDistributor( 83 ary::Repository & io_rRepository, 84 ParserInfo & io_rParserInfo ); 85 void SetTokenProvider( 86 TokenParser_Uidl & io_rTokenSource ); 87 void SetTopParseEnvironment( 88 UnoIDL_PE & io_pTopParseEnvironment ); 89 ~TokenDistributor(); 90 91 92 void Reset() { aDocumentation.Reset(); } 93 /** calls pTokenSource->GetNextToken() and checks the incoming tokens, until a 94 usable token is found. This token will be forwarded to 95 pTopParseEnv; 96 */ 97 void TradeToken(); 98 99 csi::uidl::Token_Receiver & 100 CodeTokens_Receiver(); 101 csi::dsapi::Token_Receiver & 102 DocuTokens_Receiver(); 103 104 /** Used from PE_File, if there is a docu to get without 105 an environment to push (this is the case for modules). 106 */ 107 DYN ary::doc::OldIdlDocu * 108 ReleaseLastParsedDocu() 109 { return aDocumentation.ReleaseLastParsedDocu(); } 110 111 /** Used from PE_File, if the term "published" was parsed. 112 The next opened parse environment will be set to be published 113 (call ->UnoIDL_PE::SetPublished()). 114 */ 115 void Set_PublishedOn() 116 { aProcessingData.Set_PublishedOn(); } 117 118 119 private: 120 class Documentation; 121 class ProcessingData; 122 friend class ProcessingData; 123 124 class ProcessingData : public csi::uidl::Token_Receiver, 125 private TokenProcessing_Types 126 { 127 public: 128 ProcessingData( 129 ary::Repository & io_rRepository, 130 Documentation & i_rDocuProcessor, 131 ParserInfo & io_rParserInfo ); 132 ~ProcessingData(); 133 void SetTopParseEnvironment( 134 UnoIDL_PE & io_pTopParseEnvironment ); 135 136 137 /** is called from pTokenSource before finishing a ::TokenParse2::GetNextToken() 138 call and passes the just parsed token to this class. 139 */ 140 virtual void Receive( 141 DYN csi::uidl::Token & 142 let_drToken ); 143 virtual void Increment_CurLine(); 144 145 void ProcessCurToken(); 146 147 UnoIDL_PE & CurEnvironment() const; 148 bool NextTokenExists() const; 149 void Set_PublishedOn() 150 { bPublishedRecentlyOn = true; } 151 152 private: 153 typedef uintt TokenQ_Position; 154 typedef std::pair< UnoIDL_PE *, TokenQ_Position > EnvironmentInfo; 155 typedef std::vector< EnvironmentInfo > EnvironmentStack; 156 157 void AcknowledgeResult(); 158 const csi::uidl::Token & 159 CurToken() const; 160 UnoIDL_PE & CurEnv() const; 161 UnoIDL_PE & PushEnv() const; 162 uintt CurTokenPosition() const; 163 uintt CurEnv_TriedTokenPosition() const; 164 void DecrementTryCount(); 165 166 EnvironmentStack aEnvironments; 167 TokenQueue aTokenQueue; 168 TokenIterator itCurToken; 169 TokenProcessing_Result 170 aCurResult; 171 uintt nTryCount; 172 bool bFinished; 173 ary::Repository & 174 rRepository; 175 ParserInfo & rParserInfo; 176 Documentation * pDocuProcessor; 177 bool bPublishedRecentlyOn; 178 }; 179 180 class Documentation : public csi::dsapi::Token_Receiver 181 { 182 public: 183 Documentation( 184 ParserInfo & io_rParserInfo); 185 ~Documentation(); 186 187 void Reset() { bIsPassedFirstDocu = false; } 188 189 virtual void Receive( 190 DYN csi::dsapi::Token & 191 let_drToken ); 192 virtual void Increment_CurLine(); 193 DYN ary::doc::OldIdlDocu * 194 ReleaseLastParsedDocu() 195 { return pMostRecentDocu.Release(); } 196 private: 197 Dyn<csi::dsapi::SapiDocu_PE> 198 pDocuParseEnv; 199 ParserInfo & rParserInfo; 200 Dyn<ary::doc::OldIdlDocu> 201 pMostRecentDocu; 202 bool bIsPassedFirstDocu; 203 }; 204 205 // DATA 206 TokenParser_Uidl * pTokenSource; 207 Documentation aDocumentation; 208 ProcessingData aProcessingData; 209 }; 210 211 212 213 // IMPLEMENTATION 214 215 inline void 216 TokenDistributor::SetTokenProvider( TokenParser_Uidl & io_rTokenSource ) 217 { pTokenSource = &io_rTokenSource; } 218 219 inline void 220 TokenDistributor::SetTopParseEnvironment( UnoIDL_PE & io_pTopParseEnvironment ) 221 { aProcessingData.SetTopParseEnvironment(io_pTopParseEnvironment); } 222 223 inline csi::uidl::Token_Receiver & 224 TokenDistributor::CodeTokens_Receiver() 225 { return aProcessingData; } 226 227 inline csi::dsapi::Token_Receiver & 228 TokenDistributor::DocuTokens_Receiver() 229 { return aDocumentation; } 230 231 inline const csi::uidl::Token & 232 TokenDistributor::ProcessingData::CurToken() const 233 { 234 csv_assert( itCurToken != aTokenQueue.end() ); 235 csv_assert( *itCurToken != 0 ); 236 return *(*itCurToken); 237 } 238 239 inline UnoIDL_PE & 240 TokenDistributor::ProcessingData::CurEnv() const 241 { 242 csv_assert( aEnvironments.size() > 0 ); 243 csv_assert( aEnvironments.back().first != 0 ); 244 return *aEnvironments.back().first; 245 } 246 247 inline UnoIDL_PE & 248 TokenDistributor::ProcessingData::PushEnv() const 249 { 250 csv_assert( aCurResult.pEnv2Push != 0 ); 251 return *aCurResult.pEnv2Push; 252 } 253 254 inline uintt 255 TokenDistributor::ProcessingData::CurTokenPosition() const 256 { 257 return itCurToken - aTokenQueue.begin(); 258 } 259 260 inline uintt 261 TokenDistributor::ProcessingData::CurEnv_TriedTokenPosition() const 262 { 263 csv_assert( aEnvironments.size() > 0 ); 264 return aEnvironments.back().second; 265 } 266 267 268 } // namespace uidl 269 } // namespace csi 270 271 #endif 272 273