00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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* 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 {
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;
00328
00329
if (this->
SelfDeleting)
00330 {
00331 parent->
OrphanChild(
this);
00332
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);
00351 }
00352
00353
00354
inline void
00355 vtkNestingExpatBase::NestedEndElementCb (
void* aPtr,
00356
const XML_Char* aName)
00357 {
00358
if (aPtr == NULL) {
return; }
00359
00360 vtkNestingExpatBase* parser = reinterpret_cast<vtkNestingExpatBase*>(aPtr);
00361
00362
00363
if (parser->
Depth == 0)
00364 {
00365 vtkNestingExpatBase* parentParser = parser->
ReturnToParent();
00366
00367
00368
00369
vtkNestingExpatBase::NestedEndElementCb(parentParser, aName);
00370 }
00371
else
00372 {
00373
00374 parser->
EndElement(aName);
00375 parser->
Depth--;
00376 }
00377 }
00378
00379
VTK_EXTENSIONS_NAMESPACE_END
00380
00381
#endif
00382
00383
00384
00385