source: tags/svn.1.5.4/XML/xml.hxx

Last change on this file was 7623, checked in by westram, 13 years ago
  • merge from dev [7450] [7452] [7456] [7457] [7458] [7459] [7460] [7461] [7464] [7465] [7466] [7467] [7468] [7469] [7482]
    • tweaked compiler options
      • activated -Weffc++
        • postfilter warnings where Scott Meyers' advices are too general.
          • base classes should not always have virtual destructors, since that renders tiny classes useless and
          • members should not always be initialized via initialization list, since that often violates the DRY principle
        • fix gcc's inability to detect that Noncopyable implements a private copy-ctor and op=
        • this slows down complete ARB recompilation by ~5%
    • added -Wold-style-cast (inactive)
    • removed -Wno-non-template-friend added in [7447]
  • postcompile.pl
    • added option —original to show unmodified compiler output
  • declared op= for classes which had a copy-ctor
  • moved op= macros to arbtools.h
  • derived classes containing pointers from Noncopyable (use Noncopyable virtually) or
  • made them copyable if needed (awt_mask_item, KnownDB, Code, AWT_registered_itemtype, GEN_gene, PosGene, PartialSequence, PlugIn, Range, Convaln_exception)
  • other related changes
    • user mask destruction working now
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1// --------------------------------------------------------------------------------
2// Copyright (C) 2001
3// Ralf Westram
4//
5// Permission to use, copy, modify, distribute and sell this software
6// and its documentation for any purpose is hereby granted without fee,
7// provided that the above copyright notice appear in all copies and
8// that both that copyright notice and this permission notice appear
9// in supporting documentation.  Ralf Westram makes no
10// representations about the suitability of this software for any
11// purpose.  It is provided "as is" without express or implied warranty.
12//
13// This code is part of my library.
14// You may find a more recent version at http://www.reallysoft.de/
15// --------------------------------------------------------------------------------
16
17#ifndef XML_HXX
18#define XML_HXX
19
20#ifndef __STRING__
21#include <string>
22#endif
23#ifndef __CSTDIO__
24#include <cstdio>
25#endif
26
27#ifndef ATTRIBUTES_H
28#include <attributes.h>
29#endif
30#ifndef ARB_ASSERT_H
31#include <arb_assert.h>
32#endif
33#ifndef ARBTOOLS_H
34#include <arbtools.h>
35#endif
36
37#define xml_assert(bed) arb_assert(bed)
38
39
40/*! @memo Classes used to write xml
41    @doc  In order to write xml to a stream just open an XML_Document and create and destroy the needed tags.
42*/
43
44class                XML_Document;
45extern XML_Document *the_XML_Document; // there can only be one at a time
46
47//  ----------------------------
48//      class XML_Attribute
49//  ----------------------------
50class XML_Attribute : virtual Noncopyable {
51private:
52    std::string    name;
53    std::string    content;
54    XML_Attribute *next;
55
56public:
57    XML_Attribute(const std::string& name_, const std::string& content_);
58    virtual ~XML_Attribute();
59
60    XML_Attribute *append_to(XML_Attribute *queue);
61
62    void print(FILE *out) const;
63};
64
65
66//  -----------------------
67//      class XML_Node
68//  -----------------------
69class XML_Node : virtual Noncopyable {
70protected:
71    XML_Node *father;
72    bool      opened;
73    int       indent;
74
75public:
76    XML_Node(bool is_tag);
77    virtual ~XML_Node();
78
79    int Indent() const { return indent; }
80    bool Opened() const { return opened; }
81
82    virtual void add_son(XML_Node *son_, bool son_is_tag) = 0;
83    virtual void remove_son(XML_Node *son_)               = 0;
84    virtual void open(FILE *out)                          = 0;
85    virtual void close(FILE *out)                         = 0;
86};
87
88//  ----------------------------------------
89//      class XML_Tag : public XML_Node
90//  ----------------------------------------
91
92//! xml element
93class XML_Tag : public XML_Node {  // derived from a Noncopyable
94private:
95    std::string    name;
96    XML_Node      *son;
97    XML_Attribute *attribute;
98    int            state;       // 0        = no son; 1 = only content; 2 = son-tag;
99    bool           onExtraLine; // default = true; if false -> does not print linefeed before tag
100
101public:
102    /*! Create a new xml element
103        @param name_ element name
104    */
105    XML_Tag(const std::string &name_);
106    virtual ~XML_Tag();
107
108    /*! add an attribute to the XML_Tag
109        @param name_ attribute name
110        @param content_ attribute value
111    */
112    void         add_attribute(const std::string& name_, const std::string& content_);
113    void         add_attribute(const std::string& name_, int value);
114    virtual void add_son(XML_Node *son_, bool son_is_tag);
115    virtual void remove_son(XML_Node *son_);
116    virtual void open(FILE *out);
117    virtual void close(FILE *out);
118
119    void set_on_extra_line(bool oel) { onExtraLine = oel; }
120};
121
122//! a xml text node
123class XML_Text : public XML_Node {
124private:
125    std::string content;
126
127public:
128    /*! Create text (content) in xml
129        @param content_ the content
130    */
131    XML_Text(const std::string& content_) : XML_Node(false), content(content_) {}
132    virtual ~XML_Text();
133
134    virtual void add_son(XML_Node *son_, bool son_is_tag) __ATTR__NORETURN;
135    virtual void remove_son(XML_Node *son_) __ATTR__NORETURN;
136    virtual void open(FILE *);
137    virtual void close(FILE *out);
138};
139
140class XML_Comment : public XML_Node {
141    std::string content;
142public:
143    XML_Comment(const std::string& content_) : XML_Node(false), content(content_) {}
144    virtual ~XML_Comment();
145
146    virtual void add_son(XML_Node *son_, bool son_is_tag) __ATTR__NORETURN;
147    virtual void remove_son(XML_Node *son_) __ATTR__NORETURN;
148    virtual void open(FILE *);
149    virtual void close(FILE *out);
150};
151
152//! an entire xml document
153class XML_Document : virtual Noncopyable {
154private:
155    std::string  dtd;
156    XML_Tag     *root;
157    XML_Node    *latest_son;
158    FILE        *out;
159
160public:
161    /*! Create and stream (at destruction) a xml document
162        @param name_ name of the root node
163        @param dtd_ filename of dtd
164        @param out_ FILE where xml document will be written to
165    */
166    XML_Document(const std::string& name_, const std::string& dtd_, FILE *out_);
167    virtual ~XML_Document();
168
169    //! true -> tags w/o content or attributes are skipped (default = false)
170    bool skip_empty_tags;
171
172    //! how many columns are used per indentation level (defaults to 1)
173    size_t indentation_per_level;
174
175    XML_Node* LatestSon() { return latest_son; }
176    void set_LatestSon(XML_Node* latest_son_) { latest_son = latest_son_; }
177
178    XML_Tag& getRoot() { return *root; }
179
180    void add_attribute(const std::string& name_, const std::string& content_) {
181        getRoot().add_attribute(name_, content_);
182    }
183
184    FILE *Out() { return out; }
185};
186
187#else
188#error xml.hxx included twice
189#endif // XML_HXX
Note: See TracBrowser for help on using the repository browser.