-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxmlparse.h
More file actions
283 lines (231 loc) · 7.36 KB
/
Copy pathxmlparse.h
File metadata and controls
283 lines (231 loc) · 7.36 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
* xmlparse.h
* topicNet
*
* Created by basak alper on 5/30/10.
* Copyright 2010 ucsb. All rights reserved.
*
*/
#ifndef XMLPARSE_H
#define XMLPARSE_H 1
#include <map>
#include "tinyxml.h"
const unsigned int NUM_INDENTS_PER_SPACE=2;
const char * getIndent( unsigned int numIndents )
{
static const char * pINDENT=" + ";
static const unsigned int LENGTH=strlen( pINDENT );
unsigned int n=numIndents*NUM_INDENTS_PER_SPACE;
if ( n > LENGTH ) n = LENGTH;
return &pINDENT[ LENGTH-n ];
}
// same as getIndent but no "+" at the end
const char * getIndentAlt( unsigned int numIndents )
{
static const char * pINDENT=" ";
static const unsigned int LENGTH=strlen( pINDENT );
unsigned int n=numIndents*NUM_INDENTS_PER_SPACE;
if ( n > LENGTH ) n = LENGTH;
return &pINDENT[ LENGTH-n ];
}
enum Elements { DNVGRAPH, DNVNODE, DNVEDGE, NODEPROPERTY};
static std::map<std::string, Elements> s_mapElements;
enum XMLKEYS { GRAPHML, GRAPH, NODE, EDGE, DATA, KEY, ID, SOURCE, TARGET};
void initializeEnums()
{
s_mapElements["DNVGRAPH"] = DNVGRAPH;
s_mapElements["DNVNODE"] = DNVNODE;
s_mapElements["DNVEDGE"] = DNVEDGE;
s_mapElements["NODEPROPERTY"] = NODEPROPERTY;
}
enum Attributes {Id, IntId, Level, Position, Color, Size, Active, Icon, Label, Mass, Fixed, Type, BBid,
ForceLabel, Alpha, LabelColor, LabelOutlineColor, OutlineColor, LabelSize, Expandable, Visible,
HideLabelBackground, CurvedLabel,
EdgeId, EdgeLevel, Length, Rigid, From, To, K, Directional, HasSetColor, Thickness //these are only edge attributes
};
static std::map<std::string, Attributes> s_map_attributes;
void initializeAttributeEnums()
{
s_map_attributes["Id"] = Id;
s_map_attributes["Level"] = Level;
s_map_attributes["Position"] = Position;
s_map_attributes["Color"] = Color;
s_map_attributes["Size"] = Size;
s_map_attributes["Active"] = Active;
s_map_attributes["Icon"] = Icon;
s_map_attributes["Label"] = Label;
s_map_attributes["Mass"] = Mass;
s_map_attributes["Fixed"] = Fixed;
s_map_attributes["Type"] = Type;
s_map_attributes["BBid"] = BBid;
s_map_attributes["IntId"] = IntId;
s_map_attributes["ForceLabel"] = ForceLabel;
s_map_attributes["Alpha"] = Alpha;
s_map_attributes["LabelColor"] = LabelColor;
s_map_attributes["LabelOutlineColor"] = LabelOutlineColor;
s_map_attributes["OutlineColor"] = OutlineColor;
s_map_attributes["LabelSize"] = LabelSize;
s_map_attributes["Expandable"] = Expandable;
s_map_attributes["Visible"] = Visible;
s_map_attributes["EdgeId"] = EdgeId;
s_map_attributes["EdgeLevel"] = EdgeLevel;
s_map_attributes["Length"] = Length;
s_map_attributes["rigid"] = Rigid;
s_map_attributes["From"] = From;
s_map_attributes["To"] = To;
s_map_attributes["K"] = K;
s_map_attributes["Directional"] = Directional;
s_map_attributes["HasSetColor"] = HasSetColor;
s_map_attributes["Thickness"] = Thickness;
s_map_attributes["HideLabelBackground"] = HideLabelBackground;
s_map_attributes["CurvedLabel"] = CurvedLabel;
}
/*
enum nodeAttr { Id, Level, Position, Color, Size, Active, Icon, Label, Mass, Fixed, Type, BBid,
ForceLabel, Alpha, LabelColor, LabelOutlineColor, OutlineColor, LabelSize, Expandable, Visible};
static std::map<std::string, nodeAttr> s_map_nodeAttr;
void initializeNodeEnums()
{
s_map_nodeAttr["Id"] = Id;
s_map_nodeAttr["Level"] = Level;
s_map_nodeAttr["Position"] = Position;
s_map_nodeAttr["Color"] = Color;
s_map_nodeAttr["Size"] = Size;
s_map_nodeAttr["Active"] = Active;
s_map_nodeAttr["Icon"] = Icon;
s_map_nodeAttr["Label"] = Label;
s_map_nodeAttr["Mass"] = Mass;
s_map_nodeAttr["Fixed"] = Fixed;
s_map_nodeAttr["Type"] = Type;
s_map_nodeAttr["BBid"] = BBid;
s_map_nodeAttr["ForceLabel"] = ForceLabel;
s_map_nodeAttr["Alpha"] = Alpha;
s_map_nodeAttr["LabelColor"] = LabelColor;
s_map_nodeAttr["LabelOutlineColor"] = LabelOutlineColor;
s_map_nodeAttr["OutlineColor"] = OutlineColor;
s_map_nodeAttr["LabelSize"] = LabelSize;
s_map_nodeAttr["Expandable"] = Expandable;
s_map_nodeAttr["Visible"] = Visible;
}
enum edgAttr { EdgeId, EdgeLevel, Length, Rigid, From, To, K, Label, Directional, BBid, Color,
HasSetColor, Alpha, LabelColor, LabelOutlineColor, LabelSize, Thickness, Visible};
static std::map<std::string, edgAttr> s_map_edgeAttr;
void initializeEdgeEnums()
{
s_map_edgeAttr["Id"] = EdgeId;
s_map_edgeAttr["Level"] = EdgeLevel;
s_map_edgeAttr["Length"] = Length;
s_map_edgeAttr["rigid"] = Rigid;
s_map_edgeAttr["From"] = From;
s_map_edgeAttr["To"] = To;
s_map_edgeAttr["K"] = K;
s_map_edgeAttr["Label"] = Label;
s_map_edgeAttr["Directional"] = Directional;
s_map_edgeAttr["BBid"] = BBid;
s_map_edgeAttr["Color"] = Color;
s_map_edgeAttr["HasSetColor"] = HasSetColor;
s_map_edgeAttr["Alpha"] = Alpha;
s_map_edgeAttr["LabelColor"] = LabelColor;
s_map_edgeAttr["LabelOutlineColor"] = LabelOutlineColor;
s_map_edgeAttr["LabelSize"] = LabelSize;
s_map_edgeAttr["Thickness"] = Thickness;
s_map_edgeAttr["Visible"] = Visible;
}
*/
typedef vector<string> StringVector;
StringVector stringsFrom( string s )
{
replace( s.begin(), s.end(), ',', ' ' );
istringstream stream(s);
StringVector result;
for( ;; )
{
string word;
if( !( stream >> word ) ) { break; }
result.push_back( word );
}
return result;
}
/*
int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent)
{
if ( !pElement ) return 0;
TiXmlAttribute* pAttrib=pElement->FirstAttribute();
int i=0;
int ival;
double dval;
const char* pIndent=getIndent(indent);
printf("\n");
while (pAttrib)
{
printf( "%s%s: value=[%s]", pIndent, pAttrib->Name(), pAttrib->Value());
if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS) printf( " int=%d", ival);
if (pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) printf( " d=%1.1f", dval);
printf( "\n" );
i++;
pAttrib=pAttrib->Next();
}
return i;
}
void dump_to_stdout( TiXmlNode* pParent, unsigned int indent = 0 )
{
if ( !pParent ) return;
TiXmlNode* pChild;
TiXmlText* pText;
int t = pParent->Type();
printf( "%s", getIndent(indent));
int num;
switch ( t )
{
case TiXmlNode::TINYXML_DOCUMENT:
printf( "Document" );
break;
case TiXmlNode::TINYXML_ELEMENT:
printf( "Element [%s]", pParent->Value() );
num=dump_attribs_to_stdout(pParent->ToElement(), indent+1);
switch(num)
{
case 0: printf( " (No attributes)"); break;
case 1: printf( "%s1 attribute", getIndentAlt(indent)); break;
default: printf( "%s%d attributes", getIndentAlt(indent), num); break;
}
break;
case TiXmlNode::TINYXML_COMMENT:
printf( "Comment: [%s]", pParent->Value());
break;
case TiXmlNode::TINYXML_UNKNOWN:
printf( "Unknown" );
break;
case TiXmlNode::TINYXML_TEXT:
pText = pParent->ToText();
printf( "Text: [%s]", pText->Value() );
break;
case TiXmlNode::TINYXML_DECLARATION:
printf( "Declaration" );
break;
default:
break;
}
printf( "\n" );
for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
{
dump_to_stdout( pChild, indent+1 );
}
}
// load the named file and dump its structure to STDOUT
void dump_to_stdout(const char* pFilename)
{
TiXmlDocument doc(pFilename);
bool loadOkay = doc.LoadFile();
if (loadOkay)
{
printf("\n%s:\n", pFilename);
dump_to_stdout( &doc ); // defined later in the tutorial
}
else
{
printf("Failed to load file \"%s\"\n", pFilename);
}
}
*/
#endif //XMLPARSE_H