aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/xmlserializable.h
blob: 76f0ad1fa3a299b8a7c8af1a07793ac3aa6487f4 (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <string>

namespace vespalib::xml {

class XmlOutputStream;

/**
 * @class document::XmlSerializable
 *
 * Base class for classes that can be converted into XML.
 */
class XmlSerializable
{
public:
    XmlSerializable() {}
    virtual ~XmlSerializable() = default;

    virtual void printXml(XmlOutputStream& out) const = 0;

    /** Utility function, using printXml() to create a string. */
    virtual std::string toXml(const std::string& indent = "") const;
};

}

namespace vespalib {
// The XmlSerializable and XmlOutputStream is often used in header files
// and is thus available in the vespalib namespace. To not pollute the
// vespalib namespace with all the other classes, use
// "using namespace vespalib::xml" within your printXml functions

using XmlSerializable = vespalib::xml::XmlSerializable;
using XmlOutputStream = vespalib::xml::XmlOutputStream;

} // vespalib