00001 /* 00002 * Copyright 1999-2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #if !defined(XALAN_VARIABLESSTACK_HEADER_GUARD) 00017 #define XALAN_VARIABLESSTACK_HEADER_GUARD 00018 00019 00020 00021 // Base include file. Must be first. 00022 #include <xalanc/XSLT/XSLTDefinitions.hpp> 00023 00024 00025 00026 #include <cassert> 00027 00028 00029 00030 #include <xalanc/Include/XalanVector.hpp> 00031 00032 00033 00034 #include <xalanc/XPath/XalanQName.hpp> 00035 #include <xalanc/XPath/XObject.hpp> 00036 00037 00038 00039 #include <xalanc/XSLT/XSLTProcessorException.hpp> 00040 00041 00042 00043 XALAN_CPP_NAMESPACE_BEGIN 00044 00045 00046 00047 class Arg; 00048 class ElemTemplateElement; 00049 class ElemVariable; 00050 class StylesheetExecutionContext; 00051 class XalanNode; 00052 00053 00054 00058 class XALAN_XSLT_EXPORT VariablesStack 00059 { 00060 public: 00061 00062 typedef unsigned long size_type; 00063 00067 explicit 00068 VariablesStack(MemoryManagerType& theManager); 00069 00070 ~VariablesStack(); 00071 00075 void 00076 reset(); 00077 00083 void 00084 pushElementFrame(const ElemTemplateElement* elem); 00085 00091 void 00092 popElementFrame(); 00093 00101 void 00102 pushContextMarker(); 00103 00107 void 00108 popContextMarker(); 00109 00110 struct ParamsVectorEntry 00111 { 00112 ParamsVectorEntry() : 00113 m_qname(0), 00114 m_value(), 00115 m_variable(0) 00116 { 00117 } 00118 00119 ParamsVectorEntry( 00120 const XalanQName* qname, 00121 const XObjectPtr value) : 00122 m_qname(qname), 00123 m_value(value), 00124 m_variable(0) 00125 { 00126 } 00127 00128 ParamsVectorEntry( 00129 const XalanQName* qname, 00130 const ElemVariable* variable) : 00131 m_qname(qname), 00132 m_value(), 00133 m_variable(variable) 00134 { 00135 } 00136 00137 const XalanQName* m_qname; 00138 00139 XObjectPtr m_value; 00140 00141 const ElemVariable* m_variable; 00142 }; 00143 00144 typedef XalanVector<ParamsVectorEntry> ParamsVectorType; 00145 typedef XalanVector<const ElemVariable*> RecursionGuardStackType; 00146 typedef XalanVector<const ElemTemplateElement*> ElemTemplateElementStackType; 00147 00154 void 00155 pushParams(const ParamsVectorType& theParams); 00156 00167 const XObjectPtr 00168 getParamVariable( 00169 const XalanQName& qname, 00170 StylesheetExecutionContext& executionContext, 00171 bool& fNameFound) 00172 { 00173 return findXObject(qname, executionContext, true, false, fNameFound); 00174 } 00175 00187 const XObjectPtr 00188 getVariable( 00189 const XalanQName& qname, 00190 StylesheetExecutionContext& executionContext, 00191 bool& fNameFound) 00192 { 00193 return findXObject(qname, executionContext, false, true, fNameFound); 00194 } 00195 00205 void 00206 pushVariable( 00207 const XalanQName& name, 00208 const ElemVariable* var, 00209 const ElemTemplateElement* e); 00210 00220 void 00221 pushVariable( 00222 const XalanQName& name, 00223 const XObjectPtr& val, 00224 const ElemTemplateElement* e); 00225 00229 void 00230 start(); 00231 00235 void 00236 resetParams(); 00237 00241 void 00242 markGlobalStackFrame(); 00243 00247 void 00248 unmarkGlobalStackFrame(); 00249 00257 void 00258 setCurrentStackFrameIndex(size_type currentStackFrameIndex = ~0u) 00259 { 00260 if (currentStackFrameIndex == ~0u) 00261 { 00262 assert(size_type(m_stack.size()) == m_stack.size()); 00263 00264 m_currentStackFrameIndex = size_type(m_stack.size()); 00265 } 00266 else 00267 { 00268 m_currentStackFrameIndex = currentStackFrameIndex; 00269 } 00270 } 00271 00278 size_type 00279 getCurrentStackFrameIndex() const 00280 { 00281 return m_currentStackFrameIndex; 00282 } 00283 00289 size_type 00290 getGlobalStackFrameIndex() const 00291 { 00292 return m_globalStackFrameIndex; 00293 } 00294 00295 class InvalidStackContextException : public XSLTProcessorException 00296 { 00297 public: 00298 00299 InvalidStackContextException(XalanDOMString& theResult); 00300 00301 virtual 00302 ~InvalidStackContextException(); 00303 00304 00305 virtual const XalanDOMChar* 00306 getType() const 00307 { 00308 return m_type; 00309 } 00310 00311 private: 00312 00313 static const XalanDOMChar m_type[]; 00314 00315 }; 00316 00317 class PushParamFunctor 00318 { 00319 public: 00320 00321 PushParamFunctor(VariablesStack& theVariablesStack) : 00322 m_variablesStack(theVariablesStack) 00323 { 00324 } 00325 00326 void 00327 operator()(const ParamsVectorType::value_type& theEntry) const; 00328 00329 private: 00330 00331 VariablesStack& m_variablesStack; 00332 }; 00333 00334 class XALAN_XSLT_EXPORT StackEntry 00335 { 00336 public: 00337 00342 enum eType { eContextMarker, 00343 eVariable, 00344 eParam, 00345 eActiveParam, 00346 eElementFrameMarker, 00347 eNextValue }; 00348 00352 explicit 00353 StackEntry(); 00354 00358 StackEntry( 00359 const XalanQName* name, 00360 const XObjectPtr& val, 00361 bool isParam = false); 00362 00366 StackEntry( 00367 const XalanQName* name, 00368 const ElemVariable* var, 00369 bool isParam = false); 00370 00374 StackEntry(const ElemTemplateElement* elem); 00375 00376 00380 StackEntry(const StackEntry& theSource); 00381 00385 ~StackEntry(); 00386 00392 eType 00393 getType() const 00394 { 00395 return m_type; 00396 } 00397 00403 const XalanQName* 00404 getName() const 00405 { 00406 return m_qname; 00407 } 00408 00414 const XObjectPtr& 00415 getValue() const 00416 { 00417 return m_value; 00418 } 00419 00425 void 00426 setValue(const XObjectPtr& theValue) 00427 { 00428 m_value = theValue; 00429 } 00430 00436 const ElemVariable* 00437 getVariable() const 00438 { 00439 return m_variable; 00440 } 00441 00442 void 00443 activate(); 00444 00445 void 00446 deactivate(); 00447 00453 const ElemTemplateElement* 00454 getElement() const 00455 { 00456 return m_element; 00457 } 00458 00459 StackEntry& 00460 operator=(const StackEntry& theRHS); 00461 00462 bool 00463 operator==(const StackEntry& theRHS) const; 00464 00465 private: 00466 00467 // Data members... 00468 eType m_type; 00469 00470 const XalanQName* m_qname; 00471 00472 XObjectPtr m_value; 00473 00474 const ElemVariable* m_variable; 00475 00476 const ElemTemplateElement* m_element; 00477 }; 00478 00479 typedef XalanVector<StackEntry> VariableStackStackType; 00480 00481 size_type 00482 getStackSize() const 00483 { 00484 return size_type(m_stack.size()); 00485 } 00486 00487 enum { eDefaultStackSize = 100 }; 00488 00489 private: 00490 00491 class CommitPushParams 00492 { 00493 public: 00494 00495 CommitPushParams(VariablesStack& theVariablesStack); 00496 00497 ~CommitPushParams(); 00498 00499 void 00500 commit() 00501 { 00502 m_variablesStack = 0; 00503 } 00504 00505 private: 00506 00507 VariablesStack* m_variablesStack; 00508 00509 size_type m_stackSize; 00510 }; 00511 00512 friend class CommitPushParams; 00513 00521 bool 00522 elementFrameAlreadyPushed(const ElemTemplateElement* elem) const; 00523 00529 void 00530 push(const StackEntry& theEntry); 00531 00535 void 00536 pop(); 00537 00543 const StackEntry& 00544 back() const 00545 { 00546 assert(m_stack.empty() == false); 00547 00548 return m_stack.back(); 00549 } 00550 00551 friend class CommitPushElementFrame; 00552 friend class EnsurePop; 00553 friend class PushParamFunctor; 00554 friend class SetAndRestoreForceGlobalSearch; 00555 00556 const XObjectPtr 00557 findXObject( 00558 const XalanQName& name, 00559 StylesheetExecutionContext& executionContext, 00560 bool fIsParam, 00561 bool fSearchGlobalSpace, 00562 bool& fNameFound); 00563 00564 size_type 00565 findEntry( 00566 const XalanQName& name, 00567 bool fIsParam, 00568 bool fSearchGlobalSpace); 00569 00570 00571 VariableStackStackType m_stack; 00572 00573 size_type m_globalStackFrameIndex; 00574 00575 bool m_globalStackFrameMarked; 00576 00582 size_type m_currentStackFrameIndex; 00583 00589 RecursionGuardStackType m_guardStack; 00590 00595 ElemTemplateElementStackType m_elementFrameStack; 00596 }; 00597 00598 00599 00600 XALAN_CPP_NAMESPACE_END 00601 00602 00603 00604 #endif // #if !defined(XALAN_VARIABLESSTACK_HEADER_GUARD)
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.10 |
|