summaryrefslogtreecommitdiffstats
path: root/src/xml/document.h
blob: 92878b26ea9fa99551efb627933077e8a0a3396f (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 *  Interface for XML documents
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2011 Authors
 * Copyright 2005 MenTaLguY <mental@rydia.net>
 * 
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef SEEN_INKSCAPE_XML_SP_REPR_DOC_H
#define SEEN_INKSCAPE_XML_SP_REPR_DOC_H

#include "xml/node.h"

namespace Inkscape {
namespace XML {

/**
 * @brief Interface for XML documents
 *
 * This class represents a complete document tree. You have to go through this class
 * to create new nodes. It also contains transaction support, which forms the base
 * of the undo system.
 *
 * The document is also a node. It usually contains only two child nodes - a processing
 * instruction node (PINode) containing the XML prolog, and the root node. You can get
 * the root node of the document by calling the root() method.
 *
 * The name "transaction" can be misleading, because they are not atomic. Their main feature
 * is that they provide rollback. After starting a transaction,
 * all changes made to the document are stored in an internal event log. At any time
 * after starting the transaction, you can call the rollback() method, which restores
 * the document to the state it was before starting the transaction. Calling the commit()
 * method causes the internal event log to be discarded, and you can establish a new
 * "restore point" by calling beginTransaction() again. There can be only one active
 * transaction at a time for a given document.
 */
struct Document : virtual public Node {
public:
    /**
     * @name Document transactions
     * @{
     */
    /**
     * @brief Checks whether there is an active transaction for this document
     * @return true if there's an established transaction for this document, false otherwise
     */
    virtual bool inTransaction()=0;
    /**
     * @brief Begin a transaction and start recording changes
     *
     * By calling this method you effectively establish a resotre point.
     * You can undo all changes made to the document after this call using rollback().
     */
    virtual void beginTransaction()=0;
    /**
     * @brief Restore the state of the document prior to the transaction
     *
     * This method applies the inverses of all recorded changes in reverse order,
     * restoring the document state from before the transaction. For some implementations,
     * this function may do nothing.
     */
    virtual void rollback()=0;
    /**
     * @brief Commit a transaction and discard change data
     *
     * This method finishes the active transaction and discards the recorded changes.
     */
    virtual void commit()=0;
    /**
     * @brief Commit a transaction and store the events for later use
     *
     * This method finishes a transaction and returns an event chain
     * that describes the changes made to the document. This method may return NULL,
     * which means that the document implementation doesn't support event logging,
     * or that no changes were made.
     *
     * @return Event chain describing the changes, or NULL
     */
    virtual Event *commitUndoable()=0;
    /*@}*/

    /**
     * @name Create new nodes
     * @{
     */
    virtual Node *createElement(char const *name)=0;
    virtual Node *createTextNode(char const *content)=0;
    virtual Node *createTextNode(char const *content, bool is_CData)=0;
    virtual Node *createComment(char const *content)=0;
    virtual Node *createPI(char const *target, char const *content)=0;
    /*@}*/

    /**
     * @brief Get the event logger for this document
     *
     * This is an implementation detail that should not be used outside of node implementations.
     * It should be made non-public in the future.
     */
    virtual NodeObserver *logger()=0;
};

}
}

#endif
/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :