~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to include/iprt/cpp/xml.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <list>
34
34
#include <memory>
35
35
 
36
 
#include <iprt/cpp/ministring.h>
 
36
#include <iprt/cpp/exception.h>
37
37
 
38
38
/* Forwards */
39
39
typedef struct _xmlParserInput xmlParserInput;
52
52
// Exceptions
53
53
//////////////////////////////////////////////////////////////////////////////
54
54
 
55
 
/**
56
 
 * Base exception class.
57
 
 */
58
 
class RT_DECL_CLASS Error : public std::exception
59
 
{
60
 
public:
61
 
 
62
 
    Error(const char *pcszMessage)
63
 
        : m_s(pcszMessage)
64
 
    {
65
 
    }
66
 
 
67
 
    Error(const Error &s)
68
 
        : std::exception(s),
69
 
          m_s(s.what())
70
 
    {
71
 
    }
72
 
 
73
 
    virtual ~Error() throw()
74
 
    {
75
 
    }
76
 
 
77
 
    void operator=(const Error &s)
78
 
    {
79
 
        m_s = s.what();
80
 
    }
81
 
 
82
 
    void setWhat(const char *pcszMessage)
83
 
    {
84
 
        m_s = pcszMessage;
85
 
    }
86
 
 
87
 
    virtual const char* what() const throw()
88
 
    {
89
 
        return m_s.c_str();
90
 
    }
91
 
 
92
 
private:
93
 
    // hide the default constructor to make sure the extended one above is always used
94
 
    Error();
95
 
 
96
 
    iprt::MiniString m_s;
97
 
};
98
 
 
99
 
class RT_DECL_CLASS LogicError : public Error
 
55
class RT_DECL_CLASS LogicError : public iprt::Error
100
56
{
101
57
public:
102
58
 
103
59
    LogicError(const char *aMsg = NULL)
104
 
        : xml::Error(aMsg)
 
60
        : iprt::Error(aMsg)
105
61
    {}
106
62
 
107
63
    LogicError(RT_SRC_POS_DECL);
108
64
};
109
65
 
110
 
class RT_DECL_CLASS RuntimeError : public Error
 
66
class RT_DECL_CLASS RuntimeError : public iprt::Error
111
67
{
112
68
public:
113
69
 
114
70
    RuntimeError(const char *aMsg = NULL)
115
 
        : xml::Error(aMsg)
 
71
        : iprt::Error(aMsg)
116
72
    {}
117
73
};
118
74
 
173
129
    int mRC;
174
130
};
175
131
 
176
 
 
177
132
/**
178
133
 * The Stream class is a base class for I/O streams.
179
134
 */
405
360
    struct Data *m;
406
361
};
407
362
 
408
 
/**
409
 
 * Node:
410
 
 *  an XML node, which represents either an element or text content
411
 
 *  or an attribute.
412
 
 *
413
 
 *  For elements, getName() returns the element name, and getValue()
414
 
 *  returns the text contents, if any.
415
 
 *
416
 
 *  For attributes, getName() returns the attribute name, and getValue()
417
 
 *  returns the attribute value, if any.
418
 
 *
419
 
 *  Since the default constructor is private, one can create new nodes
420
 
 *  only through factory methods provided by the XML classes. These are:
421
 
 *
422
 
 *  --  xml::Document::createRootElement()
423
 
 *  --  xml::Node::createChild()
424
 
 *  --  xml::Node::addContent()
425
 
 *  --  xml::Node::setAttribute()
426
 
 */
427
 
 
428
363
class ElementNode;
429
364
typedef std::list<const ElementNode*> ElementNodesList;
430
365
 
432
367
 
433
368
class ContentNode;
434
369
 
 
370
/**
 
371
 * Node base class. Cannot be used directly, but ElementNode, ContentNode and
 
372
 * AttributeNode derive from this. This does implement useful public methods though.
 
373
 */
435
374
class RT_DECL_CLASS Node
436
375
{
437
376
public:
485
424
    friend class AttributeNode;
486
425
};
487
426
 
 
427
/**
 
428
 *  Node subclass that represents an element.
 
429
 *
 
430
 *  For elements, Node::getName() returns the element name, and Node::getValue()
 
431
 *  returns the text contents, if any.
 
432
 *
 
433
 *  Since the Node constructor is private, one can create element nodes
 
434
 *  only through the following factory methods:
 
435
 *
 
436
 *  --  Document::createRootElement()
 
437
 *  --  ElementNode::createChild()
 
438
 */
488
439
class RT_DECL_CLASS ElementNode : public Node
489
440
{
490
441
public:
502
453
    const AttributeNode* findAttribute(const char *pcszMatch) const;
503
454
    bool getAttributeValue(const char *pcszMatch, const char *&ppcsz) const;
504
455
    bool getAttributeValue(const char *pcszMatch, iprt::MiniString &str) const;
 
456
    bool getAttributeValuePath(const char *pcszMatch, iprt::MiniString &str) const;
505
457
    bool getAttributeValue(const char *pcszMatch, int32_t &i) const;
506
458
    bool getAttributeValue(const char *pcszMatch, uint32_t &i) const;
507
459
    bool getAttributeValue(const char *pcszMatch, int64_t &i) const;
521
473
    {
522
474
        return setAttribute(pcszName, strValue.c_str());
523
475
    }
 
476
    AttributeNode* setAttributePath(const char *pcszName, const iprt::MiniString &strValue);
524
477
    AttributeNode* setAttribute(const char *pcszName, int32_t i);
525
478
    AttributeNode* setAttribute(const char *pcszName, uint32_t i);
526
479
    AttributeNode* setAttribute(const char *pcszName, int64_t i);
540
493
    friend class XmlFileParser;
541
494
};
542
495
 
 
496
/**
 
497
 * Node subclass that represents content (non-element text).
 
498
 *
 
499
 * Since the Node constructor is private, one can create new content nodes
 
500
 * only through the following factory methods:
 
501
 *
 
502
 *  --  ElementNode::addContent()
 
503
 */
543
504
class RT_DECL_CLASS ContentNode : public Node
544
505
{
545
506
public:
553
514
    friend class ElementNode;
554
515
};
555
516
 
 
517
/**
 
518
 * Node subclass that represents an attribute of an element.
 
519
 *
 
520
 * For attributes, Node::getName() returns the attribute name, and Node::getValue()
 
521
 * returns the attribute value, if any.
 
522
 *
 
523
 * Since the Node constructor is private, one can create new attribute nodes
 
524
 * only through the following factory methods:
 
525
 *
 
526
 *  --  ElementNode::setAttribute()
 
527
 */
556
528
class RT_DECL_CLASS AttributeNode : public Node
557
529
{
558
530
public:
571
543
    friend class ElementNode;
572
544
};
573
545
 
574
 
/*
575
 
 * NodesLoop
576
 
 *
 
546
/**
 
547
 * Handy helper class with which one can loop through all or some children
 
548
 * of a particular element. See NodesLoop::forAllNodes() for details.
577
549
 */
578
 
 
579
550
class RT_DECL_CLASS NodesLoop
580
551
{
581
552
public:
589
560
    Data *m;
590
561
};
591
562
 
592
 
/*
593
 
 * Document
594
 
 *
 
563
/**
 
564
 * The XML document class. An instance of this needs to be created by a user
 
565
 * of the XML classes and then passed to
 
566
 *
 
567
 * --   XmlMemParser or XmlFileParser to read an XML document; those classes then
 
568
 *      fill the caller's Document with ElementNode, ContentNode and AttributeNode
 
569
 *      instances. The typical sequence then is:
 
570
 * @code
 
571
    Document doc;
 
572
    XmlFileParser parser;
 
573
    parser.read("file.xml", doc);
 
574
    Element *pelmRoot = doc.getRootElement();
 
575
   @endcode
 
576
 *
 
577
 * --   XmlMemWriter or XmlFileWriter to write out an XML document after it has
 
578
 *      been created and filled. Example:
 
579
 *
 
580
 * @code
 
581
    Document doc;
 
582
    Element *pelmRoot = doc.createRootElement();
 
583
    // add children
 
584
    xml::XmlFileWriter writer(doc);
 
585
    writer.write("file.xml", true);
 
586
   @endcode
595
587
 */
596
 
 
597
588
class RT_DECL_CLASS Document
598
589
{
599
590
public:
609
600
    ElementNode* createRootElement(const char *pcszRootElementName);
610
601
 
611
602
private:
 
603
    friend class XmlMemParser;
612
604
    friend class XmlFileParser;
 
605
    friend class XmlMemWriter;
613
606
    friend class XmlFileWriter;
614
607
 
615
608
    void refreshInternals();
634
627
};
635
628
 
636
629
/*
 
630
 * XmlMemParser
 
631
 *
 
632
 */
 
633
 
 
634
class RT_DECL_CLASS XmlMemParser : public XmlParserBase
 
635
{
 
636
public:
 
637
    XmlMemParser();
 
638
    ~XmlMemParser();
 
639
 
 
640
    void read(const void* pvBuf, size_t cbSize, const iprt::MiniString &strFilename, Document &doc);
 
641
};
 
642
 
 
643
/*
637
644
 * XmlFileParser
638
645
 *
639
646
 */
656
663
};
657
664
 
658
665
/*
 
666
 * XmlMemParser
 
667
 *
 
668
 */
 
669
 
 
670
class RT_DECL_CLASS XmlMemWriter
 
671
{
 
672
public:
 
673
    XmlMemWriter();
 
674
    ~XmlMemWriter();
 
675
 
 
676
    void write(const Document &doc, void** ppvBuf, size_t *pcbSize);
 
677
 
 
678
private:
 
679
    void* m_pBuf;
 
680
};
 
681
 
 
682
/*
659
683
 * XmlFileWriter
660
684
 *
661
685
 */