Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

vtkNestingExpatBase.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 * 00003 * $Id: vtkNestingExpatBase.h,v 1.3 2004/05/29 23:19:34 xpxqx Exp $ 00004 * 00005 * Copyright (c) 2004 Sean McInerney 00006 * All rights reserved. 00007 * 00008 * See Copyright.txt or http://vtkextensions.sourceforge.net/Copyright.html 00009 * for details. 00010 * 00011 * This software is distributed WITHOUT ANY WARRANTY; without even 00012 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 * PURPOSE. See the above copyright notice for more information. 00014 * 00015 */ 00016 #ifndef VTK_NESTING_EXPAT_BASE_H_ 00017 # define VTK_NESTING_EXPAT_BASE_H_ 00018 # include "vtkExpatBase.h" 00019 00020 VTK_EXTENSIONS_NAMESPACE_BEGIN 00021 00114 class VTK_EXTENSIONS_COMMON_EXPORT vtkNestingExpatBase : public vtkExpatBase 00115 { 00116 public: 00117 vtkTypeRevisionMacro (vtkNestingExpatBase, vtkExpatBase); 00118 void PrintSelf (ostream&, vtkIndent); 00119 00143 void RedirectInternalParser (vtkNestingExpatBase* aChild); 00144 00149 virtual vtkNestingExpatBase* ReturnToParent (void); 00150 00152 virtual vtkNestingExpatBase* GetChild (void) const; 00153 00154 public: 00158 static void NestedStartElementCb (void* aPtr, 00159 const XML_Char* aName, 00160 const XML_Char** aAttrs); 00161 00163 static void NestedEndElementCb (void* aPtr, 00164 const XML_Char* aName); 00167 protected: 00172 vtkNestingExpatBase (vtkNestingExpatBase* parent = NULL); 00173 ~vtkNestingExpatBase(); 00174 00179 virtual void SetupHandlers (void); 00180 00188 virtual void SetChild (vtkNestingExpatBase* /*const&*/ child); 00189 00191 virtual void DeleteChild (void); 00192 00194 void GrabInternalParserFromParent (void); 00195 00218 void SetParent (vtkNestingExpatBase* aParent); 00219 00224 void OrphanChild (vtkNestingExpatBase* aCallingChild); 00225 00229 vtkNestingExpatBase* Parent; 00230 00232 int Depth; 00233 00235 bool SelfDeleting; 00236 00238 vtkNestingExpatBase* Child; 00241 private: 00247 vtkNestingExpatBase (const vtkNestingExpatBase&); 00248 void operator= (const vtkNestingExpatBase&); 00250 }; 00251 00252 00253 // ---------------------------------------------------------------------------- 00254 inline void 00255 vtkNestingExpatBase::GrabInternalParserFromParent (void) 00256 { 00257 assert(this->Parent != NULL); 00258 00259 vtkDebugMacro(<< "GrabInternalParserFromParent()"); 00260 00261 this->Parser = this->Parent->Parser; 00262 this->GrabInternalParser(); 00263 00264 this->Modified(); 00265 } 00266 00267 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00268 inline void 00269 vtkNestingExpatBase::SetParent (vtkNestingExpatBase* aParent) 00270 { 00271 vtkDebugMacro(<< "SetParent(" << aParent << ")"); 00272 00273 if (this->Parent != NULL) 00274 { 00275 assert(this->Parent == aParent); 00276 } 00277 else 00278 { // root parser being adopted, cleanup! 00279 this->ReleaseParser(); 00280 this->Parent = aParent; 00281 this->GrabInternalParserFromParent(); 00282 } 00283 00284 this->SelfDeleting = false; 00285 00286 this->Modified(); 00287 } 00288 00289 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00290 inline void 00291 vtkNestingExpatBase::RedirectInternalParser (vtkNestingExpatBase* aChild) 00292 { 00293 assert(aChild != NULL); 00294 00295 vtkDebugMacro(<< "RedirectInternalParser(" << aChild << ")"); 00296 00297 this->SetChild(aChild); 00298 aChild->SetParent(this); 00299 } 00300 00301 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00302 inline void 00303 vtkNestingExpatBase::OrphanChild (vtkNestingExpatBase* aCallingChild) 00304 { 00305 assert(aCallingChild == this->Child); 00306 00307 vtkDebugMacro(<< "OrphanChild(" << aCallingChild << ")"); 00308 00309 this->Child = NULL; 00310 00311 this->Modified(); 00312 } 00313 00314 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00315 inline vtkNestingExpatBase* 00316 vtkNestingExpatBase::ReturnToParent (void) 00317 { 00318 assert(this->Parent != NULL); 00319 00320 vtkNestingExpatBase* parent = this->Parent; 00321 00322 vtkDebugMacro(<< "ReturnToParent() returning " << parent); 00323 00324 this->Parent->GrabInternalParser(); 00325 00326 this->Parent = NULL; 00327 this->Parser = NULL; // Prevent parser shutdown by destructor! 00328 00329 if (this->SelfDeleting) 00330 { 00331 parent->OrphanChild(this); 00332 // MUST BE LAST THING CALLED IN NON-VIRTUAL FUNCTION, NO MEMBER ACCESS 00333 this->Delete(); 00334 } 00335 00336 return parent; 00337 } 00338 00339 // ---------------------------------------------------------------------------- 00340 inline void 00341 vtkNestingExpatBase::NestedStartElementCb (void* aPtr, 00342 const XML_Char* aName, 00343 const XML_Char** aAttrs) 00344 { 00345 assert(aPtr != NULL); 00346 00347 vtkNestingExpatBase* parser = reinterpret_cast<vtkNestingExpatBase*>(aPtr); 00348 00349 parser->Depth++; 00350 parser->StartElement(aName, aAttrs); // probably user override 00351 } 00352 00353 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00354 inline void 00355 vtkNestingExpatBase::NestedEndElementCb (void* aPtr, 00356 const XML_Char* aName) 00357 { 00358 if (aPtr == NULL) { return; } // This is end tag callback of a root parser. 00359 00360 vtkNestingExpatBase* parser = reinterpret_cast<vtkNestingExpatBase*>(aPtr); 00361 00362 // We don't know until we hit a closing tag 'outside' us that our run is done. 00363 if (parser->Depth == 0) 00364 { 00365 vtkNestingExpatBase* parentParser = parser->ReturnToParent(); 00366 // Callbacks for vtkNestingExpatBase stay registered, so safe 00367 // If we don't invoke their callback, they will not balance 00368 // their \c vtkNestingExpatBase::Depth. 00369 vtkNestingExpatBase::NestedEndElementCb(parentParser, aName); 00370 } 00371 else 00372 { 00373 // end of an element this parser has started 00374 parser->EndElement(aName); // probably user override 00375 parser->Depth--; 00376 } 00377 } 00378 00379 VTK_EXTENSIONS_NAMESPACE_END 00380 00381 #endif /* VTK_NESTING_EXPAT_BASE_H_ */ 00382 /* 00383 * End of: $Id: vtkNestingExpatBase.h,v 1.3 2004/05/29 23:19:34 xpxqx Exp $. 00384 * 00385 */

Generated on Tue Aug 10 03:37:40 2004 for vtkExtensions by doxygen 1.3.7