1 /**
2 * Inkscape::Whiteboard::KeyNodeTable - structure for lookup of values from keys
3 * and vice versa
4 *
5 * Authors:
6 * Bob Jamison
7 *
8 * Copyright (c) 2005 Authors
9 */
10 #ifndef __KEY_NODE_H__
11 #define __KEY_NODE_H__
13 #include <glibmm.h>
15 #include <vector>
17 #include "xml/node.h"
18 #include "jabber_whiteboard/defines.h"
20 namespace Inkscape
21 {
22 namespace Whiteboard
23 {
25 class KeyNodePair
26 {
27 public:
29 KeyNodePair(const Glib::ustring &keyArg, const XML::Node *nodeArg)
30 {
31 this->key = keyArg;
32 this->node = (XML::Node *)nodeArg;
33 this->version = 0;
34 this->index = 0;
35 this->history.push_back(Configure("",""));
36 }
38 KeyNodePair(const Glib::ustring &keyArg, const XML::Node *nodeArg,
39 unsigned int version, signed int index)
40 {
41 this->key = keyArg;
42 this->node = (XML::Node *)nodeArg;
43 this->version = version;
44 this->index = index;
45 this->history.push_back(Configure("",""));
46 }
48 KeyNodePair(const KeyNodePair &other)
49 {
50 this->key = other.key;
51 this->node = other.node;
52 this->version = other.version;
53 this->index = other.index;
54 this->history = other.history;
55 }
57 virtual ~KeyNodePair() {}
59 Glib::ustring key;
60 XML::Node *node;
61 unsigned int version;
62 signed int index;
63 std::list< Configure > history;
64 };
66 class KeyNodeTable
67 {
68 public:
70 KeyNodeTable()
71 { this->counter = 0; }
73 KeyNodeTable(const KeyNodeTable &other)
74 {
75 items = other.items;
76 this->counter = 0;
77 }
79 virtual ~KeyNodeTable()
80 {}
82 virtual void clear();
84 virtual void append(const KeyNodeTable &other);
86 virtual void put(const KeyNodePair &pair);
88 virtual void put(const Glib::ustring &key, const XML::Node *node);
90 virtual XML::Node * get(const Glib::ustring &key) const;
92 virtual void remove(const Glib::ustring &key);
94 virtual Glib::ustring get(XML::Node *node) const;
96 virtual void remove(XML::Node *node);
98 virtual unsigned int size() const;
100 virtual KeyNodePair item(unsigned int index) const;
102 virtual Glib::ustring generateKey(Glib::ustring);
104 virtual unsigned int getVersion(XML::Node *node);
106 virtual unsigned int incrementVersion(XML::Node *node);
108 virtual void addHistory(XML::Node *node, Glib::ustring attribute, Glib::ustring value);
110 virtual Glib::ustring getLastHistory(XML::Node *node, Glib::ustring attribute);
112 private:
114 std::vector<KeyNodePair> items;
116 unsigned int counter;
118 };
122 } // namespace Whiteboard
124 } // namespace Inkscape
127 #endif /* __KEY_NODE_H__ */