1 /*
2 * Inkscape::XML::CompositeNodeObserver - combine multiple observers
3 *
4 * Copyright 2005 MenTaLguY <mental@rydia.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * See the file COPYING for details.
12 *
13 */
15 #ifndef SEEN_INKSCAPE_XML_COMPOSITE_NODE_OBSERVER_H
16 #define SEEN_INKSCAPE_XML_COMPOSITE_NODE_OBSERVER_H
18 #include "gc-managed.h"
19 #include "xml/node-observer.h"
20 #include "util/list-container.h"
22 namespace Inkscape {
24 namespace XML {
26 class NodeEventVector;
28 class CompositeNodeObserver : public NodeObserver, public GC::Managed<> {
29 public:
30 struct ObserverRecord : public GC::Managed<> {
31 explicit ObserverRecord(NodeObserver &o) : observer(o), marked(false) {}
33 NodeObserver &observer;
34 bool marked; //< if marked for removal
35 };
36 typedef Util::ListContainer<ObserverRecord> ObserverRecordList;
38 CompositeNodeObserver()
39 : _iterating(0), _active_marked(0), _pending_marked(0) {}
41 void add(NodeObserver &observer);
42 void addListener(NodeEventVector const &vector, void *data);
43 void remove(NodeObserver &observer);
44 void removeListenerByData(void *data);
46 void notifyChildAdded(Node &node, Node &child, Node *prev);
48 void notifyChildRemoved(Node &node, Node &child, Node *prev);
50 void notifyChildOrderChanged(Node &node, Node &child,
51 Node *old_prev, Node *new_prev);
53 void notifyContentChanged(Node &node,
54 Util::ptr_shared<char> old_content,
55 Util::ptr_shared<char> new_content);
57 void notifyAttributeChanged(Node &node, GQuark name,
58 Util::ptr_shared<char> old_value,
59 Util::ptr_shared<char> new_value);
61 private:
62 unsigned _iterating;
63 ObserverRecordList _active;
64 unsigned _active_marked;
65 ObserverRecordList _pending;
66 unsigned _pending_marked;
68 void _startIteration() { ++_iterating; }
69 void _finishIteration();
70 };
72 }
74 }
76 #endif
77 /*
78 Local Variables:
79 mode:c++
80 c-file-style:"stroustrup"
81 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
82 indent-tabs-mode:nil
83 fill-column:99
84 End:
85 */
86 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :