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
|
/**
* Whiteboard session manager
* XML node manipulation / retrieval utilities
*
* Authors:
* David Yip <yipdw@rose-hulman.edu>
*
* Copyright (c) 2005 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "util/shared-c-string-ptr.h"
#include "util/list.h"
#include "xml/node-observer.h"
#include "xml/attribute-record.h"
#include "xml/repr.h"
#include "jabber_whiteboard/defines.h"
#include "jabber_whiteboard/typedefs.h"
#include "jabber_whiteboard/node-utilities.h"
#include "jabber_whiteboard/node-tracker.h"
//#include "jabber_whiteboard/node-observer.h"
namespace Inkscape {
namespace Whiteboard {
/*
Inkscape::XML::Node*
NodeUtilities::lookupReprByValue(Inkscape::XML::Node* root, gchar const* key, Glib::ustring const* value)
{
GQuark const quark = g_quark_from_string(key);
if (root == NULL) {
return NULL;
}
Inkscape::Util::List<Inkscape::XML::AttributeRecord const> attrlist = root->attributeList();
for( ; attrlist ; attrlist++) {
if ((attrlist->key == quark) && (strcmp(attrlist->value, value->data()) == 0)) {
return root;
}
}
Inkscape::XML::Node* result;
for ( Inkscape::XML::Node* child = root->firstChild() ; child != NULL ; child = child->next() ) {
result = NodeUtilities::lookupReprByValue(child, key, value);
if(result != NULL) {
return result;
}
}
return NULL;
}
*/
Glib::ustring const
NodeUtilities::nodeTypeToString(XML::Node const& node)
{
switch(node.type()) {
case XML::DOCUMENT_NODE:
return NODETYPE_DOCUMENT_STR;
case XML::ELEMENT_NODE:
return NODETYPE_ELEMENT_STR;
case XML::TEXT_NODE:
return NODETYPE_TEXT_STR;
case XML::COMMENT_NODE:
default:
return NODETYPE_COMMENT_STR;
}
}
XML::NodeType
NodeUtilities::stringToNodeType(Glib::ustring const& type)
{
if (type == NODETYPE_DOCUMENT_STR) {
return XML::DOCUMENT_NODE;
} else if (type == NODETYPE_ELEMENT_STR) {
return XML::ELEMENT_NODE;
} else if (type == NODETYPE_TEXT_STR) {
return XML::TEXT_NODE;
} else {
return XML::COMMENT_NODE;
}
}
std::string const
NodeUtilities::findNodeID(XML::Node const& node, XMLNodeTracker* tracker, NodeToKeyMap const& newnodes)
{
// g_log(NULL, G_LOG_LEVEL_DEBUG, "Attempting to locate id for %p", &node);
NodeToKeyMap::const_iterator result = newnodes.find(&node);
if (result != newnodes.end()) {
// g_log(NULL, G_LOG_LEVEL_DEBUG, "Located id for %p: %s", &node, (*result).second.c_str());
return (*result).second;
}
if (tracker->isTracking(node)) {
// g_log(NULL, G_LOG_LEVEL_DEBUG, "Located id for %p (in tracker): %s", &node, tracker->get(node).c_str());
return tracker->get(node);
} else {
// g_log(NULL, G_LOG_LEVEL_DEBUG, "Failed to locate id");
return "";
}
}
}
}
/*
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:encoding=utf-8:textwidth=99 :
|