File: xmlwrite.h

package info (click to toggle)
fig2sxd 0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,508 kB
  • sloc: cpp: 2,345; makefile: 39
file content (96 lines) | stat: -rw-r--r-- 2,666 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// -*-c++-*-

// fixg2sxd - a utility to convert fig to sxd format

// Copyright (C) 2003-2022 Alexander Bürger, acfb@users.sourceforge.net

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#ifndef _hdr_XMLWRITE_H
#define _hdr_XMLWRITE_H

#ifdef USE_MAP
#include <map>
#endif
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

// ------------------------------------------------------------------------

class Element {
public:
    Element() { }
    virtual void write(std::ostream&,int,bool) const = 0;
    virtual ~Element() { }
private:
    Element(Element const&); // disabled
    Element& operator=(Element const&); // disabled
};

inline std::ostream& operator<<( std::ostream& o, Element const* e )
{
    e->write( o, 0, true );
    return o;
}

inline std::ostream& operator<<( std::ostream& o, Element const& e )
{
    e.write( o, 0, true );
    return o;
}

// ------------------------------------------------------------------------

class TextElement : public Element
{
    std::ostringstream text;
public:
    std::ostringstream& t() { return text; }
    virtual void write(std::ostream&,int,bool) const;
    virtual ~TextElement() { }
};

// ------------------------------------------------------------------------

class Node : public Element
{
    std::string name;
    bool indentation;
    std::vector<Element*> elements;
#ifdef USE_MAP
    typedef std::map<std::string,std::ostringstream*> attributes_t;
#else
    typedef std::vector<std::pair<std::string,std::ostringstream*> > attributes_t;
#endif
    attributes_t attributes;
public:
    Node( std::string const& name );
    ~Node();

    void SetName(std::string const& aName)
        { name = aName; }

    std::ostringstream& att(std::string const& attname);
    std::ostringstream& operator[](std::string const& attname)
        { return att( attname ); }

    Node& subnode( std::string const& subname );
    TextElement& text();
    virtual void write(std::ostream&,int,bool) const;
};

#endif // _hdr_XMLWRITE_H