Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
simple-node.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors: see git history
6 *
7 * Copyright (C) 2018 Authors
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10
11#ifndef SEEN_INKSCAPE_XML_NODE_H
12#error You have included xml/simple-node.h in your document, which is an implementation. Chances are that you want xml/node.h. Please fix that.
13#endif
14
15#ifndef SEEN_INKSCAPE_XML_SIMPLE_NODE_H
16#define SEEN_INKSCAPE_XML_SIMPLE_NODE_H
17
18#include <cassert>
19#include <iostream>
20#include <vector>
21
22#include "xml/node.h"
25
26namespace Inkscape {
27
28namespace XML {
29
36: virtual public Node, public Inkscape::GC::Managed<>
37{
38public:
39 char const *name() const override;
40 int code() const override { return _name; }
41 void setCodeUnsafe(int code) override;
42
43 Document *document() override { return _document; }
44 Document const *document() const override {
45 return const_cast<SimpleNode *>(this)->document();
46 }
47
48 Node *root() override;
49 Node const *root() const override {
50 return const_cast<SimpleNode *>(this)->root();
51 }
52
53 Node *parent() override { return _parent; }
54 Node const *parent() const override { return _parent; }
55
56 Node *next() override { return _next; }
57 Node const *next() const override { return _next; }
58 Node *prev() override { return _prev; }
59 Node const *prev() const override { return _prev; }
60
61 Node *firstChild() override { return _first_child; }
62 Node const *firstChild() const override { return _first_child; }
63 Node *lastChild() override { return _last_child; }
64 Node const *lastChild() const override { return _last_child; }
65
66 unsigned childCount() const override { return _child_count; }
67 Node *nthChild(unsigned index) override;
68 Node const *nthChild(unsigned index) const override {
69 return const_cast<SimpleNode *>(this)->nthChild(index);
70 }
71
72 void addChild(Node *child, Node *ref) override;
76 void removeChild(Node *child) override;
77 void changeOrder(Node *child, Node *ref) override;
78
79 unsigned position() const override;
80 void setPosition(int pos) override;
81
82 char const *attribute(char const *key) const override;
83 bool matchAttributeName(char const *partial_name) const override;
84
85 char const *content() const override;
86 void setContent(char const *value) override;
87
88 void cleanOriginal(Node *src, gchar const *key) override;
89 bool equal(Node const *other, bool recursive, bool skip_ids = false) override;
90 void mergeFrom(Node const *src, char const *key, bool extension = false, bool clean = false) override;
91
92 const AttributeVector & attributeList() const override {
93 return _attributes;
94 }
95
97
104
111
112 void recursivePrintTree(unsigned level = 0) override;
113
114protected:
116 SimpleNode(SimpleNode const &repr, Document *document);
117
118 void setAttributeImpl(char const *key, char const *value) override;
119
120private:
121 void operator=(Node const &); // no assign
122
124 unsigned _childPosition(SimpleNode const &child) const;
125
130 mutable unsigned _cached_position;
131
132 int _name;
133
135
137
138 unsigned _child_count{0};
139 mutable bool _cached_positions_valid{false};
142
145};
146
147}
148
149}
150
151#endif
152/*
153 Local Variables:
154 mode:c++
155 c-file-style:"stroustrup"
156 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
157 indent-tabs-mode:nil
158 fill-column:99
159 End:
160*/
161// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
TODO: insert short description here.
Cairo::RefPtr< Cairo::Region > clean
Definition canvas.cpp:183
A base class for objects for whom the normal new and delete operators should use the garbage-collecte...
Definition gc-managed.h:27
An observer that relays notifications to multiple other observers.
void add(NodeObserver &observer)
Add an observer to the list.
void remove(NodeObserver &observer)
Remove an observer from the list.
Interface for XML node observers.
Interface for refcounted XML nodes.
Definition node.h:80
Default implementation of the XML node stored in memory.
Definition simple-node.h:37
void cleanOriginal(Node *src, gchar const *key) override
void addObserver(NodeObserver &observer) override
Add an object that will be notified of the changes to this node.
Definition simple-node.h:98
Node const * parent() const override
Definition simple-node.h:54
Node const * lastChild() const override
Definition simple-node.h:64
Node * next() override
Get the next sibling of this node.
Definition simple-node.h:56
Inkscape::Util::ptr_shared _content
bool matchAttributeName(char const *partial_name) const override
Check whether this node has any attribute that matches a string.
Node * prev() override
Definition simple-node.h:58
Node * firstChild() override
Get the first child of this node.
Definition simple-node.h:61
void removeObserver(NodeObserver &observer) override
Remove an object from the list of observers.
void recursivePrintTree(unsigned level=0) override
Node * nthChild(unsigned index) override
Get the child of this node with a given index.
void setCodeUnsafe(int code) override
Set the integer GQuark code for the name of the node.
void setPosition(int pos) override
Set the position of this node in parent's child order.
Document const * document() const override
Definition simple-node.h:44
Node * parent() override
Get the parent of this node.
Definition simple-node.h:53
bool equal(Node const *other, bool recursive, bool skip_ids=false) override
Compare 2 nodes equality.
void appendChild(Node *child) override
Append a node as the last child of this node.
Definition simple-node.h:73
int code() const override
Get the integer code corresponding to the node's name.
Definition simple-node.h:40
const AttributeVector & attributeList() const override
Get a list of the node's attributes.
Definition simple-node.h:92
char const * content() const override
Get the content of a text or comment node.
void operator=(Node const &)
void removeChild(Node *child) override
Remove a child of this node.
CompositeNodeObserver _subtree_observers
CompositeNodeObserver _observers
AttributeVector _attributes
Node const * firstChild() const override
Definition simple-node.h:62
Node const * nthChild(unsigned index) const override
Definition simple-node.h:68
char const * name() const override
Get the name of the element node.
unsigned _childPosition(SimpleNode const &child) const
void synthesizeEvents(NodeObserver &observer) override
Generate a sequence of events corresponding to the state of this node.
void setAttributeImpl(char const *key, char const *value) override
unsigned childCount() const override
Get the number of children of this node.
Definition simple-node.h:66
Node const * root() const override
Definition simple-node.h:49
void mergeFrom(Node const *src, char const *key, bool extension=false, bool clean=false) override
Merge all children of another node with the current.
Node * lastChild() override
Get the last child of this node.
Definition simple-node.h:63
Node const * prev() const override
Definition simple-node.h:59
void addChild(Node *child, Node *ref) override
Insert another node as a child of this node.
void addSubtreeObserver(NodeObserver &observer) override
Add an object that will be notified of the changes to this node and its descendants.
unsigned position() const override
Get the index of this node in parent's child order.
char const * attribute(char const *key) const override
Get the string representation of a node's attribute.
Node * root() override
Get the root node of this node's document.
void setContent(char const *value) override
Set the content of a text or comment node.
Document * document() override
Get the node's associated document.
Definition simple-node.h:43
void _setParent(SimpleNode *parent)
void changeOrder(Node *child, Node *ref) override
Move a given node in this node's child order.
void removeSubtreeObserver(NodeObserver &observer) override
Remove an object from the subtree observers list.
Node const * next() const override
Definition simple-node.h:57
NodeObserver const * observer
Inkscape::XML::CompositeNodeObserver - combine multiple observers.
std::vector< AttributeRecord, Inkscape::GC::Alloc< AttributeRecord > > AttributeVector
Definition node.h:34
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
Ocnode * child[8]
Definition quantize.cpp:33
Ocnode ** ref
Definition quantize.cpp:32
Interface for XML documents.
Definition document.h:43
int index
Interface for XML nodes.