Changeset 48779 in vbox for trunk/include/iprt/cpp
- Timestamp:
- Oct 1, 2013 2:14:13 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/xml.h
r46169 r48779 31 31 #endif 32 32 33 /*#define USE_STD_LIST_FOR_CHILDREN*/ 34 35 #include <iprt/list.h> 36 #include <iprt/cpp/exception.h> 37 33 38 #include <list> 34 39 #include <memory> 35 40 36 #include <iprt/cpp/exception.h>37 41 38 42 /** @defgroup grp_rt_cpp_xml C++ XML support … … 381 385 382 386 /** 383 * Node base class. Cannot be used directly, but ElementNode, ContentNode and 384 * AttributeNode derive from this. This does implement useful public methods though. 387 * Node base class. 388 * 389 * Cannot be used directly, but ElementNode, ContentNode and AttributeNode 390 * derive from this. This does implement useful public methods though. 391 * 392 * 385 393 */ 386 394 class RT_DECL_CLASS Node … … 389 397 ~Node(); 390 398 391 const char *getName() const;392 const char *getPrefix() const;393 const char *getNamespaceURI() const;399 const char *getName() const; 400 const char *getPrefix() const; 401 const char *getNamespaceURI() const; 394 402 bool nameEquals(const char *pcszNamespace, const char *pcsz) const; 395 403 bool nameEquals(const char *pcsz) const … … 397 405 return nameEquals(NULL, pcsz); 398 406 } 399 400 const char* getValue() const; 407 bool nameEqualsN(const char *pcszNamespace, const char *pcsz, size_t cchMax) const; 408 409 const char *getValue() const; 401 410 bool copyValue(int32_t &i) const; 402 411 bool copyValue(uint32_t &i) const; … … 404 413 bool copyValue(uint64_t &i) const; 405 414 415 /** @name Introspection. 416 * @{ */ 417 /** Is this an ElementNode instance. 418 * @returns true / false */ 419 bool isElement() const 420 { 421 return m_Type == IsElement; 422 } 423 424 /** Is this an ContentNode instance. 425 * @returns true / false */ 426 bool isContent() const 427 { 428 return m_Type == IsContent; 429 } 430 431 /** Is this an AttributeNode instance. 432 * @returns true / false */ 433 bool isAttribute() const 434 { 435 return m_Type == IsElement; 436 } 437 406 438 int getLineNumber() const; 407 439 408 int isElement() const 409 { 410 return m_Type == IsElement; 411 } 440 /** @} */ 441 442 #ifndef USE_STD_LIST_FOR_CHILDREN 443 /** @name General tree enumeration. 444 * 445 * Use the introspection methods isElement() and isContent() before doing static 446 * casting. Parents are always or ElementNode type, but siblings and children 447 * can be of both ContentNode and ElementNode types. 448 * 449 * @remarks Careful mixing tree walking with node removal! 450 * @{ 451 */ 452 /** Get the parent node 453 * @returns Pointer to the parent node, or NULL if root. */ 454 const Node *getParent() const 455 { 456 return m_pParent; 457 } 458 459 /** Get the first child node. 460 * @returns Pointer to the first child node, NULL if no children. */ 461 const Node *getFirstChild() const 462 { 463 return RTListGetFirst(&m_children, const Node, m_childEntry); 464 } 465 466 /** Get the last child node. 467 * @returns Pointer to the last child node, NULL if no children. */ 468 const Node *getLastChild() const 469 { 470 return RTListGetLast(&m_children, const Node, m_childEntry); 471 } 472 473 /** Get the previous sibling. 474 * @returns Pointer to the previous sibling node, NULL if first child. */ 475 const Node *getPrevSibiling() const 476 { 477 if (!m_pParent) 478 return NULL; 479 return RTListGetPrev(&m_pParent->m_children, this, const Node, m_childEntry); 480 } 481 482 /** Get the next sibling. 483 * @returns Pointer to the next sibling node, NULL if last child. */ 484 const Node *getNextSibiling() const 485 { 486 if (!m_pParent) 487 return NULL; 488 return RTListGetNext(&m_pParent->m_children, this, const Node, m_childEntry); 489 } 490 /** @} */ 491 #endif 412 492 413 493 protected: 414 typedef enum {IsElement, IsAttribute, IsContent} EnumType; 415 416 EnumType m_Type; 417 Node *m_pParent; 418 xmlNode *m_plibNode; // != NULL if this is an element or content node 419 xmlAttr *m_plibAttr; // != NULL if this is an attribute node 420 const char *m_pcszNamespacePrefix; // not always set 421 const char *m_pcszNamespaceHref; // full http:// spec 422 const char *m_pcszName; // element or attribute name, points either into plibNode or plibAttr; 423 // NULL if this is a content node 494 /** Node types. */ 495 typedef enum { IsElement, IsAttribute, IsContent } EnumType; 496 497 EnumType m_Type; /**< The type of node this is an instance of. */ 498 Node *m_pParent; /**< The parent node, NULL if root. */ 499 xmlNode *m_plibNode; ///< != NULL if this is an element or content node 500 xmlAttr *m_plibAttr; ///< != NULL if this is an attribute node 501 const char *m_pcszNamespacePrefix; ///< not always set 502 const char *m_pcszNamespaceHref; ///< full http:// spec 503 const char *m_pcszName; ///< element or attribute name, points either into plibNode or plibAttr; 504 ///< NULL if this is a content node 505 506 #ifndef USE_STD_LIST_FOR_CHILDREN 507 /** Child list entry of this node. (List head m_pParent->m_children.) */ 508 RTLISTNODE m_childEntry; 509 /** Child elements, if this is an element; can be empty. */ 510 RTLISTANCHOR m_children; 511 #endif 424 512 425 513 // hide the default constructor so people use only our factory methods … … 437 525 438 526 friend class AttributeNode; 527 friend class ElementNode; /* C list hack. */ 439 528 }; 440 529 … … 465 554 const ElementNode* findChildElementFromId(const char *pcszId) const; 466 555 556 const ElementNode *findChildElementDeep(const char *pcszNamespace, const char *pcszPath) const; 557 const ElementNode *findChildElementDeep(const char *pcszPath) const 558 { 559 return findChildElementDeep(NULL, pcszPath); 560 } 561 467 562 const AttributeNode* findAttribute(const char *pcszMatch) const; 468 bool getAttributeValue(const char *pcszMatch, const char *&p pcsz) const;563 bool getAttributeValue(const char *pcszMatch, const char *&pcsz) const; 469 564 bool getAttributeValue(const char *pcszMatch, RTCString &str) const; 470 565 bool getAttributeValuePath(const char *pcszMatch, RTCString &str) const; … … 474 569 bool getAttributeValue(const char *pcszMatch, uint64_t &i) const; 475 570 bool getAttributeValue(const char *pcszMatch, bool &f) const; 571 572 /** @name Variants that for clarity does not use references for output params. 573 * @{ */ 574 bool getAttributeValue(const char *pcszMatch, const char **ppcsz) const { return getAttributeValue(pcszMatch, *ppcsz); } 575 bool getAttributeValue(const char *pcszMatch, RTCString *pStr) const { return getAttributeValue(pcszMatch, *pStr); } 576 bool getAttributeValuePath(const char *pcszMatch, RTCString *pStr) const { return getAttributeValuePath(pcszMatch, *pStr); } 577 bool getAttributeValue(const char *pcszMatch, int32_t *pi) const { return getAttributeValue(pcszMatch, *pi); } 578 bool getAttributeValue(const char *pcszMatch, uint32_t *pu) const { return getAttributeValue(pcszMatch, *pu); } 579 bool getAttributeValue(const char *pcszMatch, int64_t *pi) const { return getAttributeValue(pcszMatch, *pi); } 580 bool getAttributeValue(const char *pcszMatch, uint64_t *pu) const { return getAttributeValue(pcszMatch, *pu); } 581 bool getAttributeValue(const char *pcszMatch, bool *pf) const { return getAttributeValue(pcszMatch, *pf); } 582 /** @} */ 583 476 584 477 585 ElementNode* createChild(const char *pcszElementName);
Note:
See TracChangeset
for help on using the changeset viewer.