1 /** @file
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 /**
29 * @brief An observer that relays notifications to multiple other observers
30 *
31 * This special observer keeps a list of other observer objects and sends
32 * the notifications it receives to all of them. The implementation of the class
33 * allows an observer to remove itself from this object during a method call.
34 * For the documentation of callback methods, see NodeObserver.
35 */
36 class CompositeNodeObserver : public NodeObserver, public GC::Managed<> {
37 public:
38 struct ObserverRecord : public GC::Managed<> {
39 explicit ObserverRecord(NodeObserver &o) : observer(o), marked(false) {}
41 NodeObserver &observer;
42 bool marked; //< if marked for removal
43 };
44 typedef Util::ListContainer<ObserverRecord> ObserverRecordList;
46 CompositeNodeObserver()
47 : _iterating(0), _active_marked(0), _pending_marked(0) {}
49 /**
50 * @brief Add an observer to the list
51 * @param observer The observer object to add
52 */
53 void add(NodeObserver &observer);
54 /**
55 * @brief Remove an observer from the list
56 * @param observer The observer object to remove
57 */
58 void remove(NodeObserver &observer);
59 /**
60 * @brief Add a set of callbacks with associated data
61 * @deprecated Use add() instead
62 */
63 void addListener(NodeEventVector const &vector, void *data);
64 /**
65 * @brief Remove a set of callbacks by its associated data
66 * @deprecated Use remove() instead
67 */
68 void removeListenerByData(void *data);
70 void notifyChildAdded(Node &node, Node &child, Node *prev);
72 void notifyChildRemoved(Node &node, Node &child, Node *prev);
74 void notifyChildOrderChanged(Node &node, Node &child,
75 Node *old_prev, Node *new_prev);
77 void notifyContentChanged(Node &node,
78 Util::ptr_shared<char> old_content,
79 Util::ptr_shared<char> new_content);
81 void notifyAttributeChanged(Node &node, GQuark name,
82 Util::ptr_shared<char> old_value,
83 Util::ptr_shared<char> new_value);
85 private:
86 unsigned _iterating;
87 ObserverRecordList _active;
88 unsigned _active_marked;
89 ObserverRecordList _pending;
90 unsigned _pending_marked;
92 void _startIteration() { ++_iterating; }
93 void _finishIteration();
94 };
96 } // namespace XML
97 } // namespace Inkscape
99 #endif
100 /*
101 Local Variables:
102 mode:c++
103 c-file-style:"stroustrup"
104 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
105 indent-tabs-mode:nil
106 fill-column:99
107 End:
108 */
109 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :