Merge lp:~tapaal-ctl/verifypn/verifypnCTL into lp:~verifypn-maintainers/verifypn/trunk

Proposed by Søren Moss Nielsen
Status: Superseded
Proposed branch: lp:~tapaal-ctl/verifypn/verifypnCTL
Merge into: lp:~verifypn-maintainers/verifypn/trunk
Diff against target: 6591 lines (+5834/-150)
40 files modified
.bzrignore (+29/-0)
CTL/CertainZeroFPA.cpp (+144/-0)
CTL/CertainZeroFPA.h (+28/-0)
CTL/DependencyGraph.cpp (+19/-0)
CTL/DependencyGraph.h (+39/-0)
CTL/FixedPointAlgorithm.h (+16/-0)
CTL/LocalFPA.cpp (+106/-0)
CTL/LocalFPA.h (+28/-0)
CTL/OnTheFlyDG.cpp (+367/-0)
CTL/OnTheFlyDG.h (+49/-0)
CTL/SearchStrategies/AbstractSearchStrategy.h (+23/-0)
CTL/SearchStrategies/DepthFirstSearch.cpp (+37/-0)
CTL/SearchStrategies/DepthFirstSearch.h (+28/-0)
CTL/configuration.cpp (+62/-0)
CTL/configuration.h (+73/-0)
CTL/edge.cpp (+75/-0)
CTL/edge.h (+44/-0)
CTL/marking.cpp (+38/-0)
CTL/marking.h (+76/-0)
CTLParser/CTLParser.cpp (+575/-0)
CTLParser/CTLParser.h (+126/-0)
CTLParser/rapidxml-1.13/license.txt (+52/-0)
CTLParser/rapidxml-1.13/rapidxml.hpp (+2596/-0)
CTLParser/rapidxml-1.13/rapidxml_iterators.hpp (+174/-0)
CTLParser/rapidxml-1.13/rapidxml_print.hpp (+421/-0)
CTLParser/rapidxml-1.13/rapidxml_utils.hpp (+122/-0)
PetriEngine/PQL/PQLAssignmentTokens.lexer.cpp (+4/-0)
PetriEngine/PQL/PQLQueryTokens.lexer.cpp (+15/-15)
PetriEngine/PQL/SUMoQueryTokens.lexer.cpp (+15/-15)
PetriEngine/Reachability/HashUnderApproximation.cpp (+2/-2)
PetriEngine/Structures/SmartStateSet.h (+2/-2)
PetriEngine/Structures/StateSet.h (+6/-6)
VerifyPN.cpp (+425/-95)
makefile (+1/-1)
makefile.linux32 (+3/-2)
makefile.linux64 (+6/-4)
makefile.osx32 (+2/-2)
makefile.osx64 (+2/-2)
makefile.win32 (+2/-2)
makefile.win64 (+2/-2)
To merge this branch: bzr merge lp:~tapaal-ctl/verifypn/verifypnCTL
Reviewer Review Type Date Requested Status
Jiri Srba Pending
Review via email: mp+290419@code.launchpad.net

This proposal supersedes a proposal from 2016-03-09.

This proposal has been superseded by a proposal from 2016-03-31.

Commit message

Please disregard commit messages about compression

Description of the change

Post-review proposal:
1. Help options updated
2. Reachability query section logic fixed
3. Output format updated
4. Structural reductions disabled for CTL queries (promts error message instead)

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote : Posted in a previous version of this proposal

I have a few things:

1. options, the help says:

  -ctl <algorithm> CTL query verification in VerifyPN-CTL:
                                     czero-i Certain zero early termination algorithm
                                     local-i Local algorithm
                                     gobal-i Global algorithm (very memory expensive)

but these options are not accepted, there is a typo in gobal and the engine only accepts czero and local (no global). The help should say which one is the default option.

2. in the main VerifyPN.cpp file there is the following:

 if (!isCTLlogic) {
                string querystring; // excluding EF and AG
                if (!statespaceexploration || !isCTLlogic) {

Of couse, once we enter the branch because !isCTLlogic holds, the next if statement will also always hold. Weird ...

3. Finally, the ctl algorithm does not seem to report the results according to the competition required keywords "TRUE/FALSE TECHNIQUES ..."

Can you take a look at this, please?

review: Needs Fixing
Revision history for this message
Jiri Srba (srba) wrote : Posted in a previous version of this proposal

Also another problem:

4. It appears that you allow to use reductions even for CTL queries (there is a code prepares for using the reduction on CTL queries). But reduction for CTL queries should be disabled (if a ctl query is used and reduction of type 1 or 2 is used, we should report a problem and terminated).

This needs also fixing.

review: Needs Fixing
lp:~tapaal-ctl/verifypn/verifypnCTL updated
242. By Søren Moss Nielsen <email address hidden>

Minor fix to outputformat

243. By Søren Moss Nielsen <email address hidden>

Added support for inhibitor arcs

244. By Søren Moss Nielsen <email address hidden>

Added breaks in fireable transitions traversion

245. By Søren Moss Nielsen <email address hidden>

Added another break in fireable transitions traversion

246. By Jiri Srba <email address hidden>

FORMULA is now printed just before the results are printed and printstatistics flag is used to suppress printing CTL debugging info

247. By Jiri Srba <email address hidden>

the info about the net is printed only if -n switch is not present

248. By Jiri Srba <email address hidden>

fixed the check of CTL engine and reductions that should be disabled

249. By Isabella Kaufmann <email address hidden>

still no deadlock (needs parser fixing as well if it should be possible) but only DFS is allowed and that is now the default

250. By Jiri Srba <email address hidden>

small fix in the way search strategy is search for CTL logic

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2016-03-31 07:42:46 +0000
4@@ -0,0 +1,29 @@
5+makefile
6+nbproject
7+verifypn-linux64
8+verifypn.config
9+verifypn.creator
10+verifypn.creator.user
11+verifypn.files
12+verifypn.includes
13+verifypnCTL.config
14+verifypnCTL.creator
15+verifypnCTL.creator.user
16+verifypnCTL.files
17+verifypnCTL.includes
18+log.txt
19+testlog.log
20+testFramework/analysis.log
21+testFramework/CZERO.log
22+testFramework/log.log
23+*/*/*.log
24+*/*.log
25+*/*/*/*.log
26+cdfs_czero.log
27+dfs_czero.log
28+*.directory
29+verifypn-ctl.config
30+verifypn-ctl.creator
31+verifypn-ctl.creator.user
32+verifypn-ctl.files
33+verifypn-ctl.includes
34
35=== added directory 'CTL'
36=== added file 'CTL/CertainZeroFPA.cpp'
37--- CTL/CertainZeroFPA.cpp 1970-01-01 00:00:00 +0000
38+++ CTL/CertainZeroFPA.cpp 2016-03-31 07:42:46 +0000
39@@ -0,0 +1,144 @@
40+#include "CertainZeroFPA.h"
41+
42+namespace ctl{
43+
44+bool CertainZeroFPA::search(DependencyGraph &t_graph, AbstractSearchStrategy &W)
45+{
46+ PriorityQueue N;
47+
48+ Configuration &v = t_graph.initialConfiguration();
49+ v.assignment = ZERO;
50+
51+ for(Edge *e : t_graph.successors(v)){
52+ W.push(e);
53+ if(e->source->IsNegated)
54+ N.push(e);
55+ }
56+
57+ while(!W.empty() || !N.empty()){
58+ Edge *e;
59+
60+ if(!W.empty()) {
61+ e = W.pop();
62+ }
63+ else if (!N.empty()) {
64+ e = N.top();
65+ N.pop();
66+ }
67+
68+ /*****************************************************************/
69+ /*Data handling*/
70+ int targetONEassignments = 0;
71+ int targetZEROassignments = 0;
72+ int targetUKNOWNassignments = 0;
73+ bool czero = false;
74+
75+ for(auto c : e->targets){
76+ if (c->assignment == ONE) {
77+ targetONEassignments++;
78+ }
79+ else if (c->assignment == ZERO) {
80+ targetZEROassignments++;
81+ }
82+ else if (c->assignment == CZERO){
83+ czero = true;
84+ break;
85+ }
86+ else if(c-> assignment == UNKNOWN){
87+ targetUKNOWNassignments++;
88+ }
89+
90+ }
91+ /*****************************************************************/
92+
93+ if(e->isDeleted || e->source->assignment == ONE || e->source->assignment == CZERO){
94+ //std::cout << "== Ignored ==\n" << std::flush;
95+ }
96+ /*****************************************************************/
97+
98+ else if(e->targets.size() == targetONEassignments){
99+
100+ if(e->source->IsNegated){
101+ e->source->assignment = CZERO;
102+ e->source->removeSuccessor(e);
103+ }
104+ else{
105+ e->source->assignment = ONE;
106+ }
107+ if(e->source == &v) break;
108+
109+ for(Edge *de : e->source->DependencySet){
110+ W.push_dependency(de);
111+ }
112+ e->source->DependencySet.clear();
113+ }
114+ else if(czero){
115+ if(e->source->IsNegated){
116+ e->source->assignment = ONE;
117+ if(e->source == &v) break;
118+
119+ for(Edge *de : e->source->DependencySet){
120+ W.push_dependency(de);
121+ }
122+ e->source->DependencySet.clear();
123+ }
124+ else{
125+ if(e->source->Successors.size() <= 1){
126+ e->source->assignment = CZERO;
127+ if(e->source == &v) break;
128+
129+ for(Edge *de : e->source->DependencySet){
130+ W.push_dependency(de);
131+ }
132+ e->source->DependencySet.clear();
133+ }
134+ }
135+ e->source->removeSuccessor(e);
136+ }
137+ else if(targetZEROassignments > 0){
138+ if(e->source->IsNegated && e->processed){
139+ e->source->assignment = ONE;
140+ if(e->source == &v) break;
141+ for(Edge *de : e->source->DependencySet){
142+ W.push_dependency(de);
143+ }
144+ e->source->DependencySet.clear();
145+ }
146+ else {
147+ for(auto c : e->targets){
148+ if(c->assignment == ZERO) {
149+ c->DependencySet.push_back(e);
150+ }
151+ }
152+ }
153+ }
154+ else if(targetUKNOWNassignments > 0){
155+ for(Configuration *tc : e->targets){
156+ if(tc->assignment == UNKNOWN){
157+ tc->assignment = ZERO;
158+ tc->DependencySet.push_back(e);
159+ t_graph.successors(*tc);
160+
161+ if(tc->Successors.empty()){
162+ tc->assignment = CZERO;
163+ W.push_dependency(e);
164+ }
165+ else {
166+ for(Edge *succ : tc->Successors){
167+ W.push(succ);
168+ if(succ->source->IsNegated){
169+ N.push(succ);
170+ }
171+ }
172+ }
173+ }
174+ }
175+ }
176+ e->processed = true;
177+ }
178+
179+ //std::cout << "Final Assignment: " << v.assignment << " " << ((v.assignment == ONE) ? true : false) << std::endl;
180+ return (v.assignment == ONE) ? true : false;
181+}
182+
183+}
184
185=== added file 'CTL/CertainZeroFPA.h'
186--- CTL/CertainZeroFPA.h 1970-01-01 00:00:00 +0000
187+++ CTL/CertainZeroFPA.h 2016-03-31 07:42:46 +0000
188@@ -0,0 +1,28 @@
189+#ifndef CERTAINZEROFPA_H
190+#define CERTAINZEROFPA_H
191+
192+#include "FixedPointAlgorithm.h"
193+#include "edge.h"
194+#include "configuration.h"
195+
196+#include <list>
197+#include <queue>
198+#include <vector>
199+
200+namespace ctl {
201+
202+class CertainZeroFPA : public FixedPointAlgorithm
203+{
204+public:
205+ bool search(DependencyGraph &t_graph, AbstractSearchStrategy &t_strategy);
206+
207+private:
208+ struct edge_prioritizer{
209+ bool operator()(const Edge *lhs, const Edge *rhs) const {
210+ return (lhs->source->query->max_depth > rhs->source->query->max_depth);
211+ }
212+ };
213+ typedef std::priority_queue<Edge*, std::vector<Edge*>, ctl::CertainZeroFPA::edge_prioritizer> PriorityQueue;
214+};
215+}
216+#endif // CERTAINZEROFPA_H
217
218=== added file 'CTL/DependencyGraph.cpp'
219--- CTL/DependencyGraph.cpp 1970-01-01 00:00:00 +0000
220+++ CTL/DependencyGraph.cpp 2016-03-31 07:42:46 +0000
221@@ -0,0 +1,19 @@
222+#include "DependencyGraph.h"
223+#include <iostream>
224+
225+namespace ctl{
226+
227+DependencyGraph::DependencyGraph(PetriEngine::PetriNet *t_net, PetriEngine::MarkVal *t_initial) :
228+ _petriNet(t_net),
229+ _initialMarking(t_initial),
230+ _nplaces(t_net->numberOfPlaces()),
231+ _ntransitions(t_net->numberOfTransitions()){}
232+
233+void DependencyGraph::initialize(CTLTree &t_query){
234+ if(_query != NULL)
235+ clear(false);
236+ _query = &t_query;
237+}
238+
239+
240+}//ctl
241
242=== added file 'CTL/DependencyGraph.h'
243--- CTL/DependencyGraph.h 1970-01-01 00:00:00 +0000
244+++ CTL/DependencyGraph.h 2016-03-31 07:42:46 +0000
245@@ -0,0 +1,39 @@
246+#ifndef DEPENDENCYGRAPH_H
247+#define DEPENDENCYGRAPH_H
248+
249+#include "../PetriEngine/PetriNet.h"
250+#include "../CTLParser/CTLParser.h"
251+#include <list>
252+#include <iostream>
253+
254+namespace ctl{
255+
256+class Configuration;
257+class Edge;
258+
259+class DependencyGraph
260+{
261+public:
262+
263+ DependencyGraph(PetriEngine::PetriNet *t_net,
264+ PetriEngine::MarkVal *t_initial);
265+
266+ virtual ~DependencyGraph(){};
267+
268+ virtual std::list<Edge*> successors(Configuration &v) =0;
269+ virtual Configuration &initialConfiguration()=0;
270+ virtual void clear(bool t_clear_all = false) =0;
271+ virtual int configuration_count() =0;
272+ virtual int marking_count() =0;
273+
274+ void initialize(CTLTree &t_query);
275+
276+protected:
277+ CTLTree *_query;
278+ PetriEngine::PetriNet *_petriNet;
279+ PetriEngine::MarkVal *_initialMarking;
280+ int _nplaces;
281+ int _ntransitions;
282+};
283+}
284+#endif // DEPENDENCYGRAPH_H
285
286=== added file 'CTL/FixedPointAlgorithm.h'
287--- CTL/FixedPointAlgorithm.h 1970-01-01 00:00:00 +0000
288+++ CTL/FixedPointAlgorithm.h 2016-03-31 07:42:46 +0000
289@@ -0,0 +1,16 @@
290+#ifndef FIXEDPOINTALGORITHM_H
291+#define FIXEDPOINTALGORITHM_H
292+
293+#include "DependencyGraph.h"
294+#include "SearchStrategies/AbstractSearchStrategy.h"
295+
296+namespace ctl{
297+
298+class FixedPointAlgorithm
299+{
300+public:
301+ virtual bool search(DependencyGraph &t_graph,
302+ AbstractSearchStrategy &t_strategy)=0;
303+};
304+}
305+#endif // FIXEDPOINTALGORITHM_H
306
307=== added file 'CTL/LocalFPA.cpp'
308--- CTL/LocalFPA.cpp 1970-01-01 00:00:00 +0000
309+++ CTL/LocalFPA.cpp 2016-03-31 07:42:46 +0000
310@@ -0,0 +1,106 @@
311+#include "LocalFPA.h"
312+
313+bool ctl::LocalFPA::search(ctl::DependencyGraph &t_graph, ctl::AbstractSearchStrategy &W)
314+{
315+ PriorityQueue N;
316+
317+ Configuration &v = t_graph.initialConfiguration();
318+ v.assignment = ZERO;
319+
320+ for(Edge *e : t_graph.successors(v)){
321+ W.push(e);
322+ if(e->source->IsNegated)
323+ N.push(e);
324+ }
325+
326+ while(!W.empty() || !N.empty()){
327+ Edge *e;
328+
329+ if(!W.empty()) {
330+ e = W.pop();
331+ //std::cout << "Popped negation edge from N: \n" << std::flush;
332+ // e->edgePrinter();
333+ }
334+ else if (!N.empty()) {
335+ e = N.top();
336+ N.pop();
337+ //std::cout << "Popped negation edge from N: \n" << std::flush;
338+ //e->edgePrinter();
339+ }
340+
341+ /*****************************************************************/
342+ /*Data handling*/
343+ int targetONEassignments = 0;
344+ int targetZEROassignments = 0;
345+ int targetUKNOWNassignments = 0;
346+
347+ for(auto c : e->targets){
348+ if (c->assignment == ONE) {
349+ targetONEassignments++;
350+ }
351+ else if (c->assignment == ZERO) {
352+ targetZEROassignments++;
353+ }
354+ else if(c-> assignment == UNKNOWN){
355+ targetUKNOWNassignments++;
356+ }
357+
358+ }
359+ /*****************************************************************/
360+
361+ if(e->source->assignment == ONE){
362+ //std::cout << "== Ignored ==\n" << std::flush;
363+ }
364+ else if(e->targets.size() == targetONEassignments){
365+ if(e->source->IsNegated){
366+ e->source->assignment = ZERO;
367+ }
368+ else{
369+ e->source->assignment = ONE;
370+ if(e->source == &v) break;
371+
372+ for(Edge *de : e->source->DependencySet){
373+ W.push_dependency(de);
374+ }
375+ e->source->DependencySet.clear();
376+ }
377+ }
378+ else if(targetZEROassignments > 0){
379+ if(e->source->IsNegated && e->processed){
380+ e->source->assignment = ONE;
381+ //std::cout << "== Assigned ONE to NEG Edge ==\n" << std::flush;
382+ if(e->source == &v) break;
383+
384+ for(Edge *de : e->source->DependencySet){
385+ W.push_dependency(de);
386+ }
387+ e->source->DependencySet.clear();
388+ }
389+ else{
390+ for(auto c : e->targets){
391+ if(c->assignment == ZERO) {
392+ c->DependencySet.push_back(e);
393+ }
394+ }
395+ }
396+ }
397+ else if(targetUKNOWNassignments > 0){
398+ for(Configuration *tc : e->targets){
399+ if(tc->assignment == UNKNOWN){
400+ tc->assignment = ZERO;
401+ tc->DependencySet.push_back(e);
402+
403+ for(Edge *succ : t_graph.successors(*tc)){
404+ W.push(succ);
405+ if(succ->source->IsNegated){
406+ N.push(succ);
407+ }
408+ }
409+ }
410+ }
411+ }
412+ e->processed = true;
413+ }
414+
415+ return v.assignment == ONE ? true : false;
416+}
417
418=== added file 'CTL/LocalFPA.h'
419--- CTL/LocalFPA.h 1970-01-01 00:00:00 +0000
420+++ CTL/LocalFPA.h 2016-03-31 07:42:46 +0000
421@@ -0,0 +1,28 @@
422+#ifndef LOCALFPA_H
423+#define LOCALFPA_H
424+
425+#include "FixedPointAlgorithm.h"
426+#include "edge.h"
427+#include "configuration.h"
428+
429+#include <list>
430+#include <queue>
431+#include <vector>
432+
433+namespace ctl {
434+
435+class LocalFPA : public FixedPointAlgorithm
436+{
437+public:
438+ bool search(DependencyGraph &t_graph, AbstractSearchStrategy &t_strategy);
439+
440+private:
441+ struct edge_prioritizer{
442+ bool operator()(const Edge *lhs, const Edge *rhs) const {
443+ return (lhs->source->query->max_depth > rhs->source->query->max_depth);
444+ }
445+ };
446+ typedef std::priority_queue<Edge*, std::vector<Edge*>, ctl::LocalFPA::edge_prioritizer> PriorityQueue;
447+};
448+}
449+#endif // LOCALFPA_H
450
451=== added file 'CTL/OnTheFlyDG.cpp'
452--- CTL/OnTheFlyDG.cpp 1970-01-01 00:00:00 +0000
453+++ CTL/OnTheFlyDG.cpp 2016-03-31 07:42:46 +0000
454@@ -0,0 +1,367 @@
455+#include "OnTheFlyDG.h"
456+
457+#include <string.h>
458+
459+namespace ctl{
460+
461+OnTheFlyDG::OnTheFlyDG(PetriEngine::PetriNet *t_net, PetriEngine::MarkVal *t_initial):
462+ DependencyGraph(t_net, t_initial){_compressoption = false;}
463+
464+std::list<Edge *> OnTheFlyDG::successors(Configuration &v)
465+{
466+ std::list<Edge*> succ;
467+ //All
468+ if(v.query->quantifier == A){
469+ //All Until
470+ if(v.query->path == U){
471+ Configuration* c = createConfiguration(*(v.marking), *(v.query->second));
472+ Edge* e = new Edge(&v);
473+ e->targets.push_back(c);
474+
475+ auto targets = nextState (*(v.marking));
476+
477+ if(!targets.empty()){
478+ Edge* e1 = new Edge(&v);
479+ Configuration* b = createConfiguration(*(v.marking), *(v.query->first));
480+
481+ for(auto m : targets){
482+ Configuration* c = createConfiguration(*m, *(v.query));
483+ e1->targets.push_back(c);
484+ }
485+ e1->targets.push_back(b);
486+ succ.push_back(e1);
487+ }
488+
489+ succ.push_back(e);
490+
491+ } //All Until end
492+
493+ //All Next begin
494+ else if(v.query->path == X){
495+ auto targets = nextState(*v.marking);
496+ if(!targets.empty())
497+ {
498+ Edge* e = new Edge(&v);
499+
500+ for (auto m : targets){
501+ Configuration* c = createConfiguration(*m, *(v.query->first));
502+ e->targets.push_back(c);
503+ }
504+ succ.push_back(e);
505+ }
506+ } //All Next End
507+
508+ //All Finally start
509+ else if(v.query->path == F){
510+ Edge* e = new Edge(&v);
511+ Configuration* c = createConfiguration(*(v.marking), *(v.query->first));
512+ e->targets.push_back(c);
513+
514+ auto targets = nextState(*(v.marking));
515+
516+ if(!targets.empty()){
517+ Edge* e1 = new Edge();
518+ e1->source = &v;
519+
520+ for(auto m : targets){
521+ Configuration* c = createConfiguration(*m, *(v.query));
522+ e1->targets.push_back(c);
523+ }
524+ succ.push_back(e1);
525+ }
526+ succ.push_back(e);
527+ }//All Finally end
528+ } //All end
529+
530+ //Exists start
531+ else if (v.query->quantifier == E){
532+
533+ //Exists Untill start
534+ if(v.query->path == U){
535+ Configuration* c = createConfiguration(*(v.marking), *(v.query->second));
536+ Edge* e = new Edge(&v);
537+ e->targets.push_back(c);
538+
539+ auto targets = nextState(*(v.marking));
540+
541+ if(!targets.empty()){
542+ Configuration* c = createConfiguration(*(v.marking), *(v.query->first));
543+ for(auto m : targets){
544+ Edge* e = new Edge(&v);
545+ Configuration* c1 = createConfiguration(*m, *(v.query));
546+ e->targets.push_back(c1);
547+ e->targets.push_back(c);
548+ succ.push_back(e);
549+ }
550+ }
551+ succ.push_back(e);
552+ } //Exists Until end
553+
554+ //Exists Next start
555+ else if(v.query->path == X){
556+ auto targets = nextState(*(v.marking));
557+ CTLTree* query = v.query->first;
558+
559+ if(!targets.empty())
560+ {
561+ for(auto m : targets){
562+ Edge* e = new Edge(&v);
563+ Configuration* c = createConfiguration(*m, *query);
564+ e->targets.push_back(c);
565+ succ.push_back(e);
566+ }
567+ }
568+ }//Exists Next end
569+
570+ //Exists Finally start
571+ else if(v.query->path == F){
572+ Configuration* c = createConfiguration(*(v.marking), *(v.query->first));
573+ Edge* e = new Edge(&v);
574+ e->targets.push_back(c);
575+
576+ auto targets = nextState(*(v.marking));
577+
578+ if(!targets.empty()){
579+ for(auto m : targets){
580+ Edge* e = new Edge(&v);
581+ Configuration* c = createConfiguration(*m, *(v.query));
582+ e->targets.push_back(c);
583+ succ.push_back(e);
584+ }
585+ }
586+ succ.push_back(e);
587+
588+ }//Exists Finally end
589+ } //Exists end
590+
591+ //And start
592+ else if (v.query->quantifier == AND){
593+ Configuration* c = createConfiguration(*(v.marking), *(v.query->first));
594+ Configuration* c1 = createConfiguration(*(v.marking), *(v.query->second));
595+ Edge* e = new Edge(&v);
596+ e->targets.push_back(c);
597+ e->targets.push_back(c1);
598+ succ.push_back(e);
599+ } //And end
600+
601+ //Or start
602+ else if (v.query->quantifier == OR){
603+ Configuration* c = createConfiguration(*(v.marking), *(v.query->first));
604+ Configuration* c1 = createConfiguration(*(v.marking), *(v.query->second));
605+ Edge* e = new Edge(&v);
606+ Edge* e1 = new Edge(&v);
607+ e->targets.push_back(c);
608+ e1->targets.push_back(c1);
609+ succ.push_back(e);
610+ succ.push_back(e1);
611+ } //Or end
612+
613+ //Negate start
614+ else if (v.query->quantifier == NEG){
615+ Configuration* c = createConfiguration(*(v.marking), *(v.query->first));
616+ Edge* e = new Edge(&v);
617+ e->targets.push_back(c);
618+ succ.push_back(e);
619+ } //Negate end
620+
621+ //Evaluate Query Begin
622+ else {
623+ //Edge* e = new Edge(&v);
624+ //e->targets.push_back(&v);
625+ // v.configPrinter();
626+ if (evaluateQuery(v)){
627+ //assignConfiguration(&v, ONE);
628+ succ.push_back(new Edge(&v));
629+ } else {
630+ //assignConfiguration(&v, CZERO);
631+ }
632+ //succ.push_back(e);
633+
634+ }
635+
636+ v.Successors = succ;
637+ return succ;
638+ //computedSucc += succ.size();
639+ //std::cout << "-----------EDGES NOW : " << computedSucc << "\n" << std::flush;
640+}
641+
642+Configuration &OnTheFlyDG::initialConfiguration()
643+{
644+ Marking *initial = new Marking(_initialMarking, _nplaces);
645+ return *createConfiguration(*initial, *_query);
646+}
647+
648+bool OnTheFlyDG::evaluateQuery(Configuration &t_config){
649+
650+ CTLTree* query = t_config.query;
651+
652+ bool result = false;
653+
654+ if (t_config.query->a.isFireable) {
655+ std::list<int> transistions = calculateFireableTransistions(*(t_config.marking));
656+
657+ for (auto t : transistions) {
658+ int fs_transition = 0;
659+ for(fs_transition = 0; fs_transition < query->a.firesize; fs_transition++){
660+ int dpc_place = 0;
661+ int truedependencyplaces = 0;
662+ for (dpc_place = 0; dpc_place < query->a.fireset[fs_transition].sizeofdenpencyplaces; dpc_place++){
663+
664+ if((query->a.fireset[fs_transition].denpencyplaces[dpc_place].intSmaller - 1) < t_config.marking->Value()[query->a.fireset[fs_transition].denpencyplaces[dpc_place].placeLarger]){
665+ //std::cout<<_net->placeNames()[query->a.fireset[fs_transition].denpencyplaces[dpc_place].placeLarger]<<" is true"<<std::endl;
666+ truedependencyplaces++;
667+ }
668+ }
669+ if (truedependencyplaces == query->a.fireset[fs_transition].sizeofdenpencyplaces){
670+ result = true;
671+ }
672+ }
673+ }
674+ return result;
675+ }
676+
677+ ///std::cout<<"Evaluating cardinality... "<<std::endl;
678+ // t_config.configPrinter();
679+ // std::cout<<"Less: ";
680+ int less = query->a.cardinality.intSmaller;
681+ int greater= query->a.cardinality.intLarger;
682+ if( less == -1 ){
683+ int i = 0;
684+ less = 0;
685+ for (i = 0; i < query->a.cardinality.placeSmaller.sizeoftokencount; i++){
686+ int index = query->a.cardinality.placeSmaller.cardinality[i];
687+ less += t_config.marking->Value()[index];
688+ // std::cout<<t_config.marking->Value()[index]<<" + ";
689+ }
690+ }
691+// std::cout<<" = "<<less<<std::endl;
692+// std::cout<<"Greater: ";
693+ if (greater == -1){
694+ int i = 0;
695+ greater = 0;
696+ // std::cout<<"::: Number of places: "<<query->a.cardinality.placeLarger.sizeoftokencount<<std::endl;
697+ for (i = 0; i < query->a.cardinality.placeLarger.sizeoftokencount; i++){
698+ //std::cout<<"::::: i: "<<i<<std::endl;
699+ int index = query->a.cardinality.placeLarger.cardinality[i];
700+ //std::cout<<"::::: Index: "<<index<<" - Value: "<<t_config.marking->Value()[index]<<std::endl;
701+ greater += t_config.marking->Value()[index];
702+ // std::cout<<t_config.marking->Value()[index]<<" + ";
703+ // std::cout<<"::::: greater: "<<greater<<std::endl;
704+ }
705+
706+ }
707+ // std::cout<<" = "<<greater<<std::endl;
708+
709+ result = less <= greater;
710+ // std::cout<<"... evaluation Done"<<std::endl;
711+ return result;
712+}
713+
714+int OnTheFlyDG::indexOfPlace(char *t_place){
715+ for (int i = 0; i < _nplaces; i++) {
716+ if (0 == (strcmp(t_place, _petriNet->placeNames()[i].c_str()))){
717+ //cout << "place " << query->a.tokenCount.placeLarger << " " << flush;
718+ return i;
719+ }
720+ }
721+ return -1;
722+}
723+
724+std::list<Marking*> OnTheFlyDG::nextState(Marking& t_marking){
725+
726+ std::list<int> fireableTransistions = calculateFireableTransistions(t_marking);
727+ std::list<Marking*> nextStates;
728+
729+ auto iter = fireableTransistions.begin();
730+ auto iterEnd = fireableTransistions.end();
731+
732+ //Create new markings for each fireable transistion
733+ for(; iter != iterEnd; iter++){
734+ nextStates.push_back(createMarking(t_marking, *iter));
735+ }
736+
737+ //return the set of reachable markings
738+
739+ return nextStates;
740+}
741+
742+std::list<int> OnTheFlyDG::calculateFireableTransistions(Marking &t_marking){
743+
744+ std::list<int> fireableTransistions;
745+
746+ for(int t = 0; t < _ntransitions; t++){
747+ bool transitionFound = true;
748+ for(int p = 0; p < _nplaces; p++){
749+ if(t_marking[p] < _petriNet->inArc(p,t))
750+ transitionFound = false;
751+ }
752+
753+ if(transitionFound)
754+ fireableTransistions.push_back(t);
755+ }
756+ return fireableTransistions;
757+}
758+
759+
760+void OnTheFlyDG::clear(bool t_clear_all)
761+{
762+ for(auto c : Configurations){
763+ delete c;
764+ }
765+ Configurations.clear();
766+
767+ if(t_clear_all){
768+ for(auto m : Markings){
769+ delete m;
770+ }
771+ Markings.clear();
772+ }
773+}
774+
775+Configuration *OnTheFlyDG::createConfiguration(Marking &t_marking, CTLTree &t_query)
776+{
777+ Configuration* newConfig = new Configuration();
778+ newConfig->marking = &t_marking;
779+ newConfig->query = &t_query;
780+
781+ //Default value is false
782+ if(t_query.quantifier == NEG){
783+ newConfig->IsNegated = true;
784+ }
785+ auto pair = Configurations.insert(newConfig);
786+
787+ if(!pair.second) {
788+ delete newConfig;
789+ }
790+
791+ return *(pair.first);
792+}
793+
794+
795+
796+Marking *OnTheFlyDG::createMarking(const Marking& t_marking, int t_transition){
797+ Marking* new_marking = new Marking();
798+
799+ new_marking->CopyMarking(t_marking);
800+
801+ for(int p = 0; p < _nplaces; p++){
802+ int place = (*new_marking)[p] - _petriNet->inArc(p,t_transition);
803+ (*new_marking)[p] = place + _petriNet->outArc(t_transition,p);
804+ }
805+
806+ auto result = Markings.find(new_marking);
807+
808+ if(result == Markings.end()){
809+ // std::cout << "Inserted marking - Size now: " << Markings.size() << std::endl;
810+ return *(Markings.insert(new_marking).first);
811+ }
812+ else{
813+ delete new_marking;
814+ // std::cout << "Marking exists - Size now: " << Markings.size() << std::endl;
815+ }
816+
817+
818+ return *result;
819+}
820+
821+}//ctl
822
823=== added file 'CTL/OnTheFlyDG.h'
824--- CTL/OnTheFlyDG.h 1970-01-01 00:00:00 +0000
825+++ CTL/OnTheFlyDG.h 2016-03-31 07:42:46 +0000
826@@ -0,0 +1,49 @@
827+#ifndef ONTHEFLYDG_H
828+#define ONTHEFLYDG_H
829+
830+#include "DependencyGraph.h"
831+#include "marking.h"
832+#include "configuration.h"
833+#include "edge.h"
834+
835+#include <boost/unordered_set.hpp>
836+#include <list>
837+
838+namespace ctl {
839+
840+class OnTheFlyDG : public DependencyGraph
841+{
842+public:
843+ OnTheFlyDG(PetriEngine::PetriNet *t_net,
844+ PetriEngine::MarkVal *t_initial);
845+
846+ // DependencyGraph interface
847+ std::list<Edge *> successors(Configuration &v);
848+ Configuration &initialConfiguration();
849+ void clear(bool t_clear_all);
850+ int configuration_count() { return Configurations.size();}
851+ int marking_count() { return Markings.size(); }
852+
853+
854+ boost::unordered_set< Marking*,
855+ boost::hash<Marking*>,
856+ Marking::Marking_Equal_To> Markings;
857+
858+ boost::unordered_set< Configuration*,
859+ boost::hash<Configuration*>,
860+ Configuration::Configuration_Equal_To> Configurations;
861+ bool isCompressing() {return _compressoption;};
862+
863+protected:
864+ bool evaluateQuery(Configuration &t_config);
865+ bool _compressoption;
866+ int indexOfPlace(char *t_place);
867+ std::list<Marking *> nextState(Marking &t_marking);
868+ std::list<int> calculateFireableTransistions(Marking &t_marking);
869+ Configuration *createConfiguration(Marking &t_marking, CTLTree &t_query);
870+ Marking *createMarking(const Marking &t_marking, int t_transition);
871+ void initCompressOption();
872+
873+};
874+}
875+#endif // ONTHEFLYDG_H
876
877=== added directory 'CTL/SearchStrategies'
878=== added file 'CTL/SearchStrategies/AbstractSearchStrategy.h'
879--- CTL/SearchStrategies/AbstractSearchStrategy.h 1970-01-01 00:00:00 +0000
880+++ CTL/SearchStrategies/AbstractSearchStrategy.h 2016-03-31 07:42:46 +0000
881@@ -0,0 +1,23 @@
882+#ifndef ABSTRACTSEARCHSTRATEGY_H
883+#define ABSTRACTSEARCHSTRATEGY_H
884+
885+#include <cstddef>
886+
887+namespace ctl {
888+
889+class Edge; //Forward declaration of edge
890+
891+class AbstractSearchStrategy {
892+public:
893+ virtual void push(Edge *e) =0;
894+ virtual void push_dependency(Edge *e) =0;
895+ virtual Edge *pop() =0;
896+ virtual bool remove(Edge *e) =0;
897+ virtual size_t size() =0;
898+ virtual bool empty() =0;
899+ virtual void clear()=0;
900+};
901+
902+}
903+
904+#endif // ABSTRACTSEARCHSTRATEGY_H
905
906=== added file 'CTL/SearchStrategies/DepthFirstSearch.cpp'
907--- CTL/SearchStrategies/DepthFirstSearch.cpp 1970-01-01 00:00:00 +0000
908+++ CTL/SearchStrategies/DepthFirstSearch.cpp 2016-03-31 07:42:46 +0000
909@@ -0,0 +1,37 @@
910+#include "DepthFirstSearch.h"
911+
912+ctl::DepthFirstSearch::DepthFirstSearch()
913+{
914+}
915+
916+void ctl::DepthFirstSearch::push(ctl::Edge *e)
917+{
918+ W.push_back(e);
919+}
920+
921+void ctl::DepthFirstSearch::push_dependency(ctl::Edge *e)
922+{
923+ W.push_back(e);
924+}
925+
926+ctl::Edge *ctl::DepthFirstSearch::pop()
927+{
928+ Edge *e = W.back();
929+ W.pop_back();
930+ return e;
931+}
932+
933+bool ctl::DepthFirstSearch::remove(ctl::Edge *e)
934+{
935+ iterator current = W.begin();
936+ iterator end = W.end();
937+
938+ while(current != end){
939+ if((*current) == e){
940+ W.erase(current);
941+ return true;
942+ }
943+ }
944+
945+ return false;
946+}
947
948=== added file 'CTL/SearchStrategies/DepthFirstSearch.h'
949--- CTL/SearchStrategies/DepthFirstSearch.h 1970-01-01 00:00:00 +0000
950+++ CTL/SearchStrategies/DepthFirstSearch.h 2016-03-31 07:42:46 +0000
951@@ -0,0 +1,28 @@
952+#ifndef DEPTHFIRSTSEARCH_H
953+#define DEPTHFIRSTSEARCH_H
954+
955+#include <deque>
956+#include "AbstractSearchStrategy.h"
957+
958+namespace ctl{
959+
960+class DepthFirstSearch : public ctl::AbstractSearchStrategy
961+{
962+public:
963+ DepthFirstSearch();
964+
965+ // AbstractSearchStrategy interface
966+ void push(Edge *e);
967+ void push_dependency(Edge *e);
968+ Edge *pop();
969+ bool remove(Edge *e);
970+ size_t size() {return W.size();}
971+ bool empty() {return W.empty();}
972+ void clear(){ W.clear();}
973+
974+private:
975+ std::deque<Edge*> W; //Waiting list
976+ typedef std::deque<Edge*>::iterator iterator;
977+};
978+}
979+#endif // DEPTHFIRSTSEARCH_H
980
981=== added file 'CTL/configuration.cpp'
982--- CTL/configuration.cpp 1970-01-01 00:00:00 +0000
983+++ CTL/configuration.cpp 2016-03-31 07:42:46 +0000
984@@ -0,0 +1,62 @@
985+#include "configuration.h"
986+
987+namespace ctl{
988+
989+Configuration::Configuration(Marking * t_marking, CTLTree * t_query){
990+ marking = t_marking;
991+ query = t_query;
992+}
993+
994+Configuration::~Configuration(){
995+
996+ for(Edge* e: Successors){
997+ delete (e);
998+ }
999+ for(Edge* e: deletedSuccessors){
1000+ delete e;
1001+ }
1002+}
1003+
1004+void Configuration::removeSuccessor(Edge *t_successor){
1005+ {
1006+ if (t_successor->isDeleted)
1007+ return;
1008+ Successors.remove(t_successor);
1009+
1010+ for(auto t : t_successor->targets){
1011+ t->DependencySet.remove(t_successor);
1012+ }
1013+
1014+ t_successor->isDeleted = true;
1015+ deletedSuccessors.push_front(t_successor);
1016+ //delete t_successor;
1017+ return;
1018+ }
1019+}
1020+
1021+
1022+void Configuration::configPrinter(){
1023+ CTLParser ctlParser = CTLParser();
1024+ int i = 0;
1025+ std::cout << "Marking: ";
1026+ marking->print();
1027+ std::cout << " Q: " << std::flush;
1028+ ctlParser.printQuery(query);
1029+ std::cout << " D: "<<query->depth << std::flush;
1030+ std::cout << " Assign: " << assignment << std::flush;
1031+
1032+ std::cout << " NEG: " << IsNegated << "\n" << std::flush;
1033+}
1034+
1035+bool Configuration::operator ==(const Configuration& rhs) const{
1036+ if(query != rhs.query)
1037+ return false;
1038+ else if(IsNegated != rhs.IsNegated)
1039+ return false;
1040+ else if(*marking == *(rhs.marking))//Use equality from marking
1041+ return true;
1042+ else
1043+ return false;
1044+}
1045+
1046+}
1047
1048=== added file 'CTL/configuration.h'
1049--- CTL/configuration.h 1970-01-01 00:00:00 +0000
1050+++ CTL/configuration.h 2016-03-31 07:42:46 +0000
1051@@ -0,0 +1,73 @@
1052+#ifndef CONFIGURATION_H
1053+#define CONFIGURATION_H
1054+
1055+#include "../CTLParser/CTLParser.h"
1056+#include "marking.h"
1057+#include "edge.h"
1058+#include <list>
1059+#include <stdint.h>
1060+
1061+namespace ctl {
1062+
1063+class Edge;
1064+
1065+enum Assignment {
1066+ ONE = 1, UNKNOWN = 0, ZERO = -1, CZERO = -2
1067+};
1068+
1069+class Configuration
1070+{
1071+public:
1072+
1073+ struct Configuration_Equal_To{
1074+ bool operator()(const Configuration* rhs, const Configuration* lhs) const{
1075+ return (*rhs)==(*lhs);
1076+ }
1077+ };
1078+
1079+ Configuration(){}
1080+ Configuration(Marking* t_marking, CTLTree* t_query);
1081+ virtual ~Configuration();
1082+
1083+ void removeSuccessor(Edge *t_successor);
1084+ void configPrinter();
1085+
1086+ bool operator==(const Configuration& rhs)const;
1087+ bool operator!=(const Configuration &rhs) const {return !(*this == rhs);}
1088+
1089+ Marking* marking;
1090+ CTLTree* query;
1091+ std::list<Edge*> Successors;
1092+ std::list<Edge*> DependencySet;
1093+ bool IsNegated = false;
1094+ Assignment assignment = UNKNOWN;
1095+
1096+private:
1097+ std::list<Edge*> deletedSuccessors;
1098+};
1099+}// end of ctl
1100+
1101+namespace boost {
1102+ //Hash specialization implementations
1103+ template<>
1104+ struct hash<ctl::Configuration>{
1105+ size_t operator()(const ctl::Configuration& t_config) const {
1106+ hash<ctl::Marking> hasher;
1107+ size_t seed = (size_t)reinterpret_cast<uintptr_t>(t_config.query);
1108+ //Combine query ptr adr with marking hashing
1109+ size_t result = hasher.operator ()(*t_config.marking);
1110+ result ^= seed + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1111+
1112+ return result;
1113+ }
1114+ };
1115+ template<>
1116+ struct hash<ctl::Configuration*>{
1117+ size_t operator()(const ctl::Configuration* t_config) const {
1118+ hash<ctl::Configuration> hasher;
1119+ return hasher.operator ()(*t_config);
1120+ }
1121+ };
1122+}
1123+
1124+#endif // CONFIGURATION_H
1125
1126=== added file 'CTL/edge.cpp'
1127--- CTL/edge.cpp 1970-01-01 00:00:00 +0000
1128+++ CTL/edge.cpp 2016-03-31 07:42:46 +0000
1129@@ -0,0 +1,75 @@
1130+#include "edge.h"
1131+#include "configuration.h"
1132+
1133+namespace ctl{
1134+
1135+// bool Edge::operator ==(const Edge& rhs) const {
1136+// if(source != rhs.source)
1137+// return false;
1138+// if(!(targets == rhs.targets))
1139+// return false;
1140+
1141+// return true;
1142+// }
1143+
1144+
1145+
1146+void Edge::edgePrinter(){
1147+ std::cout << "--------------- Edge Information -------------------\n";
1148+ std::cout << "--------------- source config----------------------\n";
1149+ source->configPrinter();
1150+ std::cout << "--------------- target configs----------------------\n";
1151+ for( auto c : targets){
1152+ c->configPrinter();
1153+ }
1154+ std::cout << "-------------------------------------------------------\n";
1155+ }
1156+
1157+void Edge::rateEdge(){
1158+
1159+ if(Rating > -1){
1160+ return;
1161+ }
1162+ int alpha = 1;
1163+ int beta = 1;
1164+ int gamma = 1;
1165+
1166+ int dist = source->query->depth;
1167+ int breath = 0;
1168+ int succ = source->Successors.size();
1169+
1170+ for(auto t : targets){
1171+ breath++;
1172+ }
1173+ //make equation
1174+ Rating = (alpha*dist) + (beta*breath) + (gamma*succ);
1175+}
1176+
1177+}
1178+//namespace std{
1179+// // Specializations of hash functions.
1180+// // Normal
1181+// template<>
1182+// struct hash<ctl::Edge>{
1183+// size_t operator()(const ctl::Edge& t_edge ) const {
1184+// size_t seed = 0x9e3779b9;
1185+// hash<ctl::Configuration> hasher;
1186+// size_t result = hasher.operator()(*t_edge.source);
1187+
1188+// for(auto t : t_edge.targets){
1189+// result ^= hasher.operator()(*t);
1190+// }
1191+// result ^= seed + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1192+
1193+// return result;
1194+// }
1195+// };
1196+// //
1197+// template<>
1198+// struct hash<ctl::Edge*>{
1199+// size_t operator()(const ctl::Edge* t_edge ) const {
1200+// hash<ctl::Edge> hasher;
1201+// return hasher.operator ()(*t_edge);
1202+// }
1203+// };
1204+//}
1205
1206=== added file 'CTL/edge.h'
1207--- CTL/edge.h 1970-01-01 00:00:00 +0000
1208+++ CTL/edge.h 2016-03-31 07:42:46 +0000
1209@@ -0,0 +1,44 @@
1210+#ifndef EDGE_H
1211+#define EDGE_H
1212+
1213+#include <list>
1214+#include <iostream>
1215+
1216+
1217+namespace ctl {
1218+
1219+//To avoid circular dependency
1220+class Configuration;
1221+
1222+class Edge
1223+{
1224+public:
1225+ class EdgePointerEqual{
1226+ bool operator()(const Edge& lhs, const Edge& rhs) const{
1227+ return &lhs == &rhs;
1228+ }
1229+ };
1230+ class EdgePointerHash{
1231+ size_t operator()(const Edge* e)const{
1232+ return (size_t)e;
1233+ }
1234+ };
1235+
1236+ Edge(){};
1237+ Edge(Configuration* t_source) : source(t_source) {}
1238+ //virtual ~Edge(){std::cout << "Destroying Edge" << std::endl;}
1239+
1240+ bool processed = false;
1241+ //bool isDeleted = false;
1242+ int Rating = -1;
1243+ bool isDeleted = false;
1244+ Configuration* source;
1245+ std::list<Configuration*> targets;
1246+
1247+ //bool operator==(const Edge & rhs) const;
1248+ void edgePrinter();
1249+ void rateEdge();
1250+};
1251+}
1252+
1253+#endif // EDGE_H
1254
1255=== added file 'CTL/marking.cpp'
1256--- CTL/marking.cpp 1970-01-01 00:00:00 +0000
1257+++ CTL/marking.cpp 2016-03-31 07:42:46 +0000
1258@@ -0,0 +1,38 @@
1259+#include <string.h>
1260+#include <iostream>
1261+
1262+#include "../PetriEngine/PetriNet.h"
1263+
1264+#include "marking.h"
1265+
1266+using namespace PetriEngine;
1267+
1268+namespace ctl {
1269+
1270+ bool Marking::operator ==(const Marking& rhs) const {
1271+ for(int i = 0; i < this->Length(); i++){
1272+ if(!(this->Value()[i] == rhs.Value()[i])){
1273+ return false;
1274+ }
1275+ } return true;
1276+ //return (0 == (memcmp(this->Value(), rhs.Value(), this->Length())));
1277+ }
1278+
1279+ void Marking::CopyMarking(const Marking& t_marking){
1280+ this->m_marking = (MarkVal*)malloc(sizeof(MarkVal) * t_marking.Length());
1281+ this->m_length = t_marking.Length();
1282+
1283+ for(int i = 0; i < m_length; i++){
1284+ m_marking[i] = t_marking[i];
1285+ }
1286+ }
1287+
1288+
1289+ void Marking::print() const {
1290+ for(int i = 0; i < m_length; i++){
1291+ std::cout << m_marking[i] <<std::flush;
1292+ }
1293+ }
1294+
1295+}
1296+
1297
1298=== added file 'CTL/marking.h'
1299--- CTL/marking.h 1970-01-01 00:00:00 +0000
1300+++ CTL/marking.h 2016-03-31 07:42:46 +0000
1301@@ -0,0 +1,76 @@
1302+#ifndef MARKING_H
1303+#define MARKING_H
1304+
1305+#include <vector>
1306+#include <boost/functional/hash/hash.hpp>
1307+#include "../PetriEngine/PetriNet.h"
1308+
1309+namespace ctl {
1310+
1311+//A Marking is essentially just an Array.
1312+//However since C++ does not support
1313+//VLA we must make use of a variable to
1314+//said length.
1315+//Along with that we are going make a few
1316+//inline functions to make the class
1317+//act/look/feel like an array.
1318+
1319+class Marking
1320+{
1321+ public:
1322+ // Equality checker for containers
1323+ // with pointers to markings
1324+ struct Marking_Equal_To{
1325+ bool operator()(const Marking* rhs, const Marking* lhs) const{
1326+ return (*rhs)==(*lhs);
1327+ }
1328+ };
1329+
1330+ Marking(){}
1331+ Marking(PetriEngine::MarkVal* t_marking, size_t t_length)
1332+ : m_marking(t_marking), m_length(t_length){}
1333+
1334+ virtual ~Marking(){ free(m_marking); }
1335+
1336+ void CopyMarking(const Marking& t_marking);
1337+
1338+ bool operator==(const Marking& rhs) const;
1339+
1340+ //Hopefully the compiler with agree with this inlining
1341+ inline PetriEngine::MarkVal& operator[](const int index) const {
1342+ return m_marking[index];
1343+ }
1344+ inline PetriEngine::MarkVal* Value() const {return m_marking;}
1345+ void print() const;
1346+ inline size_t Length() const {return m_length;}
1347+private:
1348+ PetriEngine::MarkVal* m_marking;
1349+ size_t m_length;
1350+};
1351+}
1352+
1353+namespace boost {
1354+ // Specializations of hash functions.
1355+ // Normal
1356+ template<>
1357+ struct hash<ctl::Marking>{
1358+ size_t operator()(const ctl::Marking& t_marking ) const {
1359+ size_t seed = 0x9e3779b9;
1360+
1361+ for(int i = 0; i < t_marking.Length(); i++){
1362+ seed ^= t_marking[i] + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1363+ }
1364+
1365+ return seed;
1366+ }
1367+ };
1368+ // Pointer to Marking
1369+ template<>
1370+ struct hash<ctl::Marking*>{
1371+ size_t operator()(const ctl::Marking* t_marking ) const {
1372+ hash<ctl::Marking> hasher;
1373+ return hasher.operator ()(*t_marking);
1374+ }
1375+ };
1376+}
1377+#endif // MARKING_H
1378
1379=== added directory 'CTLParser'
1380=== added file 'CTLParser/CTLParser.cpp'
1381--- CTLParser/CTLParser.cpp 1970-01-01 00:00:00 +0000
1382+++ CTLParser/CTLParser.cpp 2016-03-31 07:42:46 +0000
1383@@ -0,0 +1,575 @@
1384+/*
1385+ * File: CTLParser.cpp
1386+ * Author: mossns
1387+ *
1388+ * Created on September 30, 2015, 10:39 AM
1389+ */
1390+
1391+#include <string>
1392+#include <fstream>
1393+#include <string.h>
1394+#include <iostream>
1395+#include <stdio.h>
1396+#include <vector>
1397+#include "rapidxml-1.13/rapidxml.hpp"
1398+
1399+#include "CTLParser.h"
1400+
1401+
1402+using namespace rapidxml;
1403+
1404+CTLParser::CTLParser() {
1405+}
1406+
1407+CTLParser::CTLParser(PetriEngine::PetriNet* net) {
1408+ _net = net;
1409+}
1410+
1411+CTLParser::CTLParser(const CTLParser& orig) {
1412+}
1413+
1414+CTLParser::~CTLParser() {
1415+}
1416+
1417+void CTLParser::ParseXMLQuery(std::vector<char> buffer, CTLFormula *queryList[]) {
1418+ #ifdef DEBUG
1419+ std::cout << "Creating doc\n" << std::flush;
1420+ #endif
1421+// CTLquery ctlquery;
1422+ xml_document<> doc;
1423+ xml_node<> * root_node;
1424+
1425+ #ifdef DEBUG
1426+ std::cout << "Size of Path enum: " << sizeof(Path)*8 <<"\n";
1427+ #endif
1428+ doc.parse<0>(&buffer[0]);
1429+
1430+
1431+#ifdef DEBUG
1432+ std::cout << "First node id: " << doc.first_node()->name() << std::endl;
1433+#endif
1434+
1435+ root_node = doc.first_node();
1436+
1437+#ifdef Analysis
1438+ std::cout << "\nAnalysis:: Queries:" << std::endl;
1439+#endif
1440+
1441+ int i = 0;
1442+ for (xml_node<> * property_node = root_node->first_node("property"); property_node; property_node = property_node->next_sibling()) {
1443+ xml_node<> * id_node = property_node->first_node("id");
1444+ queryList[i] = (CTLFormula*)malloc(sizeof(CTLFormula));
1445+
1446+ //Set competition information
1447+ int size = id_node->value_size();
1448+ queryList[i]->Name = strcpy((char*)calloc(size, sizeof(char)*size),
1449+ id_node->value());
1450+ queryList[i]->Result = false;
1451+ queryList[i]->Techniques = new std::vector<std::string>();
1452+
1453+ //Fill list with individual queries
1454+ xml_node<> * formula_node = id_node->next_sibling("description")->next_sibling("formula");
1455+ queryList[i]->Query = xmlToCTLquery(formula_node->first_node());
1456+
1457+ // printQuery(queryList[i]->Query);
1458+ // std::cout << "\n";
1459+
1460+ i++;
1461+ }
1462+}
1463+
1464+CTLTree* CTLParser::xmlToCTLquery(xml_node<> * root) {
1465+ bool isA = false;
1466+ bool isE = false;
1467+ CTLTree *query = (CTLTree*)malloc(sizeof(CTLTree));
1468+ char *root_name = root->name();
1469+ char firstLetter = root_name[0];
1470+
1471+ //Parse query segment
1472+ if (firstLetter == 'a') {
1473+ //Construct All (Transformed if AG)
1474+ isA = true;
1475+ query->quantifier = A;
1476+ query->path = setPathOperator(root->first_node(), isA, isE);
1477+ isA = false;
1478+ if(isAG){
1479+ createAGquery(root, query);
1480+ return query;
1481+ }
1482+
1483+ }
1484+ else if (firstLetter == 'e' ) {
1485+ //Construct Exist (Transformed if EG)
1486+ isE = true;
1487+ query->quantifier = E;
1488+ query->path = setPathOperator(root->first_node(), isA, isE);
1489+ isE = false;
1490+ if(isEG){
1491+ createEGquery(root, query);
1492+ return query;
1493+ }
1494+
1495+ }
1496+ else if (firstLetter == 'n' ) {
1497+ //Construct negation
1498+ query->quantifier = NEG;
1499+
1500+ }
1501+ else if (firstLetter == 'c' ) {
1502+ //Construct conjunction
1503+ query->quantifier = AND;
1504+ }
1505+ else if (firstLetter == 'd' ) {
1506+ //Construct disjunction
1507+ query->quantifier = OR;
1508+ }
1509+ else if (firstLetter == 'i' ) {
1510+ //Construct Atom
1511+ query->quantifier = EMPTY;
1512+ query->depth = 0;
1513+ query->max_depth = 0;
1514+ if (root_name[1] == 's' ) { // Check if Fireability query
1515+ constructFireAtom(query, root);
1516+ return query;
1517+ }
1518+ else if (root_name[1] == 'n') { // Check if Cardinality query
1519+ constructCardinalityAtom(query, root);
1520+ return query;
1521+ }
1522+ else {
1523+ #ifdef DEBUG
1524+ std::cout << "ERROR in xmlToCTLquery: Invalid atom " << root_name << "\n";
1525+ #endif
1526+ }
1527+ }
1528+ else {
1529+ #ifdef DEBUG
1530+ std::cout << "ERROR in xmlToCTLquery: Invalid boolean operator: " << root_name << "\n";
1531+ #endif
1532+ }
1533+
1534+
1535+ //Create query children
1536+ if (query->path == pError) {
1537+ #ifdef DEBUG
1538+ std::cout << "ERROR in xmlToCTLquery: !!Exiting - parse error!!\n";
1539+ #endif
1540+ }
1541+ else if (query->path == U) {
1542+ xml_node<> * child_node = root->first_node()->first_node();
1543+ query->first = xmlToCTLquery(child_node->first_node());
1544+ child_node = child_node->next_sibling();
1545+ query->second = xmlToCTLquery(child_node->first_node());
1546+ }
1547+ else if (query->quantifier == AND || query->quantifier == OR) {
1548+ xml_node<> * child_node = root->first_node();
1549+ query->first = xmlToCTLquery(child_node);
1550+ child_node = child_node->next_sibling();
1551+ query->second = xmlToCTLquery(child_node);
1552+ }
1553+ else if (query->quantifier == NEG) {
1554+ query->first = xmlToCTLquery(root->first_node());
1555+ }
1556+ else {
1557+ query->first = xmlToCTLquery(root->first_node()->first_node());
1558+ }
1559+
1560+
1561+ //Update query depth information
1562+ if (query->quantifier == AND || query->quantifier == OR || query->path == U){
1563+ int first_depth = query->first->depth, second_depth = query->second->depth;
1564+ query->depth = (lowerDepth(first_depth, second_depth) + 1);
1565+
1566+ int first_max_depth = query->first->max_depth, second_max_depth = query->second->max_depth;
1567+ query->max_depth = (higherDepth(first_max_depth, second_max_depth) + 1);
1568+ }
1569+ else {
1570+ query->depth = (query->first->depth + 1);
1571+ query->max_depth = (query->first->max_depth + 1);
1572+ }
1573+
1574+ return query;
1575+}
1576+
1577+Path CTLParser::setPathOperator(xml_node<> * root, bool isA, bool isE) {
1578+ char *root_name = root->name();
1579+ char firstLetter = root_name[0];
1580+
1581+ if (firstLetter == 'g') {
1582+ if(isA) { isAG = true; }
1583+ if(isE){ isEG = true; }
1584+ return G;
1585+ }
1586+ else if (firstLetter == 'f') {
1587+ isEG = false;
1588+ isAG = false;
1589+ return F;
1590+ }
1591+ else if (firstLetter == 'n') {
1592+ isEG = false;
1593+ isAG = false;
1594+ return X;
1595+ }
1596+ else if (firstLetter == 'u') {
1597+ isEG = false;
1598+ isAG = false;
1599+ return U;
1600+ }
1601+ else {
1602+ #ifdef DEBUG
1603+ std::cout << "ERROR in setPathOperator: Invalid path operator: " << root_name << "\n";
1604+ #endif
1605+ }
1606+ return pError;
1607+}
1608+
1609+void CTLParser::printQuery(CTLTree *query) {
1610+ if(query->quantifier == EMPTY) {
1611+ Atom a = query->a;
1612+ if(a.isFireable){
1613+ std::cout<< " IsFireable(" << std::flush;
1614+ int i = 0;
1615+ for(i = 0; i < query->a.firesize; i++){
1616+ int j = 0;
1617+ for (j = 0; j < query->a.fireset[i].sizeofdenpencyplaces; j++){
1618+ std::cout<<"t_name_not_available" << std::flush;
1619+ if(j < (query->a.fireset[i].sizeofdenpencyplaces - 1))
1620+ std::cout << ", ";
1621+ }
1622+ }
1623+ std::cout << ")";
1624+ return;
1625+ }
1626+ else {
1627+ std::cout<< " Tokencount(" << std::flush;
1628+ if (a.cardinality.intSmaller == -1){
1629+ int i = 0;
1630+ for (i = 0; i < a.cardinality.placeSmaller.sizeoftokencount; i++){
1631+ std::cout<< a.cardinality.placeSmaller.cardinality[i]<<" ";
1632+ }
1633+ }
1634+ else
1635+ std::cout << a.cardinality.intSmaller;
1636+
1637+ std::cout<< " le " << std::flush;
1638+
1639+ if (a.cardinality.intLarger == -1) {
1640+ int i = 0;
1641+ for (i = 0; i < a.cardinality.placeLarger.sizeoftokencount; i++){
1642+ std::cout<< a.cardinality.placeLarger.cardinality[i]<<" ";
1643+ }
1644+ }
1645+ else
1646+ std::cout<< a.cardinality.intLarger;
1647+ std::cout << ")";
1648+ }
1649+ return;
1650+ }
1651+ else if (query->quantifier == NEG){
1652+ std::cout << "!("; printQuery(query->first) ;std::cout <<")" << std::flush;
1653+ }
1654+ else if (query->quantifier == AND){
1655+ std::cout << "(" ; printQuery(query->first);std::cout <<") AND ("; printQuery(query->second);std::cout<< ")" << std::flush;
1656+ }
1657+ else if (query->quantifier == OR){
1658+ std::cout << "("; printQuery(query->first);std::cout <<") OR ("; printQuery(query->second);std::cout << ")" << std::flush;
1659+ }
1660+ else if (query->quantifier == A){
1661+ std::cout << "A" << std::flush;
1662+ printPath(query);
1663+ }
1664+ else if ( query->quantifier == E){
1665+ std::cout << "E" << std::flush;
1666+ printPath(query);
1667+ }
1668+ else return;
1669+}
1670+
1671+void CTLParser::printPath(CTLTree *query) {
1672+ if (query->path == G)
1673+ std::cout << "G";
1674+ else if (query->path == F)
1675+ std::cout << "F";
1676+ else if (query->path == U)
1677+ {std::cout << "("; printQuery(query->first);std::cout <<") U ("; printQuery(query->second);std::cout << ")"; return;}
1678+ else if (query->path == X)
1679+ std::cout << "X";
1680+ printQuery(query->first);
1681+}
1682+
1683+bool CTLParser::charEmpty(char *query) {
1684+ if (query == NULL) {
1685+ return true;
1686+ }
1687+ return false;
1688+}
1689+
1690+void CTLParser::constructCardinalityAtom(CTLTree *query, xml_node<> *root){
1691+ xml_node<> * integerNode = root->first_node();
1692+ query->a.isFireable = false;
1693+ query->a.firesize = 0;
1694+
1695+ constructPreOperator(integerNode, query);
1696+
1697+ integerNode = integerNode->next_sibling();
1698+
1699+ constructPostOperator(integerNode, query);
1700+}
1701+
1702+void CTLParser::constructPreOperator(xml_node<> * integerNode, CTLTree *query){
1703+ if (integerNode->name()[0] == 't') {
1704+ int smallPlacecount = 0, numberofplaces = 0;
1705+ for (xml_node<> * place_node = integerNode->first_node(); place_node; place_node = place_node->next_sibling()) {
1706+ numberofplaces++;
1707+ }
1708+ //std::cout<<"Number of places: "<<numberofplaces<<std::flush;
1709+
1710+ query->a.cardinality.placeSmaller.cardinality = (int*) calloc(numberofplaces, sizeof(int));
1711+ query->a.cardinality.placeSmaller.sizeoftokencount = numberofplaces;
1712+
1713+ for (xml_node<> * place_node = integerNode->first_node(); place_node; place_node = place_node->next_sibling()) {
1714+ int p_index = 0;
1715+ for (p_index = 0; p_index < _net->numberOfPlaces(); p_index++){
1716+ if(strcmp(_net->placeNames()[p_index].c_str(),place_node->value()) == 0){
1717+ query->a.cardinality.placeSmaller.cardinality[smallPlacecount] = p_index;
1718+ smallPlacecount++;
1719+ break;
1720+ }
1721+ }
1722+ }
1723+ query->a.cardinality.intSmaller = -1;
1724+ // std::cout<< query->a.tokenCount.placeSmaller << " should be a smaller PLACE than ";
1725+ }
1726+ else if (integerNode->name()[0] == 'i') {
1727+ char *temp;
1728+ temp = integerNode->value();
1729+ query->a.cardinality.intSmaller = atoi(temp);
1730+ query->a.cardinality.placeSmaller.sizeoftokencount = 0;
1731+ //std::cout<< query->a.cardinality.intSmaller << " should be a smaller INTEGER-CONTANT than ";
1732+ }
1733+}
1734+
1735+void CTLParser::constructPostOperator(xml_node<> * integerNode, CTLTree *query){
1736+ if (integerNode->name()[0] == 't') {
1737+ int largePlacecount = 0, numberofplaces = 0;
1738+ for (xml_node<> * place_node = integerNode->first_node(); place_node; place_node = place_node->next_sibling()) {
1739+ numberofplaces++;
1740+ }
1741+ //std::cout<<"Number of places: "<<numberofplaces<<std::endl;
1742+ query->a.cardinality.placeLarger.cardinality = (int*) calloc(numberofplaces, sizeof(int));
1743+ query->a.cardinality.placeLarger.sizeoftokencount = numberofplaces;
1744+ for (xml_node<> * place_node = integerNode->first_node(); place_node; place_node = place_node->next_sibling()) {
1745+ int p_index = 0;
1746+ for (p_index = 0; p_index < _net->numberOfPlaces(); p_index++){
1747+ if(strcmp(_net->placeNames()[p_index].c_str(),place_node->first_node()->value()) == 0){
1748+ query->a.cardinality.placeLarger.cardinality[largePlacecount] = p_index;
1749+ largePlacecount++;
1750+ break;
1751+ }
1752+ }
1753+ }
1754+ query->a.cardinality.intLarger = -1;
1755+ }
1756+
1757+ else if (integerNode->name()[0] == 'i') {
1758+ char *temp;
1759+ temp = integerNode->value();
1760+ query->a.cardinality.intLarger = atoi(temp);
1761+ query->a.cardinality.placeLarger.sizeoftokencount = 0;
1762+ //std::cout<< query->a.cardinality.intLarger << " - witch is an INTEGER-CONTANT ";
1763+ }
1764+}
1765+
1766+void CTLParser::constructFireAtom(CTLTree *query, xml_node<> *root){
1767+ numberoftransitions = 0;
1768+ int i = 0, numberofdependencyplaces = 0;
1769+ query->a.isFireable = true;
1770+ //std::cout << "TEST:: Current set made" <<std::endl;
1771+ for (xml_node<> * transition_node = root->first_node(); transition_node; transition_node = transition_node->next_sibling()) {
1772+ numberoftransitions++;
1773+ }
1774+ //numberoftransitions++;
1775+ //std::cout << "TEST:: Number of transitions: "<<numberoftransitions <<std::endl;
1776+ query->a.firesize = numberoftransitions;
1777+ query->a.fireset = (Fireability*) calloc(numberoftransitions, sizeof(Fireability));
1778+
1779+
1780+ for (xml_node<> * transition_node = root->first_node(); transition_node; transition_node = transition_node->next_sibling()) {
1781+ int t_count = 0;
1782+ for (t_count = 0; t_count < _net->numberOfTransitions(); t_count++){
1783+ if (strcmp( _net->transitionNames()[t_count].c_str(), transition_node->value()) == 0){
1784+ numberofdependencyplaces = countNumberofDependencies(t_count);
1785+ query->a.fireset[i].denpencyplaces = (Dependency*) calloc(numberofdependencyplaces, sizeof(Dependency));
1786+ query->a.fireset[i].sizeofdenpencyplaces = numberofdependencyplaces;
1787+ }
1788+ }
1789+ for (t_count = 0; t_count < _net->numberOfTransitions(); t_count++){
1790+ if (strcmp( _net->transitionNames()[t_count].c_str(), transition_node->value()) == 0){
1791+ convertToCardinality(i, query, t_count);
1792+ }
1793+ }
1794+
1795+ i++;
1796+ }
1797+}
1798+
1799+void CTLParser::convertToCardinality(int i, CTLTree *query, int t_index){
1800+ int p_count = 0;
1801+ int dependent_count = 0;
1802+ for(p_count = 0; p_count < _net->numberOfPlaces(); p_count++){
1803+ int arc_weight = _net->inArc(p_count, t_index);
1804+ if (arc_weight > 0){
1805+ query->a.fireset[i].denpencyplaces[dependent_count].intSmaller = arc_weight;
1806+ query->a.fireset[i].denpencyplaces[dependent_count].placeLarger = p_count;
1807+ dependent_count++;
1808+ }
1809+ }
1810+}
1811+
1812+int CTLParser::countNumberofDependencies(int t_index){
1813+ //Returns how many places the transition is dependent on
1814+ int p_count = 0, res = 0;
1815+ for(p_count = 0; p_count < _net->numberOfPlaces(); p_count++){
1816+ int arc_weight = _net->inArc(p_count, t_index);
1817+ if (arc_weight > 0){
1818+ res++;
1819+ }
1820+ }
1821+ return res;
1822+}
1823+
1824+void CTLParser::createAGquery(xml_node<> * root, CTLTree *query){
1825+ //Function for converting AG to !EF!
1826+ CTLTree *query1 = (CTLTree*)malloc(sizeof(CTLTree));
1827+ CTLTree *query2 = (CTLTree*)malloc(sizeof(CTLTree));
1828+
1829+ //Set the first operator to neg
1830+ query->quantifier = NEG;
1831+ query->a.fireset = NULL;
1832+ query->first = query1;
1833+
1834+ //Set the second operator to EF
1835+ query1->quantifier = E;
1836+ query1->path = F;
1837+ query1->a.fireset = NULL;
1838+ query1->first = query2;
1839+
1840+ ////Set the third operator to neg
1841+ query2->quantifier = NEG;
1842+ query2->a.fireset = NULL;
1843+
1844+ //Recursively find successor query
1845+ query2->first = xmlToCTLquery(root->first_node()->first_node());
1846+
1847+ //Update depth information
1848+ isAG = false;
1849+ query2->max_depth = (query2->first->max_depth + 1);
1850+ query2->depth = (query2->first->depth + 1);
1851+ query1->depth = (query2->depth + 1);
1852+ query1->max_depth = (query2->max_depth + 1);
1853+ query->depth = (query1->depth + 1);
1854+ query->max_depth = (query1->max_depth + 1);
1855+}
1856+
1857+void CTLParser::createEGquery(xml_node<> * root, CTLTree *query){
1858+ //Function for converting EG to !AF!
1859+ CTLTree *query1 = (CTLTree*)malloc(sizeof(CTLTree));
1860+ CTLTree *query2 = (CTLTree*)malloc(sizeof(CTLTree));
1861+
1862+ //Set the first operator to neg
1863+ query->quantifier = NEG;
1864+ query->a.fireset = NULL;
1865+ query->first = query1;
1866+
1867+ //Set the second operator to AF
1868+ query1->quantifier = A;
1869+ query1->path = F;
1870+ query1->a.fireset = NULL;
1871+ query1->first = query2;
1872+
1873+ ////Set the third operator to neg
1874+ query2->quantifier = NEG;
1875+ query2->a.fireset = NULL;
1876+
1877+ //Recursively find successor query
1878+ query2->first = xmlToCTLquery(root->first_node()->first_node());
1879+
1880+ //Update depth information
1881+ isEG = false;
1882+ query2->depth = (query2->first->depth + 1);
1883+ query2->max_depth = (query2->first->max_depth + 1);
1884+ query1->depth = (query2->depth + 1);
1885+ query1->max_depth = (query2->max_depth + 1);
1886+ query->depth = (query1->depth + 1);
1887+ query->max_depth = (query1->max_depth + 1);
1888+}
1889+
1890+unsigned int CTLParser::lowerDepth(unsigned int a, unsigned int b){
1891+ if (a < b)
1892+ return a;
1893+ else if (a == b)
1894+ return a;
1895+ else return b;
1896+}
1897+
1898+unsigned int CTLParser::higherDepth(unsigned int a, unsigned int b){
1899+ if (b > a)
1900+ return b;
1901+ else if (a == b)
1902+ return b;
1903+ else return a;
1904+}
1905+
1906+//Test functions
1907+void CTLParser::RunParserTest(){
1908+ CTLFormula *queryList[12];
1909+ std::string querypath = "testFramework/unitTestResources/TEST_CTLFireabilitySimple.xml";
1910+ //"testFramework/unitTestResources/TEST_CTLFireabilitySimple.xml";
1911+ const char* queryfile = querypath.c_str();
1912+ std::ifstream xmlfile (queryfile);
1913+ std::vector<char> buffer((std::istreambuf_iterator<char>(xmlfile)), std::istreambuf_iterator<char>());
1914+ buffer.push_back('\0');
1915+
1916+
1917+ //Test 1 - charEmpty
1918+ char* test1input = NULL;
1919+ bool resTest1 = charEmpty(test1input);
1920+ assert(resTest1 == true);
1921+
1922+
1923+ //Test 2 - Correct queries
1924+ ParseXMLQuery(buffer, queryList);
1925+ //Confirm AF becomes AF
1926+ assert(queryList[0]->Query->quantifier == A);
1927+ assert(queryList[0]->Query->path == F);
1928+ //Confirm EF becomes EF
1929+ assert(queryList[1]->Query->quantifier == E);
1930+ assert(queryList[1]->Query->path == F);
1931+ //Confirm AG becomes !EF!()
1932+ assert(queryList[2]->Query->quantifier == NEG);
1933+ assert(queryList[2]->Query->first->quantifier == E);
1934+ assert(queryList[2]->Query->first->path == F);
1935+ assert(queryList[2]->Query->first->first->quantifier == NEG);
1936+ //Confirm EG becomes !AF!()
1937+ assert(queryList[3]->Query->quantifier == NEG);
1938+ assert(queryList[3]->Query->first->quantifier == A);
1939+ assert(queryList[3]->Query->first->path == F);
1940+ assert(queryList[3]->Query->first->first->quantifier == NEG);
1941+ //Confirm AU becomes AU
1942+ assert(queryList[4]->Query->quantifier == A);
1943+ assert(queryList[4]->Query->path == U);
1944+ //Confirm EU becomes EU
1945+ assert(queryList[5]->Query->quantifier == E);
1946+ assert(queryList[5]->Query->path == U);
1947+ //Confirm AX becomes AX
1948+ assert(queryList[6]->Query->quantifier == A);
1949+ assert(queryList[6]->Query->path == X);
1950+ //Confirm EX becomes EX
1951+ assert(queryList[7]->Query->quantifier == E);
1952+ assert(queryList[7]->Query->path == X);
1953+ //Confirm Houseconstructions
1954+ int i = 0;
1955+
1956+ std::cout<<"::::::::::::::::::::::::::::::::\n:::::::: Parse Test End ::::::::\n::::::::::::::::::::::::::::::::\n"<<std::endl;
1957+
1958+}
1959
1960=== added file 'CTLParser/CTLParser.h'
1961--- CTLParser/CTLParser.h 1970-01-01 00:00:00 +0000
1962+++ CTLParser/CTLParser.h 2016-03-31 07:42:46 +0000
1963@@ -0,0 +1,126 @@
1964+/*
1965+ * File: CTLParser.h
1966+ * Author: moss
1967+ *
1968+ * Created on September 30, 2015, 10:39 AM
1969+ */
1970+
1971+#ifndef CTLPARSER_H
1972+#define CTLPARSER_H
1973+
1974+#include "rapidxml-1.13/rapidxml.hpp"
1975+#include <vector>
1976+#include <string>
1977+#include <iostream>
1978+#include "../PetriEngine/PetriNet.h"
1979+
1980+enum Quantifier { AND = 1, OR = 2, A = 3, E = 4, NEG = 5, EMPTY = -1 };
1981+enum Path { G = 1, X = 2, F = 3, U = 4, pError = -1 };
1982+
1983+struct TokenCount{
1984+ int sizeoftokencount;
1985+ int* cardinality;
1986+};
1987+
1988+struct Cardinality {
1989+ int intSmaller;
1990+ TokenCount placeSmaller;
1991+ int intLarger;
1992+ TokenCount placeLarger;
1993+};
1994+
1995+struct Dependency{
1996+ int intSmaller;
1997+ int placeSmaller;
1998+ int intLarger;
1999+ int placeLarger;
2000+};
2001+
2002+struct Fireability{
2003+ int sizeofdenpencyplaces;
2004+ Dependency* denpencyplaces;
2005+};
2006+
2007+struct Atom {
2008+ bool isFireable;
2009+ int firesize;
2010+ Fireability* fireset;
2011+ Cardinality cardinality;
2012+};
2013+
2014+struct CTLTree {
2015+ Quantifier quantifier;
2016+ Path path;
2017+ CTLTree *first;
2018+ CTLTree *second;
2019+ Atom a;
2020+ unsigned int depth;
2021+ unsigned int max_depth;
2022+} ;
2023+
2024+struct CTLFormula {
2025+ char* Name;
2026+ bool Result;
2027+ std::vector<std::string>* Techniques;
2028+ CTLTree* Query;
2029+
2030+ std::string boolToString(){
2031+ if(Result)
2032+ return " TRUE ";
2033+ else if (!Result)
2034+ return " FALSE ";
2035+ else
2036+ return " ERROR ";
2037+ }
2038+
2039+ //MCC2015 result printer
2040+ void pResult(){
2041+ std::cout << "FORMULA "
2042+ << Name
2043+ << boolToString()
2044+ << "TECHNIQUES SEQUENTIAL_PROCESSING EXPLICIT";
2045+
2046+ for(std::vector<std::string>::const_iterator iter = Techniques->begin();
2047+ iter != Techniques->end();
2048+ iter++ )
2049+ {
2050+ std::cout << *iter << " ";
2051+ }
2052+ std::cout << std::endl;
2053+ }
2054+};
2055+
2056+class CTLParser {
2057+public:
2058+ CTLParser();
2059+ CTLParser(PetriEngine::PetriNet* net);
2060+ CTLParser(const CTLParser& orig);
2061+ virtual ~CTLParser();
2062+ void ParseXMLQuery(std::vector<char> buffer, CTLFormula **queryList);
2063+ void printQuery(CTLTree *query);
2064+ void RunParserTest();
2065+private:
2066+ PetriEngine::PetriNet* _net;
2067+ bool isAG = false;
2068+ bool isEG = false;
2069+ int numberoftransitions;
2070+ unsigned int lowerDepth(unsigned int a, unsigned int b);
2071+ unsigned int higherDepth(unsigned int a, unsigned int b);
2072+ CTLTree* xmlToCTLquery(rapidxml::xml_node<> * root);
2073+ Path setPathOperator(rapidxml::xml_node<> * root, bool isA, bool isE);
2074+ void createAGquery(rapidxml::xml_node<> * root, CTLTree *query);
2075+ void createEGquery(rapidxml::xml_node<> * root, CTLTree *query);
2076+ void constructFireAtom(CTLTree *query, rapidxml::xml_node<> *root);
2077+ void constructCardinalityAtom(CTLTree *query, rapidxml::xml_node<> *root);
2078+ int countNumberofDependencies(int t_index);
2079+ void convertToCardinality(int i, CTLTree *query, int t_index);
2080+ void constructPreOperator(rapidxml::xml_node<> * integerNode, CTLTree *query);
2081+ void constructPostOperator(rapidxml::xml_node<> * integerNode, CTLTree *query);
2082+
2083+ bool charEmpty(char *query);
2084+ void printPath(CTLTree *query);
2085+
2086+};
2087+
2088+#endif /* CTLPARSER_H */
2089+
2090
2091=== added directory 'CTLParser/rapidxml-1.13'
2092=== added file 'CTLParser/rapidxml-1.13/license.txt'
2093--- CTLParser/rapidxml-1.13/license.txt 1970-01-01 00:00:00 +0000
2094+++ CTLParser/rapidxml-1.13/license.txt 2016-03-31 07:42:46 +0000
2095@@ -0,0 +1,52 @@
2096+Use of this software is granted under one of the following two licenses,
2097+to be chosen freely by the user.
2098+
2099+1. Boost Software License - Version 1.0 - August 17th, 2003
2100+===============================================================================
2101+
2102+Copyright (c) 2006, 2007 Marcin Kalicinski
2103+
2104+Permission is hereby granted, free of charge, to any person or organization
2105+obtaining a copy of the software and accompanying documentation covered by
2106+this license (the "Software") to use, reproduce, display, distribute,
2107+execute, and transmit the Software, and to prepare derivative works of the
2108+Software, and to permit third-parties to whom the Software is furnished to
2109+do so, all subject to the following:
2110+
2111+The copyright notices in the Software and this entire statement, including
2112+the above license grant, this restriction and the following disclaimer,
2113+must be included in all copies of the Software, in whole or in part, and
2114+all derivative works of the Software, unless such copies or derivative
2115+works are solely in the form of machine-executable object code generated by
2116+a source language processor.
2117+
2118+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2119+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2120+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
2121+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
2122+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
2123+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2124+DEALINGS IN THE SOFTWARE.
2125+
2126+2. The MIT License
2127+===============================================================================
2128+
2129+Copyright (c) 2006, 2007 Marcin Kalicinski
2130+
2131+Permission is hereby granted, free of charge, to any person obtaining a copy
2132+of this software and associated documentation files (the "Software"), to deal
2133+in the Software without restriction, including without limitation the rights
2134+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
2135+of the Software, and to permit persons to whom the Software is furnished to do so,
2136+subject to the following conditions:
2137+
2138+The above copyright notice and this permission notice shall be included in all
2139+copies or substantial portions of the Software.
2140+
2141+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2142+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2143+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2144+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2145+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2146+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2147+IN THE SOFTWARE.
2148
2149=== added file 'CTLParser/rapidxml-1.13/rapidxml.hpp'
2150--- CTLParser/rapidxml-1.13/rapidxml.hpp 1970-01-01 00:00:00 +0000
2151+++ CTLParser/rapidxml-1.13/rapidxml.hpp 2016-03-31 07:42:46 +0000
2152@@ -0,0 +1,2596 @@
2153+#ifndef RAPIDXML_HPP_INCLUDED
2154+#define RAPIDXML_HPP_INCLUDED
2155+
2156+// Copyright (C) 2006, 2009 Marcin Kalicinski
2157+// Version 1.13
2158+// Revision $DateTime: 2009/05/13 01:46:17 $
2159+//! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation
2160+
2161+// If standard library is disabled, user must provide implementations of required functions and typedefs
2162+#if !defined(RAPIDXML_NO_STDLIB)
2163+ #include <cstdlib> // For std::size_t
2164+ #include <cassert> // For assert
2165+ #include <new> // For placement new
2166+#endif
2167+
2168+// On MSVC, disable "conditional expression is constant" warning (level 4).
2169+// This warning is almost impossible to avoid with certain types of templated code
2170+#ifdef _MSC_VER
2171+ #pragma warning(push)
2172+ #pragma warning(disable:4127) // Conditional expression is constant
2173+#endif
2174+
2175+///////////////////////////////////////////////////////////////////////////
2176+// RAPIDXML_PARSE_ERROR
2177+
2178+#if defined(RAPIDXML_NO_EXCEPTIONS)
2179+
2180+#define RAPIDXML_PARSE_ERROR(what, where) { parse_error_handler(what, where); assert(0); }
2181+
2182+namespace rapidxml
2183+{
2184+ //! When exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS,
2185+ //! this function is called to notify user about the error.
2186+ //! It must be defined by the user.
2187+ //! <br><br>
2188+ //! This function cannot return. If it does, the results are undefined.
2189+ //! <br><br>
2190+ //! A very simple definition might look like that:
2191+ //! <pre>
2192+ //! void %rapidxml::%parse_error_handler(const char *what, void *where)
2193+ //! {
2194+ //! std::cout << "Parse error: " << what << "\n";
2195+ //! std::abort();
2196+ //! }
2197+ //! </pre>
2198+ //! \param what Human readable description of the error.
2199+ //! \param where Pointer to character data where error was detected.
2200+ void parse_error_handler(const char *what, void *where);
2201+}
2202+
2203+#else
2204+
2205+#include <exception> // For std::exception
2206+
2207+#define RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where)
2208+
2209+namespace rapidxml
2210+{
2211+
2212+ //! Parse error exception.
2213+ //! This exception is thrown by the parser when an error occurs.
2214+ //! Use what() function to get human-readable error message.
2215+ //! Use where() function to get a pointer to position within source text where error was detected.
2216+ //! <br><br>
2217+ //! If throwing exceptions by the parser is undesirable,
2218+ //! it can be disabled by defining RAPIDXML_NO_EXCEPTIONS macro before rapidxml.hpp is included.
2219+ //! This will cause the parser to call rapidxml::parse_error_handler() function instead of throwing an exception.
2220+ //! This function must be defined by the user.
2221+ //! <br><br>
2222+ //! This class derives from <code>std::exception</code> class.
2223+ class parse_error: public std::exception
2224+ {
2225+
2226+ public:
2227+
2228+ //! Constructs parse error
2229+ parse_error(const char *what, void *where)
2230+ : m_what(what)
2231+ , m_where(where)
2232+ {
2233+ }
2234+
2235+ //! Gets human readable description of error.
2236+ //! \return Pointer to null terminated description of the error.
2237+ virtual const char *what() const throw()
2238+ {
2239+ return m_what;
2240+ }
2241+
2242+ //! Gets pointer to character data where error happened.
2243+ //! Ch should be the same as char type of xml_document that produced the error.
2244+ //! \return Pointer to location within the parsed string where error occured.
2245+ template<class Ch>
2246+ Ch *where() const
2247+ {
2248+ return reinterpret_cast<Ch *>(m_where);
2249+ }
2250+
2251+ private:
2252+
2253+ const char *m_what;
2254+ void *m_where;
2255+
2256+ };
2257+}
2258+
2259+#endif
2260+
2261+///////////////////////////////////////////////////////////////////////////
2262+// Pool sizes
2263+
2264+#ifndef RAPIDXML_STATIC_POOL_SIZE
2265+ // Size of static memory block of memory_pool.
2266+ // Define RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
2267+ // No dynamic memory allocations are performed by memory_pool until static memory is exhausted.
2268+ #define RAPIDXML_STATIC_POOL_SIZE (64 * 1024)
2269+#endif
2270+
2271+#ifndef RAPIDXML_DYNAMIC_POOL_SIZE
2272+ // Size of dynamic memory block of memory_pool.
2273+ // Define RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
2274+ // After the static block is exhausted, dynamic blocks with approximately this size are allocated by memory_pool.
2275+ #define RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024)
2276+#endif
2277+
2278+#ifndef RAPIDXML_ALIGNMENT
2279+ // Memory allocation alignment.
2280+ // Define RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer.
2281+ // All memory allocations for nodes, attributes and strings will be aligned to this value.
2282+ // This must be a power of 2 and at least 1, otherwise memory_pool will not work.
2283+ #define RAPIDXML_ALIGNMENT sizeof(void *)
2284+#endif
2285+
2286+namespace rapidxml
2287+{
2288+ // Forward declarations
2289+ template<class Ch> class xml_node;
2290+ template<class Ch> class xml_attribute;
2291+ template<class Ch> class xml_document;
2292+
2293+ //! Enumeration listing all node types produced by the parser.
2294+ //! Use xml_node::type() function to query node type.
2295+ enum node_type
2296+ {
2297+ node_document, //!< A document node. Name and value are empty.
2298+ node_element, //!< An element node. Name contains element name. Value contains text of first data node.
2299+ node_data, //!< A data node. Name is empty. Value contains data text.
2300+ node_cdata, //!< A CDATA node. Name is empty. Value contains data text.
2301+ node_comment, //!< A comment node. Name is empty. Value contains comment text.
2302+ node_declaration, //!< A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes.
2303+ node_doctype, //!< A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
2304+ node_pi //!< A PI node. Name contains target. Value contains instructions.
2305+ };
2306+
2307+ ///////////////////////////////////////////////////////////////////////
2308+ // Parsing flags
2309+
2310+ //! Parse flag instructing the parser to not create data nodes.
2311+ //! Text of first data node will still be placed in value of parent element, unless rapidxml::parse_no_element_values flag is also specified.
2312+ //! Can be combined with other flags by use of | operator.
2313+ //! <br><br>
2314+ //! See xml_document::parse() function.
2315+ const int parse_no_data_nodes = 0x1;
2316+
2317+ //! Parse flag instructing the parser to not use text of first data node as a value of parent element.
2318+ //! Can be combined with other flags by use of | operator.
2319+ //! Note that child data nodes of element node take precendence over its value when printing.
2320+ //! That is, if element has one or more child data nodes <em>and</em> a value, the value will be ignored.
2321+ //! Use rapidxml::parse_no_data_nodes flag to prevent creation of data nodes if you want to manipulate data using values of elements.
2322+ //! <br><br>
2323+ //! See xml_document::parse() function.
2324+ const int parse_no_element_values = 0x2;
2325+
2326+ //! Parse flag instructing the parser to not place zero terminators after strings in the source text.
2327+ //! By default zero terminators are placed, modifying source text.
2328+ //! Can be combined with other flags by use of | operator.
2329+ //! <br><br>
2330+ //! See xml_document::parse() function.
2331+ const int parse_no_string_terminators = 0x4;
2332+
2333+ //! Parse flag instructing the parser to not translate entities in the source text.
2334+ //! By default entities are translated, modifying source text.
2335+ //! Can be combined with other flags by use of | operator.
2336+ //! <br><br>
2337+ //! See xml_document::parse() function.
2338+ const int parse_no_entity_translation = 0x8;
2339+
2340+ //! Parse flag instructing the parser to disable UTF-8 handling and assume plain 8 bit characters.
2341+ //! By default, UTF-8 handling is enabled.
2342+ //! Can be combined with other flags by use of | operator.
2343+ //! <br><br>
2344+ //! See xml_document::parse() function.
2345+ const int parse_no_utf8 = 0x10;
2346+
2347+ //! Parse flag instructing the parser to create XML declaration node.
2348+ //! By default, declaration node is not created.
2349+ //! Can be combined with other flags by use of | operator.
2350+ //! <br><br>
2351+ //! See xml_document::parse() function.
2352+ const int parse_declaration_node = 0x20;
2353+
2354+ //! Parse flag instructing the parser to create comments nodes.
2355+ //! By default, comment nodes are not created.
2356+ //! Can be combined with other flags by use of | operator.
2357+ //! <br><br>
2358+ //! See xml_document::parse() function.
2359+ const int parse_comment_nodes = 0x40;
2360+
2361+ //! Parse flag instructing the parser to create DOCTYPE node.
2362+ //! By default, doctype node is not created.
2363+ //! Although W3C specification allows at most one DOCTYPE node, RapidXml will silently accept documents with more than one.
2364+ //! Can be combined with other flags by use of | operator.
2365+ //! <br><br>
2366+ //! See xml_document::parse() function.
2367+ const int parse_doctype_node = 0x80;
2368+
2369+ //! Parse flag instructing the parser to create PI nodes.
2370+ //! By default, PI nodes are not created.
2371+ //! Can be combined with other flags by use of | operator.
2372+ //! <br><br>
2373+ //! See xml_document::parse() function.
2374+ const int parse_pi_nodes = 0x100;
2375+
2376+ //! Parse flag instructing the parser to validate closing tag names.
2377+ //! If not set, name inside closing tag is irrelevant to the parser.
2378+ //! By default, closing tags are not validated.
2379+ //! Can be combined with other flags by use of | operator.
2380+ //! <br><br>
2381+ //! See xml_document::parse() function.
2382+ const int parse_validate_closing_tags = 0x200;
2383+
2384+ //! Parse flag instructing the parser to trim all leading and trailing whitespace of data nodes.
2385+ //! By default, whitespace is not trimmed.
2386+ //! This flag does not cause the parser to modify source text.
2387+ //! Can be combined with other flags by use of | operator.
2388+ //! <br><br>
2389+ //! See xml_document::parse() function.
2390+ const int parse_trim_whitespace = 0x400;
2391+
2392+ //! Parse flag instructing the parser to condense all whitespace runs of data nodes to a single space character.
2393+ //! Trimming of leading and trailing whitespace of data is controlled by rapidxml::parse_trim_whitespace flag.
2394+ //! By default, whitespace is not normalized.
2395+ //! If this flag is specified, source text will be modified.
2396+ //! Can be combined with other flags by use of | operator.
2397+ //! <br><br>
2398+ //! See xml_document::parse() function.
2399+ const int parse_normalize_whitespace = 0x800;
2400+
2401+ // Compound flags
2402+
2403+ //! Parse flags which represent default behaviour of the parser.
2404+ //! This is always equal to 0, so that all other flags can be simply ored together.
2405+ //! Normally there is no need to inconveniently disable flags by anding with their negated (~) values.
2406+ //! This also means that meaning of each flag is a <i>negation</i> of the default setting.
2407+ //! For example, if flag name is rapidxml::parse_no_utf8, it means that utf-8 is <i>enabled</i> by default,
2408+ //! and using the flag will disable it.
2409+ //! <br><br>
2410+ //! See xml_document::parse() function.
2411+ const int parse_default = 0;
2412+
2413+ //! A combination of parse flags that forbids any modifications of the source text.
2414+ //! This also results in faster parsing. However, note that the following will occur:
2415+ //! <ul>
2416+ //! <li>names and values of nodes will not be zero terminated, you have to use xml_base::name_size() and xml_base::value_size() functions to determine where name and value ends</li>
2417+ //! <li>entities will not be translated</li>
2418+ //! <li>whitespace will not be normalized</li>
2419+ //! </ul>
2420+ //! See xml_document::parse() function.
2421+ const int parse_non_destructive = parse_no_string_terminators | parse_no_entity_translation;
2422+
2423+ //! A combination of parse flags resulting in fastest possible parsing, without sacrificing important data.
2424+ //! <br><br>
2425+ //! See xml_document::parse() function.
2426+ const int parse_fastest = parse_non_destructive | parse_no_data_nodes;
2427+
2428+ //! A combination of parse flags resulting in largest amount of data being extracted.
2429+ //! This usually results in slowest parsing.
2430+ //! <br><br>
2431+ //! See xml_document::parse() function.
2432+ const int parse_full = parse_declaration_node | parse_comment_nodes | parse_doctype_node | parse_pi_nodes | parse_validate_closing_tags;
2433+
2434+ ///////////////////////////////////////////////////////////////////////
2435+ // Internals
2436+
2437+ //! \cond internal
2438+ namespace internal
2439+ {
2440+
2441+ // Struct that contains lookup tables for the parser
2442+ // It must be a template to allow correct linking (because it has static data members, which are defined in a header file).
2443+ template<int Dummy>
2444+ struct lookup_tables
2445+ {
2446+ static const unsigned char lookup_whitespace[256]; // Whitespace table
2447+ static const unsigned char lookup_node_name[256]; // Node name table
2448+ static const unsigned char lookup_text[256]; // Text table
2449+ static const unsigned char lookup_text_pure_no_ws[256]; // Text table
2450+ static const unsigned char lookup_text_pure_with_ws[256]; // Text table
2451+ static const unsigned char lookup_attribute_name[256]; // Attribute name table
2452+ static const unsigned char lookup_attribute_data_1[256]; // Attribute data table with single quote
2453+ static const unsigned char lookup_attribute_data_1_pure[256]; // Attribute data table with single quote
2454+ static const unsigned char lookup_attribute_data_2[256]; // Attribute data table with double quotes
2455+ static const unsigned char lookup_attribute_data_2_pure[256]; // Attribute data table with double quotes
2456+ static const unsigned char lookup_digits[256]; // Digits
2457+ static const unsigned char lookup_upcase[256]; // To uppercase conversion table for ASCII characters
2458+ };
2459+
2460+ // Find length of the string
2461+ template<class Ch>
2462+ inline std::size_t measure(const Ch *p)
2463+ {
2464+ const Ch *tmp = p;
2465+ while (*tmp)
2466+ ++tmp;
2467+ return tmp - p;
2468+ }
2469+
2470+ // Compare strings for equality
2471+ template<class Ch>
2472+ inline bool compare(const Ch *p1, std::size_t size1, const Ch *p2, std::size_t size2, bool case_sensitive)
2473+ {
2474+ if (size1 != size2)
2475+ return false;
2476+ if (case_sensitive)
2477+ {
2478+ for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
2479+ if (*p1 != *p2)
2480+ return false;
2481+ }
2482+ else
2483+ {
2484+ for (const Ch *end = p1 + size1; p1 < end; ++p1, ++p2)
2485+ if (lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p1)] != lookup_tables<0>::lookup_upcase[static_cast<unsigned char>(*p2)])
2486+ return false;
2487+ }
2488+ return true;
2489+ }
2490+ }
2491+ //! \endcond
2492+
2493+ ///////////////////////////////////////////////////////////////////////
2494+ // Memory pool
2495+
2496+ //! This class is used by the parser to create new nodes and attributes, without overheads of dynamic memory allocation.
2497+ //! In most cases, you will not need to use this class directly.
2498+ //! However, if you need to create nodes manually or modify names/values of nodes,
2499+ //! you are encouraged to use memory_pool of relevant xml_document to allocate the memory.
2500+ //! Not only is this faster than allocating them by using <code>new</code> operator,
2501+ //! but also their lifetime will be tied to the lifetime of document,
2502+ //! possibly simplyfing memory management.
2503+ //! <br><br>
2504+ //! Call allocate_node() or allocate_attribute() functions to obtain new nodes or attributes from the pool.
2505+ //! You can also call allocate_string() function to allocate strings.
2506+ //! Such strings can then be used as names or values of nodes without worrying about their lifetime.
2507+ //! Note that there is no <code>free()</code> function -- all allocations are freed at once when clear() function is called,
2508+ //! or when the pool is destroyed.
2509+ //! <br><br>
2510+ //! It is also possible to create a standalone memory_pool, and use it
2511+ //! to allocate nodes, whose lifetime will not be tied to any document.
2512+ //! <br><br>
2513+ //! Pool maintains <code>RAPIDXML_STATIC_POOL_SIZE</code> bytes of statically allocated memory.
2514+ //! Until static memory is exhausted, no dynamic memory allocations are done.
2515+ //! When static memory is exhausted, pool allocates additional blocks of memory of size <code>RAPIDXML_DYNAMIC_POOL_SIZE</code> each,
2516+ //! by using global <code>new[]</code> and <code>delete[]</code> operators.
2517+ //! This behaviour can be changed by setting custom allocation routines.
2518+ //! Use set_allocator() function to set them.
2519+ //! <br><br>
2520+ //! Allocations for nodes, attributes and strings are aligned at <code>RAPIDXML_ALIGNMENT</code> bytes.
2521+ //! This value defaults to the size of pointer on target architecture.
2522+ //! <br><br>
2523+ //! To obtain absolutely top performance from the parser,
2524+ //! it is important that all nodes are allocated from a single, contiguous block of memory.
2525+ //! Otherwise, cache misses when jumping between two (or more) disjoint blocks of memory can slow down parsing quite considerably.
2526+ //! If required, you can tweak <code>RAPIDXML_STATIC_POOL_SIZE</code>, <code>RAPIDXML_DYNAMIC_POOL_SIZE</code> and <code>RAPIDXML_ALIGNMENT</code>
2527+ //! to obtain best wasted memory to performance compromise.
2528+ //! To do it, define their values before rapidxml.hpp file is included.
2529+ //! \param Ch Character type of created nodes.
2530+ template<class Ch = char>
2531+ class memory_pool
2532+ {
2533+
2534+ public:
2535+
2536+ //! \cond internal
2537+ typedef void *(alloc_func)(std::size_t); // Type of user-defined function used to allocate memory
2538+ typedef void (free_func)(void *); // Type of user-defined function used to free memory
2539+ //! \endcond
2540+
2541+ //! Constructs empty pool with default allocator functions.
2542+ memory_pool()
2543+ : m_alloc_func(0)
2544+ , m_free_func(0)
2545+ {
2546+ init();
2547+ }
2548+
2549+ //! Destroys pool and frees all the memory.
2550+ //! This causes memory occupied by nodes allocated by the pool to be freed.
2551+ //! Nodes allocated from the pool are no longer valid.
2552+ ~memory_pool()
2553+ {
2554+ clear();
2555+ }
2556+
2557+ //! Allocates a new node from the pool, and optionally assigns name and value to it.
2558+ //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
2559+ //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
2560+ //! will call rapidxml::parse_error_handler() function.
2561+ //! \param type Type of node to create.
2562+ //! \param name Name to assign to the node, or 0 to assign no name.
2563+ //! \param value Value to assign to the node, or 0 to assign no value.
2564+ //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
2565+ //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
2566+ //! \return Pointer to allocated node. This pointer will never be NULL.
2567+ xml_node<Ch> *allocate_node(node_type type,
2568+ const Ch *name = 0, const Ch *value = 0,
2569+ std::size_t name_size = 0, std::size_t value_size = 0)
2570+ {
2571+ void *memory = allocate_aligned(sizeof(xml_node<Ch>));
2572+ xml_node<Ch> *node = new(memory) xml_node<Ch>(type);
2573+ if (name)
2574+ {
2575+ if (name_size > 0)
2576+ node->name(name, name_size);
2577+ else
2578+ node->name(name);
2579+ }
2580+ if (value)
2581+ {
2582+ if (value_size > 0)
2583+ node->value(value, value_size);
2584+ else
2585+ node->value(value);
2586+ }
2587+ return node;
2588+ }
2589+
2590+ //! Allocates a new attribute from the pool, and optionally assigns name and value to it.
2591+ //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
2592+ //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
2593+ //! will call rapidxml::parse_error_handler() function.
2594+ //! \param name Name to assign to the attribute, or 0 to assign no name.
2595+ //! \param value Value to assign to the attribute, or 0 to assign no value.
2596+ //! \param name_size Size of name to assign, or 0 to automatically calculate size from name string.
2597+ //! \param value_size Size of value to assign, or 0 to automatically calculate size from value string.
2598+ //! \return Pointer to allocated attribute. This pointer will never be NULL.
2599+ xml_attribute<Ch> *allocate_attribute(const Ch *name = 0, const Ch *value = 0,
2600+ std::size_t name_size = 0, std::size_t value_size = 0)
2601+ {
2602+ void *memory = allocate_aligned(sizeof(xml_attribute<Ch>));
2603+ xml_attribute<Ch> *attribute = new(memory) xml_attribute<Ch>;
2604+ if (name)
2605+ {
2606+ if (name_size > 0)
2607+ attribute->name(name, name_size);
2608+ else
2609+ attribute->name(name);
2610+ }
2611+ if (value)
2612+ {
2613+ if (value_size > 0)
2614+ attribute->value(value, value_size);
2615+ else
2616+ attribute->value(value);
2617+ }
2618+ return attribute;
2619+ }
2620+
2621+ //! Allocates a char array of given size from the pool, and optionally copies a given string to it.
2622+ //! If the allocation request cannot be accomodated, this function will throw <code>std::bad_alloc</code>.
2623+ //! If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function
2624+ //! will call rapidxml::parse_error_handler() function.
2625+ //! \param source String to initialize the allocated memory with, or 0 to not initialize it.
2626+ //! \param size Number of characters to allocate, or zero to calculate it automatically from source string length; if size is 0, source string must be specified and null terminated.
2627+ //! \return Pointer to allocated char array. This pointer will never be NULL.
2628+ Ch *allocate_string(const Ch *source = 0, std::size_t size = 0)
2629+ {
2630+ assert(source || size); // Either source or size (or both) must be specified
2631+ if (size == 0)
2632+ size = internal::measure(source) + 1;
2633+ Ch *result = static_cast<Ch *>(allocate_aligned(size * sizeof(Ch)));
2634+ if (source)
2635+ for (std::size_t i = 0; i < size; ++i)
2636+ result[i] = source[i];
2637+ return result;
2638+ }
2639+
2640+ //! Clones an xml_node and its hierarchy of child nodes and attributes.
2641+ //! Nodes and attributes are allocated from this memory pool.
2642+ //! Names and values are not cloned, they are shared between the clone and the source.
2643+ //! Result node can be optionally specified as a second parameter,
2644+ //! in which case its contents will be replaced with cloned source node.
2645+ //! This is useful when you want to clone entire document.
2646+ //! \param source Node to clone.
2647+ //! \param result Node to put results in, or 0 to automatically allocate result node
2648+ //! \return Pointer to cloned node. This pointer will never be NULL.
2649+ xml_node<Ch> *clone_node(const xml_node<Ch> *source, xml_node<Ch> *result = 0)
2650+ {
2651+ // Prepare result node
2652+ if (result)
2653+ {
2654+ result->remove_all_attributes();
2655+ result->remove_all_nodes();
2656+ result->type(source->type());
2657+ }
2658+ else
2659+ result = allocate_node(source->type());
2660+
2661+ // Clone name and value
2662+ result->name(source->name(), source->name_size());
2663+ result->value(source->value(), source->value_size());
2664+
2665+ // Clone child nodes and attributes
2666+ for (xml_node<Ch> *child = source->first_node(); child; child = child->next_sibling())
2667+ result->append_node(clone_node(child));
2668+ for (xml_attribute<Ch> *attr = source->first_attribute(); attr; attr = attr->next_attribute())
2669+ result->append_attribute(allocate_attribute(attr->name(), attr->value(), attr->name_size(), attr->value_size()));
2670+
2671+ return result;
2672+ }
2673+
2674+ //! Clears the pool.
2675+ //! This causes memory occupied by nodes allocated by the pool to be freed.
2676+ //! Any nodes or strings allocated from the pool will no longer be valid.
2677+ void clear()
2678+ {
2679+ while (m_begin != m_static_memory)
2680+ {
2681+ char *previous_begin = reinterpret_cast<header *>(align(m_begin))->previous_begin;
2682+ if (m_free_func)
2683+ m_free_func(m_begin);
2684+ else
2685+ delete[] m_begin;
2686+ m_begin = previous_begin;
2687+ }
2688+ init();
2689+ }
2690+
2691+ //! Sets or resets the user-defined memory allocation functions for the pool.
2692+ //! This can only be called when no memory is allocated from the pool yet, otherwise results are undefined.
2693+ //! Allocation function must not return invalid pointer on failure. It should either throw,
2694+ //! stop the program, or use <code>longjmp()</code> function to pass control to other place of program.
2695+ //! If it returns invalid pointer, results are undefined.
2696+ //! <br><br>
2697+ //! User defined allocation functions must have the following forms:
2698+ //! <br><code>
2699+ //! <br>void *allocate(std::size_t size);
2700+ //! <br>void free(void *pointer);
2701+ //! </code><br>
2702+ //! \param af Allocation function, or 0 to restore default function
2703+ //! \param ff Free function, or 0 to restore default function
2704+ void set_allocator(alloc_func *af, free_func *ff)
2705+ {
2706+ assert(m_begin == m_static_memory && m_ptr == align(m_begin)); // Verify that no memory is allocated yet
2707+ m_alloc_func = af;
2708+ m_free_func = ff;
2709+ }
2710+
2711+ private:
2712+
2713+ struct header
2714+ {
2715+ char *previous_begin;
2716+ };
2717+
2718+ void init()
2719+ {
2720+ m_begin = m_static_memory;
2721+ m_ptr = align(m_begin);
2722+ m_end = m_static_memory + sizeof(m_static_memory);
2723+ }
2724+
2725+ char *align(char *ptr)
2726+ {
2727+ std::size_t alignment = ((RAPIDXML_ALIGNMENT - (std::size_t(ptr) & (RAPIDXML_ALIGNMENT - 1))) & (RAPIDXML_ALIGNMENT - 1));
2728+ return ptr + alignment;
2729+ }
2730+
2731+ char *allocate_raw(std::size_t size)
2732+ {
2733+ // Allocate
2734+ void *memory;
2735+ if (m_alloc_func) // Allocate memory using either user-specified allocation function or global operator new[]
2736+ {
2737+ memory = m_alloc_func(size);
2738+ assert(memory); // Allocator is not allowed to return 0, on failure it must either throw, stop the program or use longjmp
2739+ }
2740+ else
2741+ {
2742+ memory = new char[size];
2743+#ifdef RAPIDXML_NO_EXCEPTIONS
2744+ if (!memory) // If exceptions are disabled, verify memory allocation, because new will not be able to throw bad_alloc
2745+ RAPIDXML_PARSE_ERROR("out of memory", 0);
2746+#endif
2747+ }
2748+ return static_cast<char *>(memory);
2749+ }
2750+
2751+ void *allocate_aligned(std::size_t size)
2752+ {
2753+ // Calculate aligned pointer
2754+ char *result = align(m_ptr);
2755+
2756+ // If not enough memory left in current pool, allocate a new pool
2757+ if (result + size > m_end)
2758+ {
2759+ // Calculate required pool size (may be bigger than RAPIDXML_DYNAMIC_POOL_SIZE)
2760+ std::size_t pool_size = RAPIDXML_DYNAMIC_POOL_SIZE;
2761+ if (pool_size < size)
2762+ pool_size = size;
2763+
2764+ // Allocate
2765+ std::size_t alloc_size = sizeof(header) + (2 * RAPIDXML_ALIGNMENT - 2) + pool_size; // 2 alignments required in worst case: one for header, one for actual allocation
2766+ char *raw_memory = allocate_raw(alloc_size);
2767+
2768+ // Setup new pool in allocated memory
2769+ char *pool = align(raw_memory);
2770+ header *new_header = reinterpret_cast<header *>(pool);
2771+ new_header->previous_begin = m_begin;
2772+ m_begin = raw_memory;
2773+ m_ptr = pool + sizeof(header);
2774+ m_end = raw_memory + alloc_size;
2775+
2776+ // Calculate aligned pointer again using new pool
2777+ result = align(m_ptr);
2778+ }
2779+
2780+ // Update pool and return aligned pointer
2781+ m_ptr = result + size;
2782+ return result;
2783+ }
2784+
2785+ char *m_begin; // Start of raw memory making up current pool
2786+ char *m_ptr; // First free byte in current pool
2787+ char *m_end; // One past last available byte in current pool
2788+ char m_static_memory[RAPIDXML_STATIC_POOL_SIZE]; // Static raw memory
2789+ alloc_func *m_alloc_func; // Allocator function, or 0 if default is to be used
2790+ free_func *m_free_func; // Free function, or 0 if default is to be used
2791+ };
2792+
2793+ ///////////////////////////////////////////////////////////////////////////
2794+ // XML base
2795+
2796+ //! Base class for xml_node and xml_attribute implementing common functions:
2797+ //! name(), name_size(), value(), value_size() and parent().
2798+ //! \param Ch Character type to use
2799+ template<class Ch = char>
2800+ class xml_base
2801+ {
2802+
2803+ public:
2804+
2805+ ///////////////////////////////////////////////////////////////////////////
2806+ // Construction & destruction
2807+
2808+ // Construct a base with empty name, value and parent
2809+ xml_base()
2810+ : m_name(0)
2811+ , m_value(0)
2812+ , m_parent(0)
2813+ {
2814+ }
2815+
2816+ ///////////////////////////////////////////////////////////////////////////
2817+ // Node data access
2818+
2819+ //! Gets name of the node.
2820+ //! Interpretation of name depends on type of node.
2821+ //! Note that name will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
2822+ //! <br><br>
2823+ //! Use name_size() function to determine length of the name.
2824+ //! \return Name of node, or empty string if node has no name.
2825+ Ch *name() const
2826+ {
2827+ return m_name ? m_name : nullstr();
2828+ }
2829+
2830+ //! Gets size of node name, not including terminator character.
2831+ //! This function works correctly irrespective of whether name is or is not zero terminated.
2832+ //! \return Size of node name, in characters.
2833+ std::size_t name_size() const
2834+ {
2835+ return m_name ? m_name_size : 0;
2836+ }
2837+
2838+ //! Gets value of node.
2839+ //! Interpretation of value depends on type of node.
2840+ //! Note that value will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.
2841+ //! <br><br>
2842+ //! Use value_size() function to determine length of the value.
2843+ //! \return Value of node, or empty string if node has no value.
2844+ Ch *value() const
2845+ {
2846+ return m_value ? m_value : nullstr();
2847+ }
2848+
2849+ //! Gets size of node value, not including terminator character.
2850+ //! This function works correctly irrespective of whether value is or is not zero terminated.
2851+ //! \return Size of node value, in characters.
2852+ std::size_t value_size() const
2853+ {
2854+ return m_value ? m_value_size : 0;
2855+ }
2856+
2857+ ///////////////////////////////////////////////////////////////////////////
2858+ // Node modification
2859+
2860+ //! Sets name of node to a non zero-terminated string.
2861+ //! See \ref ownership_of_strings.
2862+ //! <br><br>
2863+ //! Note that node does not own its name or value, it only stores a pointer to it.
2864+ //! It will not delete or otherwise free the pointer on destruction.
2865+ //! It is reponsibility of the user to properly manage lifetime of the string.
2866+ //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
2867+ //! on destruction of the document the string will be automatically freed.
2868+ //! <br><br>
2869+ //! Size of name must be specified separately, because name does not have to be zero terminated.
2870+ //! Use name(const Ch *) function to have the length automatically calculated (string must be zero terminated).
2871+ //! \param name Name of node to set. Does not have to be zero terminated.
2872+ //! \param size Size of name, in characters. This does not include zero terminator, if one is present.
2873+ void name(const Ch *name, std::size_t size)
2874+ {
2875+ m_name = const_cast<Ch *>(name);
2876+ m_name_size = size;
2877+ }
2878+
2879+ //! Sets name of node to a zero-terminated string.
2880+ //! See also \ref ownership_of_strings and xml_node::name(const Ch *, std::size_t).
2881+ //! \param name Name of node to set. Must be zero terminated.
2882+ void name(const Ch *name)
2883+ {
2884+ this->name(name, internal::measure(name));
2885+ }
2886+
2887+ //! Sets value of node to a non zero-terminated string.
2888+ //! See \ref ownership_of_strings.
2889+ //! <br><br>
2890+ //! Note that node does not own its name or value, it only stores a pointer to it.
2891+ //! It will not delete or otherwise free the pointer on destruction.
2892+ //! It is reponsibility of the user to properly manage lifetime of the string.
2893+ //! The easiest way to achieve it is to use memory_pool of the document to allocate the string -
2894+ //! on destruction of the document the string will be automatically freed.
2895+ //! <br><br>
2896+ //! Size of value must be specified separately, because it does not have to be zero terminated.
2897+ //! Use value(const Ch *) function to have the length automatically calculated (string must be zero terminated).
2898+ //! <br><br>
2899+ //! If an element has a child node of type node_data, it will take precedence over element value when printing.
2900+ //! If you want to manipulate data of elements using values, use parser flag rapidxml::parse_no_data_nodes to prevent creation of data nodes by the parser.
2901+ //! \param value value of node to set. Does not have to be zero terminated.
2902+ //! \param size Size of value, in characters. This does not include zero terminator, if one is present.
2903+ void value(const Ch *value, std::size_t size)
2904+ {
2905+ m_value = const_cast<Ch *>(value);
2906+ m_value_size = size;
2907+ }
2908+
2909+ //! Sets value of node to a zero-terminated string.
2910+ //! See also \ref ownership_of_strings and xml_node::value(const Ch *, std::size_t).
2911+ //! \param value Vame of node to set. Must be zero terminated.
2912+ void value(const Ch *value)
2913+ {
2914+ this->value(value, internal::measure(value));
2915+ }
2916+
2917+ ///////////////////////////////////////////////////////////////////////////
2918+ // Related nodes access
2919+
2920+ //! Gets node parent.
2921+ //! \return Pointer to parent node, or 0 if there is no parent.
2922+ xml_node<Ch> *parent() const
2923+ {
2924+ return m_parent;
2925+ }
2926+
2927+ protected:
2928+
2929+ // Return empty string
2930+ static Ch *nullstr()
2931+ {
2932+ static Ch zero = Ch('\0');
2933+ return &zero;
2934+ }
2935+
2936+ Ch *m_name; // Name of node, or 0 if no name
2937+ Ch *m_value; // Value of node, or 0 if no value
2938+ std::size_t m_name_size; // Length of node name, or undefined of no name
2939+ std::size_t m_value_size; // Length of node value, or undefined if no value
2940+ xml_node<Ch> *m_parent; // Pointer to parent node, or 0 if none
2941+
2942+ };
2943+
2944+ //! Class representing attribute node of XML document.
2945+ //! Each attribute has name and value strings, which are available through name() and value() functions (inherited from xml_base).
2946+ //! Note that after parse, both name and value of attribute will point to interior of source text used for parsing.
2947+ //! Thus, this text must persist in memory for the lifetime of attribute.
2948+ //! \param Ch Character type to use.
2949+ template<class Ch = char>
2950+ class xml_attribute: public xml_base<Ch>
2951+ {
2952+
2953+ friend class xml_node<Ch>;
2954+
2955+ public:
2956+
2957+ ///////////////////////////////////////////////////////////////////////////
2958+ // Construction & destruction
2959+
2960+ //! Constructs an empty attribute with the specified type.
2961+ //! Consider using memory_pool of appropriate xml_document if allocating attributes manually.
2962+ xml_attribute()
2963+ {
2964+ }
2965+
2966+ ///////////////////////////////////////////////////////////////////////////
2967+ // Related nodes access
2968+
2969+ //! Gets document of which attribute is a child.
2970+ //! \return Pointer to document that contains this attribute, or 0 if there is no parent document.
2971+ xml_document<Ch> *document() const
2972+ {
2973+ if (xml_node<Ch> *node = this->parent())
2974+ {
2975+ while (node->parent())
2976+ node = node->parent();
2977+ return node->type() == node_document ? static_cast<xml_document<Ch> *>(node) : 0;
2978+ }
2979+ else
2980+ return 0;
2981+ }
2982+
2983+ //! Gets previous attribute, optionally matching attribute name.
2984+ //! \param name Name of attribute to find, or 0 to return previous attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
2985+ //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
2986+ //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
2987+ //! \return Pointer to found attribute, or 0 if not found.
2988+ xml_attribute<Ch> *previous_attribute(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const
2989+ {
2990+ if (name)
2991+ {
2992+ if (name_size == 0)
2993+ name_size = internal::measure(name);
2994+ for (xml_attribute<Ch> *attribute = m_prev_attribute; attribute; attribute = attribute->m_prev_attribute)
2995+ if (internal::compare(attribute->name(), attribute->name_size(), name, name_size, case_sensitive))
2996+ return attribute;
2997+ return 0;
2998+ }
2999+ else
3000+ return this->m_parent ? m_prev_attribute : 0;
3001+ }
3002+
3003+ //! Gets next attribute, optionally matching attribute name.
3004+ //! \param name Name of attribute to find, or 0 to return next attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
3005+ //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
3006+ //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
3007+ //! \return Pointer to found attribute, or 0 if not found.
3008+ xml_attribute<Ch> *next_attribute(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const
3009+ {
3010+ if (name)
3011+ {
3012+ if (name_size == 0)
3013+ name_size = internal::measure(name);
3014+ for (xml_attribute<Ch> *attribute = m_next_attribute; attribute; attribute = attribute->m_next_attribute)
3015+ if (internal::compare(attribute->name(), attribute->name_size(), name, name_size, case_sensitive))
3016+ return attribute;
3017+ return 0;
3018+ }
3019+ else
3020+ return this->m_parent ? m_next_attribute : 0;
3021+ }
3022+
3023+ private:
3024+
3025+ xml_attribute<Ch> *m_prev_attribute; // Pointer to previous sibling of attribute, or 0 if none; only valid if parent is non-zero
3026+ xml_attribute<Ch> *m_next_attribute; // Pointer to next sibling of attribute, or 0 if none; only valid if parent is non-zero
3027+
3028+ };
3029+
3030+ ///////////////////////////////////////////////////////////////////////////
3031+ // XML node
3032+
3033+ //! Class representing a node of XML document.
3034+ //! Each node may have associated name and value strings, which are available through name() and value() functions.
3035+ //! Interpretation of name and value depends on type of the node.
3036+ //! Type of node can be determined by using type() function.
3037+ //! <br><br>
3038+ //! Note that after parse, both name and value of node, if any, will point interior of source text used for parsing.
3039+ //! Thus, this text must persist in the memory for the lifetime of node.
3040+ //! \param Ch Character type to use.
3041+ template<class Ch = char>
3042+ class xml_node: public xml_base<Ch>
3043+ {
3044+
3045+ public:
3046+
3047+ ///////////////////////////////////////////////////////////////////////////
3048+ // Construction & destruction
3049+
3050+ //! Constructs an empty node with the specified type.
3051+ //! Consider using memory_pool of appropriate document to allocate nodes manually.
3052+ //! \param type Type of node to construct.
3053+ xml_node(node_type type)
3054+ : m_type(type)
3055+ , m_first_node(0)
3056+ , m_first_attribute(0)
3057+ {
3058+ }
3059+
3060+ ///////////////////////////////////////////////////////////////////////////
3061+ // Node data access
3062+
3063+ //! Gets type of node.
3064+ //! \return Type of node.
3065+ node_type type() const
3066+ {
3067+ return m_type;
3068+ }
3069+
3070+ ///////////////////////////////////////////////////////////////////////////
3071+ // Related nodes access
3072+
3073+ //! Gets document of which node is a child.
3074+ //! \return Pointer to document that contains this node, or 0 if there is no parent document.
3075+ xml_document<Ch> *document() const
3076+ {
3077+ xml_node<Ch> *node = const_cast<xml_node<Ch> *>(this);
3078+ while (node->parent())
3079+ node = node->parent();
3080+ return node->type() == node_document ? static_cast<xml_document<Ch> *>(node) : 0;
3081+ }
3082+
3083+ //! Gets first child node, optionally matching node name.
3084+ //! \param name Name of child to find, or 0 to return first child regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
3085+ //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
3086+ //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
3087+ //! \return Pointer to found child, or 0 if not found.
3088+ xml_node<Ch> *first_node(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const
3089+ {
3090+ if (name)
3091+ {
3092+ if (name_size == 0)
3093+ name_size = internal::measure(name);
3094+ for (xml_node<Ch> *child = m_first_node; child; child = child->next_sibling())
3095+ if (internal::compare(child->name(), child->name_size(), name, name_size, case_sensitive))
3096+ return child;
3097+ return 0;
3098+ }
3099+ else
3100+ return m_first_node;
3101+ }
3102+
3103+ //! Gets last child node, optionally matching node name.
3104+ //! Behaviour is undefined if node has no children.
3105+ //! Use first_node() to test if node has children.
3106+ //! \param name Name of child to find, or 0 to return last child regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
3107+ //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
3108+ //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
3109+ //! \return Pointer to found child, or 0 if not found.
3110+ xml_node<Ch> *last_node(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const
3111+ {
3112+ assert(m_first_node); // Cannot query for last child if node has no children
3113+ if (name)
3114+ {
3115+ if (name_size == 0)
3116+ name_size = internal::measure(name);
3117+ for (xml_node<Ch> *child = m_last_node; child; child = child->previous_sibling())
3118+ if (internal::compare(child->name(), child->name_size(), name, name_size, case_sensitive))
3119+ return child;
3120+ return 0;
3121+ }
3122+ else
3123+ return m_last_node;
3124+ }
3125+
3126+ //! Gets previous sibling node, optionally matching node name.
3127+ //! Behaviour is undefined if node has no parent.
3128+ //! Use parent() to test if node has a parent.
3129+ //! \param name Name of sibling to find, or 0 to return previous sibling regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
3130+ //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
3131+ //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
3132+ //! \return Pointer to found sibling, or 0 if not found.
3133+ xml_node<Ch> *previous_sibling(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const
3134+ {
3135+ assert(this->m_parent); // Cannot query for siblings if node has no parent
3136+ if (name)
3137+ {
3138+ if (name_size == 0)
3139+ name_size = internal::measure(name);
3140+ for (xml_node<Ch> *sibling = m_prev_sibling; sibling; sibling = sibling->m_prev_sibling)
3141+ if (internal::compare(sibling->name(), sibling->name_size(), name, name_size, case_sensitive))
3142+ return sibling;
3143+ return 0;
3144+ }
3145+ else
3146+ return m_prev_sibling;
3147+ }
3148+
3149+ //! Gets next sibling node, optionally matching node name.
3150+ //! Behaviour is undefined if node has no parent.
3151+ //! Use parent() to test if node has a parent.
3152+ //! \param name Name of sibling to find, or 0 to return next sibling regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
3153+ //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
3154+ //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
3155+ //! \return Pointer to found sibling, or 0 if not found.
3156+ xml_node<Ch> *next_sibling(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const
3157+ {
3158+ assert(this->m_parent); // Cannot query for siblings if node has no parent
3159+ if (name)
3160+ {
3161+ if (name_size == 0)
3162+ name_size = internal::measure(name);
3163+ for (xml_node<Ch> *sibling = m_next_sibling; sibling; sibling = sibling->m_next_sibling)
3164+ if (internal::compare(sibling->name(), sibling->name_size(), name, name_size, case_sensitive))
3165+ return sibling;
3166+ return 0;
3167+ }
3168+ else
3169+ return m_next_sibling;
3170+ }
3171+
3172+ //! Gets first attribute of node, optionally matching attribute name.
3173+ //! \param name Name of attribute to find, or 0 to return first attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
3174+ //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
3175+ //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
3176+ //! \return Pointer to found attribute, or 0 if not found.
3177+ xml_attribute<Ch> *first_attribute(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const
3178+ {
3179+ if (name)
3180+ {
3181+ if (name_size == 0)
3182+ name_size = internal::measure(name);
3183+ for (xml_attribute<Ch> *attribute = m_first_attribute; attribute; attribute = attribute->m_next_attribute)
3184+ if (internal::compare(attribute->name(), attribute->name_size(), name, name_size, case_sensitive))
3185+ return attribute;
3186+ return 0;
3187+ }
3188+ else
3189+ return m_first_attribute;
3190+ }
3191+
3192+ //! Gets last attribute of node, optionally matching attribute name.
3193+ //! \param name Name of attribute to find, or 0 to return last attribute regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero
3194+ //! \param name_size Size of name, in characters, or 0 to have size calculated automatically from string
3195+ //! \param case_sensitive Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters
3196+ //! \return Pointer to found attribute, or 0 if not found.
3197+ xml_attribute<Ch> *last_attribute(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const
3198+ {
3199+ if (name)
3200+ {
3201+ if (name_size == 0)
3202+ name_size = internal::measure(name);
3203+ for (xml_attribute<Ch> *attribute = m_last_attribute; attribute; attribute = attribute->m_prev_attribute)
3204+ if (internal::compare(attribute->name(), attribute->name_size(), name, name_size, case_sensitive))
3205+ return attribute;
3206+ return 0;
3207+ }
3208+ else
3209+ return m_first_attribute ? m_last_attribute : 0;
3210+ }
3211+
3212+ ///////////////////////////////////////////////////////////////////////////
3213+ // Node modification
3214+
3215+ //! Sets type of node.
3216+ //! \param type Type of node to set.
3217+ void type(node_type type)
3218+ {
3219+ m_type = type;
3220+ }
3221+
3222+ ///////////////////////////////////////////////////////////////////////////
3223+ // Node manipulation
3224+
3225+ //! Prepends a new child node.
3226+ //! The prepended child becomes the first child, and all existing children are moved one position back.
3227+ //! \param child Node to prepend.
3228+ void prepend_node(xml_node<Ch> *child)
3229+ {
3230+ assert(child && !child->parent() && child->type() != node_document);
3231+ if (first_node())
3232+ {
3233+ child->m_next_sibling = m_first_node;
3234+ m_first_node->m_prev_sibling = child;
3235+ }
3236+ else
3237+ {
3238+ child->m_next_sibling = 0;
3239+ m_last_node = child;
3240+ }
3241+ m_first_node = child;
3242+ child->m_parent = this;
3243+ child->m_prev_sibling = 0;
3244+ }
3245+
3246+ //! Appends a new child node.
3247+ //! The appended child becomes the last child.
3248+ //! \param child Node to append.
3249+ void append_node(xml_node<Ch> *child)
3250+ {
3251+ assert(child && !child->parent() && child->type() != node_document);
3252+ if (first_node())
3253+ {
3254+ child->m_prev_sibling = m_last_node;
3255+ m_last_node->m_next_sibling = child;
3256+ }
3257+ else
3258+ {
3259+ child->m_prev_sibling = 0;
3260+ m_first_node = child;
3261+ }
3262+ m_last_node = child;
3263+ child->m_parent = this;
3264+ child->m_next_sibling = 0;
3265+ }
3266+
3267+ //! Inserts a new child node at specified place inside the node.
3268+ //! All children after and including the specified node are moved one position back.
3269+ //! \param where Place where to insert the child, or 0 to insert at the back.
3270+ //! \param child Node to insert.
3271+ void insert_node(xml_node<Ch> *where, xml_node<Ch> *child)
3272+ {
3273+ assert(!where || where->parent() == this);
3274+ assert(child && !child->parent() && child->type() != node_document);
3275+ if (where == m_first_node)
3276+ prepend_node(child);
3277+ else if (where == 0)
3278+ append_node(child);
3279+ else
3280+ {
3281+ child->m_prev_sibling = where->m_prev_sibling;
3282+ child->m_next_sibling = where;
3283+ where->m_prev_sibling->m_next_sibling = child;
3284+ where->m_prev_sibling = child;
3285+ child->m_parent = this;
3286+ }
3287+ }
3288+
3289+ //! Removes first child node.
3290+ //! If node has no children, behaviour is undefined.
3291+ //! Use first_node() to test if node has children.
3292+ void remove_first_node()
3293+ {
3294+ assert(first_node());
3295+ xml_node<Ch> *child = m_first_node;
3296+ m_first_node = child->m_next_sibling;
3297+ if (child->m_next_sibling)
3298+ child->m_next_sibling->m_prev_sibling = 0;
3299+ else
3300+ m_last_node = 0;
3301+ child->m_parent = 0;
3302+ }
3303+
3304+ //! Removes last child of the node.
3305+ //! If node has no children, behaviour is undefined.
3306+ //! Use first_node() to test if node has children.
3307+ void remove_last_node()
3308+ {
3309+ assert(first_node());
3310+ xml_node<Ch> *child = m_last_node;
3311+ if (child->m_prev_sibling)
3312+ {
3313+ m_last_node = child->m_prev_sibling;
3314+ child->m_prev_sibling->m_next_sibling = 0;
3315+ }
3316+ else
3317+ m_first_node = 0;
3318+ child->m_parent = 0;
3319+ }
3320+
3321+ //! Removes specified child from the node
3322+ // \param where Pointer to child to be removed.
3323+ void remove_node(xml_node<Ch> *where)
3324+ {
3325+ assert(where && where->parent() == this);
3326+ assert(first_node());
3327+ if (where == m_first_node)
3328+ remove_first_node();
3329+ else if (where == m_last_node)
3330+ remove_last_node();
3331+ else
3332+ {
3333+ where->m_prev_sibling->m_next_sibling = where->m_next_sibling;
3334+ where->m_next_sibling->m_prev_sibling = where->m_prev_sibling;
3335+ where->m_parent = 0;
3336+ }
3337+ }
3338+
3339+ //! Removes all child nodes (but not attributes).
3340+ void remove_all_nodes()
3341+ {
3342+ for (xml_node<Ch> *node = first_node(); node; node = node->m_next_sibling)
3343+ node->m_parent = 0;
3344+ m_first_node = 0;
3345+ }
3346+
3347+ //! Prepends a new attribute to the node.
3348+ //! \param attribute Attribute to prepend.
3349+ void prepend_attribute(xml_attribute<Ch> *attribute)
3350+ {
3351+ assert(attribute && !attribute->parent());
3352+ if (first_attribute())
3353+ {
3354+ attribute->m_next_attribute = m_first_attribute;
3355+ m_first_attribute->m_prev_attribute = attribute;
3356+ }
3357+ else
3358+ {
3359+ attribute->m_next_attribute = 0;
3360+ m_last_attribute = attribute;
3361+ }
3362+ m_first_attribute = attribute;
3363+ attribute->m_parent = this;
3364+ attribute->m_prev_attribute = 0;
3365+ }
3366+
3367+ //! Appends a new attribute to the node.
3368+ //! \param attribute Attribute to append.
3369+ void append_attribute(xml_attribute<Ch> *attribute)
3370+ {
3371+ assert(attribute && !attribute->parent());
3372+ if (first_attribute())
3373+ {
3374+ attribute->m_prev_attribute = m_last_attribute;
3375+ m_last_attribute->m_next_attribute = attribute;
3376+ }
3377+ else
3378+ {
3379+ attribute->m_prev_attribute = 0;
3380+ m_first_attribute = attribute;
3381+ }
3382+ m_last_attribute = attribute;
3383+ attribute->m_parent = this;
3384+ attribute->m_next_attribute = 0;
3385+ }
3386+
3387+ //! Inserts a new attribute at specified place inside the node.
3388+ //! All attributes after and including the specified attribute are moved one position back.
3389+ //! \param where Place where to insert the attribute, or 0 to insert at the back.
3390+ //! \param attribute Attribute to insert.
3391+ void insert_attribute(xml_attribute<Ch> *where, xml_attribute<Ch> *attribute)
3392+ {
3393+ assert(!where || where->parent() == this);
3394+ assert(attribute && !attribute->parent());
3395+ if (where == m_first_attribute)
3396+ prepend_attribute(attribute);
3397+ else if (where == 0)
3398+ append_attribute(attribute);
3399+ else
3400+ {
3401+ attribute->m_prev_attribute = where->m_prev_attribute;
3402+ attribute->m_next_attribute = where;
3403+ where->m_prev_attribute->m_next_attribute = attribute;
3404+ where->m_prev_attribute = attribute;
3405+ attribute->m_parent = this;
3406+ }
3407+ }
3408+
3409+ //! Removes first attribute of the node.
3410+ //! If node has no attributes, behaviour is undefined.
3411+ //! Use first_attribute() to test if node has attributes.
3412+ void remove_first_attribute()
3413+ {
3414+ assert(first_attribute());
3415+ xml_attribute<Ch> *attribute = m_first_attribute;
3416+ if (attribute->m_next_attribute)
3417+ {
3418+ attribute->m_next_attribute->m_prev_attribute = 0;
3419+ }
3420+ else
3421+ m_last_attribute = 0;
3422+ attribute->m_parent = 0;
3423+ m_first_attribute = attribute->m_next_attribute;
3424+ }
3425+
3426+ //! Removes last attribute of the node.
3427+ //! If node has no attributes, behaviour is undefined.
3428+ //! Use first_attribute() to test if node has attributes.
3429+ void remove_last_attribute()
3430+ {
3431+ assert(first_attribute());
3432+ xml_attribute<Ch> *attribute = m_last_attribute;
3433+ if (attribute->m_prev_attribute)
3434+ {
3435+ attribute->m_prev_attribute->m_next_attribute = 0;
3436+ m_last_attribute = attribute->m_prev_attribute;
3437+ }
3438+ else
3439+ m_first_attribute = 0;
3440+ attribute->m_parent = 0;
3441+ }
3442+
3443+ //! Removes specified attribute from node.
3444+ //! \param where Pointer to attribute to be removed.
3445+ void remove_attribute(xml_attribute<Ch> *where)
3446+ {
3447+ assert(first_attribute() && where->parent() == this);
3448+ if (where == m_first_attribute)
3449+ remove_first_attribute();
3450+ else if (where == m_last_attribute)
3451+ remove_last_attribute();
3452+ else
3453+ {
3454+ where->m_prev_attribute->m_next_attribute = where->m_next_attribute;
3455+ where->m_next_attribute->m_prev_attribute = where->m_prev_attribute;
3456+ where->m_parent = 0;
3457+ }
3458+ }
3459+
3460+ //! Removes all attributes of node.
3461+ void remove_all_attributes()
3462+ {
3463+ for (xml_attribute<Ch> *attribute = first_attribute(); attribute; attribute = attribute->m_next_attribute)
3464+ attribute->m_parent = 0;
3465+ m_first_attribute = 0;
3466+ }
3467+
3468+ private:
3469+
3470+ ///////////////////////////////////////////////////////////////////////////
3471+ // Restrictions
3472+
3473+ // No copying
3474+ xml_node(const xml_node &);
3475+ void operator =(const xml_node &);
3476+
3477+ ///////////////////////////////////////////////////////////////////////////
3478+ // Data members
3479+
3480+ // Note that some of the pointers below have UNDEFINED values if certain other pointers are 0.
3481+ // This is required for maximum performance, as it allows the parser to omit initialization of
3482+ // unneded/redundant values.
3483+ //
3484+ // The rules are as follows:
3485+ // 1. first_node and first_attribute contain valid pointers, or 0 if node has no children/attributes respectively
3486+ // 2. last_node and last_attribute are valid only if node has at least one child/attribute respectively, otherwise they contain garbage
3487+ // 3. prev_sibling and next_sibling are valid only if node has a parent, otherwise they contain garbage
3488+
3489+ node_type m_type; // Type of node; always valid
3490+ xml_node<Ch> *m_first_node; // Pointer to first child node, or 0 if none; always valid
3491+ xml_node<Ch> *m_last_node; // Pointer to last child node, or 0 if none; this value is only valid if m_first_node is non-zero
3492+ xml_attribute<Ch> *m_first_attribute; // Pointer to first attribute of node, or 0 if none; always valid
3493+ xml_attribute<Ch> *m_last_attribute; // Pointer to last attribute of node, or 0 if none; this value is only valid if m_first_attribute is non-zero
3494+ xml_node<Ch> *m_prev_sibling; // Pointer to previous sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
3495+ xml_node<Ch> *m_next_sibling; // Pointer to next sibling of node, or 0 if none; this value is only valid if m_parent is non-zero
3496+
3497+ };
3498+
3499+ ///////////////////////////////////////////////////////////////////////////
3500+ // XML document
3501+
3502+ //! This class represents root of the DOM hierarchy.
3503+ //! It is also an xml_node and a memory_pool through public inheritance.
3504+ //! Use parse() function to build a DOM tree from a zero-terminated XML text string.
3505+ //! parse() function allocates memory for nodes and attributes by using functions of xml_document,
3506+ //! which are inherited from memory_pool.
3507+ //! To access root node of the document, use the document itself, as if it was an xml_node.
3508+ //! \param Ch Character type to use.
3509+ template<class Ch = char>
3510+ class xml_document: public xml_node<Ch>, public memory_pool<Ch>
3511+ {
3512+
3513+ public:
3514+
3515+ //! Constructs empty XML document
3516+ xml_document()
3517+ : xml_node<Ch>(node_document)
3518+ {
3519+ }
3520+
3521+ //! Parses zero-terminated XML string according to given flags.
3522+ //! Passed string will be modified by the parser, unless rapidxml::parse_non_destructive flag is used.
3523+ //! The string must persist for the lifetime of the document.
3524+ //! In case of error, rapidxml::parse_error exception will be thrown.
3525+ //! <br><br>
3526+ //! If you want to parse contents of a file, you must first load the file into the memory, and pass pointer to its beginning.
3527+ //! Make sure that data is zero-terminated.
3528+ //! <br><br>
3529+ //! Document can be parsed into multiple times.
3530+ //! Each new call to parse removes previous nodes and attributes (if any), but does not clear memory pool.
3531+ //! \param text XML data to parse; pointer is non-const to denote fact that this data may be modified by the parser.
3532+ template<int Flags>
3533+ void parse(Ch *text)
3534+ {
3535+ assert(text);
3536+
3537+ // Remove current contents
3538+ this->remove_all_nodes();
3539+ this->remove_all_attributes();
3540+
3541+ // Parse BOM, if any
3542+ parse_bom<Flags>(text);
3543+
3544+ // Parse children
3545+ while (1)
3546+ {
3547+ // Skip whitespace before node
3548+ skip<whitespace_pred, Flags>(text);
3549+ if (*text == 0)
3550+ break;
3551+
3552+ // Parse and append new child
3553+ if (*text == Ch('<'))
3554+ {
3555+ ++text; // Skip '<'
3556+ if (xml_node<Ch> *node = parse_node<Flags>(text))
3557+ this->append_node(node);
3558+ }
3559+ else
3560+ RAPIDXML_PARSE_ERROR("expected <", text);
3561+ }
3562+
3563+ }
3564+
3565+ //! Clears the document by deleting all nodes and clearing the memory pool.
3566+ //! All nodes owned by document pool are destroyed.
3567+ void clear()
3568+ {
3569+ this->remove_all_nodes();
3570+ this->remove_all_attributes();
3571+ memory_pool<Ch>::clear();
3572+ }
3573+
3574+ private:
3575+
3576+ ///////////////////////////////////////////////////////////////////////
3577+ // Internal character utility functions
3578+
3579+ // Detect whitespace character
3580+ struct whitespace_pred
3581+ {
3582+ static unsigned char test(Ch ch)
3583+ {
3584+ return internal::lookup_tables<0>::lookup_whitespace[static_cast<unsigned char>(ch)];
3585+ }
3586+ };
3587+
3588+ // Detect node name character
3589+ struct node_name_pred
3590+ {
3591+ static unsigned char test(Ch ch)
3592+ {
3593+ return internal::lookup_tables<0>::lookup_node_name[static_cast<unsigned char>(ch)];
3594+ }
3595+ };
3596+
3597+ // Detect attribute name character
3598+ struct attribute_name_pred
3599+ {
3600+ static unsigned char test(Ch ch)
3601+ {
3602+ return internal::lookup_tables<0>::lookup_attribute_name[static_cast<unsigned char>(ch)];
3603+ }
3604+ };
3605+
3606+ // Detect text character (PCDATA)
3607+ struct text_pred
3608+ {
3609+ static unsigned char test(Ch ch)
3610+ {
3611+ return internal::lookup_tables<0>::lookup_text[static_cast<unsigned char>(ch)];
3612+ }
3613+ };
3614+
3615+ // Detect text character (PCDATA) that does not require processing
3616+ struct text_pure_no_ws_pred
3617+ {
3618+ static unsigned char test(Ch ch)
3619+ {
3620+ return internal::lookup_tables<0>::lookup_text_pure_no_ws[static_cast<unsigned char>(ch)];
3621+ }
3622+ };
3623+
3624+ // Detect text character (PCDATA) that does not require processing
3625+ struct text_pure_with_ws_pred
3626+ {
3627+ static unsigned char test(Ch ch)
3628+ {
3629+ return internal::lookup_tables<0>::lookup_text_pure_with_ws[static_cast<unsigned char>(ch)];
3630+ }
3631+ };
3632+
3633+ // Detect attribute value character
3634+ template<Ch Quote>
3635+ struct attribute_value_pred
3636+ {
3637+ static unsigned char test(Ch ch)
3638+ {
3639+ if (Quote == Ch('\''))
3640+ return internal::lookup_tables<0>::lookup_attribute_data_1[static_cast<unsigned char>(ch)];
3641+ if (Quote == Ch('\"'))
3642+ return internal::lookup_tables<0>::lookup_attribute_data_2[static_cast<unsigned char>(ch)];
3643+ return 0; // Should never be executed, to avoid warnings on Comeau
3644+ }
3645+ };
3646+
3647+ // Detect attribute value character
3648+ template<Ch Quote>
3649+ struct attribute_value_pure_pred
3650+ {
3651+ static unsigned char test(Ch ch)
3652+ {
3653+ if (Quote == Ch('\''))
3654+ return internal::lookup_tables<0>::lookup_attribute_data_1_pure[static_cast<unsigned char>(ch)];
3655+ if (Quote == Ch('\"'))
3656+ return internal::lookup_tables<0>::lookup_attribute_data_2_pure[static_cast<unsigned char>(ch)];
3657+ return 0; // Should never be executed, to avoid warnings on Comeau
3658+ }
3659+ };
3660+
3661+ // Insert coded character, using UTF8 or 8-bit ASCII
3662+ template<int Flags>
3663+ static void insert_coded_character(Ch *&text, unsigned long code)
3664+ {
3665+ if (Flags & parse_no_utf8)
3666+ {
3667+ // Insert 8-bit ASCII character
3668+ // Todo: possibly verify that code is less than 256 and use replacement char otherwise?
3669+ text[0] = static_cast<unsigned char>(code);
3670+ text += 1;
3671+ }
3672+ else
3673+ {
3674+ // Insert UTF8 sequence
3675+ if (code < 0x80) // 1 byte sequence
3676+ {
3677+ text[0] = static_cast<unsigned char>(code);
3678+ text += 1;
3679+ }
3680+ else if (code < 0x800) // 2 byte sequence
3681+ {
3682+ text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
3683+ text[0] = static_cast<unsigned char>(code | 0xC0);
3684+ text += 2;
3685+ }
3686+ else if (code < 0x10000) // 3 byte sequence
3687+ {
3688+ text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
3689+ text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
3690+ text[0] = static_cast<unsigned char>(code | 0xE0);
3691+ text += 3;
3692+ }
3693+ else if (code < 0x110000) // 4 byte sequence
3694+ {
3695+ text[3] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
3696+ text[2] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
3697+ text[1] = static_cast<unsigned char>((code | 0x80) & 0xBF); code >>= 6;
3698+ text[0] = static_cast<unsigned char>(code | 0xF0);
3699+ text += 4;
3700+ }
3701+ else // Invalid, only codes up to 0x10FFFF are allowed in Unicode
3702+ {
3703+ RAPIDXML_PARSE_ERROR("invalid numeric character entity", text);
3704+ }
3705+ }
3706+ }
3707+
3708+ // Skip characters until predicate evaluates to true
3709+ template<class StopPred, int Flags>
3710+ static void skip(Ch *&text)
3711+ {
3712+ Ch *tmp = text;
3713+ while (StopPred::test(*tmp))
3714+ ++tmp;
3715+ text = tmp;
3716+ }
3717+
3718+ // Skip characters until predicate evaluates to true while doing the following:
3719+ // - replacing XML character entity references with proper characters (&apos; &amp; &quot; &lt; &gt; &#...;)
3720+ // - condensing whitespace sequences to single space character
3721+ template<class StopPred, class StopPredPure, int Flags>
3722+ static Ch *skip_and_expand_character_refs(Ch *&text)
3723+ {
3724+ // If entity translation, whitespace condense and whitespace trimming is disabled, use plain skip
3725+ if (Flags & parse_no_entity_translation &&
3726+ !(Flags & parse_normalize_whitespace) &&
3727+ !(Flags & parse_trim_whitespace))
3728+ {
3729+ skip<StopPred, Flags>(text);
3730+ return text;
3731+ }
3732+
3733+ // Use simple skip until first modification is detected
3734+ skip<StopPredPure, Flags>(text);
3735+
3736+ // Use translation skip
3737+ Ch *src = text;
3738+ Ch *dest = src;
3739+ while (StopPred::test(*src))
3740+ {
3741+ // If entity translation is enabled
3742+ if (!(Flags & parse_no_entity_translation))
3743+ {
3744+ // Test if replacement is needed
3745+ if (src[0] == Ch('&'))
3746+ {
3747+ switch (src[1])
3748+ {
3749+
3750+ // &amp; &apos;
3751+ case Ch('a'):
3752+ if (src[2] == Ch('m') && src[3] == Ch('p') && src[4] == Ch(';'))
3753+ {
3754+ *dest = Ch('&');
3755+ ++dest;
3756+ src += 5;
3757+ continue;
3758+ }
3759+ if (src[2] == Ch('p') && src[3] == Ch('o') && src[4] == Ch('s') && src[5] == Ch(';'))
3760+ {
3761+ *dest = Ch('\'');
3762+ ++dest;
3763+ src += 6;
3764+ continue;
3765+ }
3766+ break;
3767+
3768+ // &quot;
3769+ case Ch('q'):
3770+ if (src[2] == Ch('u') && src[3] == Ch('o') && src[4] == Ch('t') && src[5] == Ch(';'))
3771+ {
3772+ *dest = Ch('"');
3773+ ++dest;
3774+ src += 6;
3775+ continue;
3776+ }
3777+ break;
3778+
3779+ // &gt;
3780+ case Ch('g'):
3781+ if (src[2] == Ch('t') && src[3] == Ch(';'))
3782+ {
3783+ *dest = Ch('>');
3784+ ++dest;
3785+ src += 4;
3786+ continue;
3787+ }
3788+ break;
3789+
3790+ // &lt;
3791+ case Ch('l'):
3792+ if (src[2] == Ch('t') && src[3] == Ch(';'))
3793+ {
3794+ *dest = Ch('<');
3795+ ++dest;
3796+ src += 4;
3797+ continue;
3798+ }
3799+ break;
3800+
3801+ // &#...; - assumes ASCII
3802+ case Ch('#'):
3803+ if (src[2] == Ch('x'))
3804+ {
3805+ unsigned long code = 0;
3806+ src += 3; // Skip &#x
3807+ while (1)
3808+ {
3809+ unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
3810+ if (digit == 0xFF)
3811+ break;
3812+ code = code * 16 + digit;
3813+ ++src;
3814+ }
3815+ insert_coded_character<Flags>(dest, code); // Put character in output
3816+ }
3817+ else
3818+ {
3819+ unsigned long code = 0;
3820+ src += 2; // Skip &#
3821+ while (1)
3822+ {
3823+ unsigned char digit = internal::lookup_tables<0>::lookup_digits[static_cast<unsigned char>(*src)];
3824+ if (digit == 0xFF)
3825+ break;
3826+ code = code * 10 + digit;
3827+ ++src;
3828+ }
3829+ insert_coded_character<Flags>(dest, code); // Put character in output
3830+ }
3831+ if (*src == Ch(';'))
3832+ ++src;
3833+ else
3834+ RAPIDXML_PARSE_ERROR("expected ;", src);
3835+ continue;
3836+
3837+ // Something else
3838+ default:
3839+ // Ignore, just copy '&' verbatim
3840+ break;
3841+
3842+ }
3843+ }
3844+ }
3845+
3846+ // If whitespace condensing is enabled
3847+ if (Flags & parse_normalize_whitespace)
3848+ {
3849+ // Test if condensing is needed
3850+ if (whitespace_pred::test(*src))
3851+ {
3852+ *dest = Ch(' '); ++dest; // Put single space in dest
3853+ ++src; // Skip first whitespace char
3854+ // Skip remaining whitespace chars
3855+ while (whitespace_pred::test(*src))
3856+ ++src;
3857+ continue;
3858+ }
3859+ }
3860+
3861+ // No replacement, only copy character
3862+ *dest++ = *src++;
3863+
3864+ }
3865+
3866+ // Return new end
3867+ text = src;
3868+ return dest;
3869+
3870+ }
3871+
3872+ ///////////////////////////////////////////////////////////////////////
3873+ // Internal parsing functions
3874+
3875+ // Parse BOM, if any
3876+ template<int Flags>
3877+ void parse_bom(Ch *&text)
3878+ {
3879+ // UTF-8?
3880+ if (static_cast<unsigned char>(text[0]) == 0xEF &&
3881+ static_cast<unsigned char>(text[1]) == 0xBB &&
3882+ static_cast<unsigned char>(text[2]) == 0xBF)
3883+ {
3884+ text += 3; // Skup utf-8 bom
3885+ }
3886+ }
3887+
3888+ // Parse XML declaration (<?xml...)
3889+ template<int Flags>
3890+ xml_node<Ch> *parse_xml_declaration(Ch *&text)
3891+ {
3892+ // If parsing of declaration is disabled
3893+ if (!(Flags & parse_declaration_node))
3894+ {
3895+ // Skip until end of declaration
3896+ while (text[0] != Ch('?') || text[1] != Ch('>'))
3897+ {
3898+ if (!text[0])
3899+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
3900+ ++text;
3901+ }
3902+ text += 2; // Skip '?>'
3903+ return 0;
3904+ }
3905+
3906+ // Create declaration
3907+ xml_node<Ch> *declaration = this->allocate_node(node_declaration);
3908+
3909+ // Skip whitespace before attributes or ?>
3910+ skip<whitespace_pred, Flags>(text);
3911+
3912+ // Parse declaration attributes
3913+ parse_node_attributes<Flags>(text, declaration);
3914+
3915+ // Skip ?>
3916+ if (text[0] != Ch('?') || text[1] != Ch('>'))
3917+ RAPIDXML_PARSE_ERROR("expected ?>", text);
3918+ text += 2;
3919+
3920+ return declaration;
3921+ }
3922+
3923+ // Parse XML comment (<!--...)
3924+ template<int Flags>
3925+ xml_node<Ch> *parse_comment(Ch *&text)
3926+ {
3927+ // If parsing of comments is disabled
3928+ if (!(Flags & parse_comment_nodes))
3929+ {
3930+ // Skip until end of comment
3931+ while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
3932+ {
3933+ if (!text[0])
3934+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
3935+ ++text;
3936+ }
3937+ text += 3; // Skip '-->'
3938+ return 0; // Do not produce comment node
3939+ }
3940+
3941+ // Remember value start
3942+ Ch *value = text;
3943+
3944+ // Skip until end of comment
3945+ while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
3946+ {
3947+ if (!text[0])
3948+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
3949+ ++text;
3950+ }
3951+
3952+ // Create comment node
3953+ xml_node<Ch> *comment = this->allocate_node(node_comment);
3954+ comment->value(value, text - value);
3955+
3956+ // Place zero terminator after comment value
3957+ if (!(Flags & parse_no_string_terminators))
3958+ *text = Ch('\0');
3959+
3960+ text += 3; // Skip '-->'
3961+ return comment;
3962+ }
3963+
3964+ // Parse DOCTYPE
3965+ template<int Flags>
3966+ xml_node<Ch> *parse_doctype(Ch *&text)
3967+ {
3968+ // Remember value start
3969+ Ch *value = text;
3970+
3971+ // Skip to >
3972+ while (*text != Ch('>'))
3973+ {
3974+ // Determine character type
3975+ switch (*text)
3976+ {
3977+
3978+ // If '[' encountered, scan for matching ending ']' using naive algorithm with depth
3979+ // This works for all W3C test files except for 2 most wicked
3980+ case Ch('['):
3981+ {
3982+ ++text; // Skip '['
3983+ int depth = 1;
3984+ while (depth > 0)
3985+ {
3986+ switch (*text)
3987+ {
3988+ case Ch('['): ++depth; break;
3989+ case Ch(']'): --depth; break;
3990+ case 0: RAPIDXML_PARSE_ERROR("unexpected end of data", text);
3991+ }
3992+ ++text;
3993+ }
3994+ break;
3995+ }
3996+
3997+ // Error on end of text
3998+ case Ch('\0'):
3999+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
4000+
4001+ // Other character, skip it
4002+ default:
4003+ ++text;
4004+
4005+ }
4006+ }
4007+
4008+ // If DOCTYPE nodes enabled
4009+ if (Flags & parse_doctype_node)
4010+ {
4011+ // Create a new doctype node
4012+ xml_node<Ch> *doctype = this->allocate_node(node_doctype);
4013+ doctype->value(value, text - value);
4014+
4015+ // Place zero terminator after value
4016+ if (!(Flags & parse_no_string_terminators))
4017+ *text = Ch('\0');
4018+
4019+ text += 1; // skip '>'
4020+ return doctype;
4021+ }
4022+ else
4023+ {
4024+ text += 1; // skip '>'
4025+ return 0;
4026+ }
4027+
4028+ }
4029+
4030+ // Parse PI
4031+ template<int Flags>
4032+ xml_node<Ch> *parse_pi(Ch *&text)
4033+ {
4034+ // If creation of PI nodes is enabled
4035+ if (Flags & parse_pi_nodes)
4036+ {
4037+ // Create pi node
4038+ xml_node<Ch> *pi = this->allocate_node(node_pi);
4039+
4040+ // Extract PI target name
4041+ Ch *name = text;
4042+ skip<node_name_pred, Flags>(text);
4043+ if (text == name)
4044+ RAPIDXML_PARSE_ERROR("expected PI target", text);
4045+ pi->name(name, text - name);
4046+
4047+ // Skip whitespace between pi target and pi
4048+ skip<whitespace_pred, Flags>(text);
4049+
4050+ // Remember start of pi
4051+ Ch *value = text;
4052+
4053+ // Skip to '?>'
4054+ while (text[0] != Ch('?') || text[1] != Ch('>'))
4055+ {
4056+ if (*text == Ch('\0'))
4057+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
4058+ ++text;
4059+ }
4060+
4061+ // Set pi value (verbatim, no entity expansion or whitespace normalization)
4062+ pi->value(value, text - value);
4063+
4064+ // Place zero terminator after name and value
4065+ if (!(Flags & parse_no_string_terminators))
4066+ {
4067+ pi->name()[pi->name_size()] = Ch('\0');
4068+ pi->value()[pi->value_size()] = Ch('\0');
4069+ }
4070+
4071+ text += 2; // Skip '?>'
4072+ return pi;
4073+ }
4074+ else
4075+ {
4076+ // Skip to '?>'
4077+ while (text[0] != Ch('?') || text[1] != Ch('>'))
4078+ {
4079+ if (*text == Ch('\0'))
4080+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
4081+ ++text;
4082+ }
4083+ text += 2; // Skip '?>'
4084+ return 0;
4085+ }
4086+ }
4087+
4088+ // Parse and append data
4089+ // Return character that ends data.
4090+ // This is necessary because this character might have been overwritten by a terminating 0
4091+ template<int Flags>
4092+ Ch parse_and_append_data(xml_node<Ch> *node, Ch *&text, Ch *contents_start)
4093+ {
4094+ // Backup to contents start if whitespace trimming is disabled
4095+ if (!(Flags & parse_trim_whitespace))
4096+ text = contents_start;
4097+
4098+ // Skip until end of data
4099+ Ch *value = text, *end;
4100+ if (Flags & parse_normalize_whitespace)
4101+ end = skip_and_expand_character_refs<text_pred, text_pure_with_ws_pred, Flags>(text);
4102+ else
4103+ end = skip_and_expand_character_refs<text_pred, text_pure_no_ws_pred, Flags>(text);
4104+
4105+ // Trim trailing whitespace if flag is set; leading was already trimmed by whitespace skip after >
4106+ if (Flags & parse_trim_whitespace)
4107+ {
4108+ if (Flags & parse_normalize_whitespace)
4109+ {
4110+ // Whitespace is already condensed to single space characters by skipping function, so just trim 1 char off the end
4111+ if (*(end - 1) == Ch(' '))
4112+ --end;
4113+ }
4114+ else
4115+ {
4116+ // Backup until non-whitespace character is found
4117+ while (whitespace_pred::test(*(end - 1)))
4118+ --end;
4119+ }
4120+ }
4121+
4122+ // If characters are still left between end and value (this test is only necessary if normalization is enabled)
4123+ // Create new data node
4124+ if (!(Flags & parse_no_data_nodes))
4125+ {
4126+ xml_node<Ch> *data = this->allocate_node(node_data);
4127+ data->value(value, end - value);
4128+ node->append_node(data);
4129+ }
4130+
4131+ // Add data to parent node if no data exists yet
4132+ if (!(Flags & parse_no_element_values))
4133+ if (*node->value() == Ch('\0'))
4134+ node->value(value, end - value);
4135+
4136+ // Place zero terminator after value
4137+ if (!(Flags & parse_no_string_terminators))
4138+ {
4139+ Ch ch = *text;
4140+ *end = Ch('\0');
4141+ return ch; // Return character that ends data; this is required because zero terminator overwritten it
4142+ }
4143+
4144+ // Return character that ends data
4145+ return *text;
4146+ }
4147+
4148+ // Parse CDATA
4149+ template<int Flags>
4150+ xml_node<Ch> *parse_cdata(Ch *&text)
4151+ {
4152+ // If CDATA is disabled
4153+ if (Flags & parse_no_data_nodes)
4154+ {
4155+ // Skip until end of cdata
4156+ while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
4157+ {
4158+ if (!text[0])
4159+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
4160+ ++text;
4161+ }
4162+ text += 3; // Skip ]]>
4163+ return 0; // Do not produce CDATA node
4164+ }
4165+
4166+ // Skip until end of cdata
4167+ Ch *value = text;
4168+ while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
4169+ {
4170+ if (!text[0])
4171+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
4172+ ++text;
4173+ }
4174+
4175+ // Create new cdata node
4176+ xml_node<Ch> *cdata = this->allocate_node(node_cdata);
4177+ cdata->value(value, text - value);
4178+
4179+ // Place zero terminator after value
4180+ if (!(Flags & parse_no_string_terminators))
4181+ *text = Ch('\0');
4182+
4183+ text += 3; // Skip ]]>
4184+ return cdata;
4185+ }
4186+
4187+ // Parse element node
4188+ template<int Flags>
4189+ xml_node<Ch> *parse_element(Ch *&text)
4190+ {
4191+ // Create element node
4192+ xml_node<Ch> *element = this->allocate_node(node_element);
4193+
4194+ // Extract element name
4195+ Ch *name = text;
4196+ skip<node_name_pred, Flags>(text);
4197+ if (text == name)
4198+ RAPIDXML_PARSE_ERROR("expected element name", text);
4199+ element->name(name, text - name);
4200+
4201+ // Skip whitespace between element name and attributes or >
4202+ skip<whitespace_pred, Flags>(text);
4203+
4204+ // Parse attributes, if any
4205+ parse_node_attributes<Flags>(text, element);
4206+
4207+ // Determine ending type
4208+ if (*text == Ch('>'))
4209+ {
4210+ ++text;
4211+ parse_node_contents<Flags>(text, element);
4212+ }
4213+ else if (*text == Ch('/'))
4214+ {
4215+ ++text;
4216+ if (*text != Ch('>'))
4217+ RAPIDXML_PARSE_ERROR("expected >", text);
4218+ ++text;
4219+ }
4220+ else
4221+ RAPIDXML_PARSE_ERROR("expected >", text);
4222+
4223+ // Place zero terminator after name
4224+ if (!(Flags & parse_no_string_terminators))
4225+ element->name()[element->name_size()] = Ch('\0');
4226+
4227+ // Return parsed element
4228+ return element;
4229+ }
4230+
4231+ // Determine node type, and parse it
4232+ template<int Flags>
4233+ xml_node<Ch> *parse_node(Ch *&text)
4234+ {
4235+ // Parse proper node type
4236+ switch (text[0])
4237+ {
4238+
4239+ // <...
4240+ default:
4241+ // Parse and append element node
4242+ return parse_element<Flags>(text);
4243+
4244+ // <?...
4245+ case Ch('?'):
4246+ ++text; // Skip ?
4247+ if ((text[0] == Ch('x') || text[0] == Ch('X')) &&
4248+ (text[1] == Ch('m') || text[1] == Ch('M')) &&
4249+ (text[2] == Ch('l') || text[2] == Ch('L')) &&
4250+ whitespace_pred::test(text[3]))
4251+ {
4252+ // '<?xml ' - xml declaration
4253+ text += 4; // Skip 'xml '
4254+ return parse_xml_declaration<Flags>(text);
4255+ }
4256+ else
4257+ {
4258+ // Parse PI
4259+ return parse_pi<Flags>(text);
4260+ }
4261+
4262+ // <!...
4263+ case Ch('!'):
4264+
4265+ // Parse proper subset of <! node
4266+ switch (text[1])
4267+ {
4268+
4269+ // <!-
4270+ case Ch('-'):
4271+ if (text[2] == Ch('-'))
4272+ {
4273+ // '<!--' - xml comment
4274+ text += 3; // Skip '!--'
4275+ return parse_comment<Flags>(text);
4276+ }
4277+ break;
4278+
4279+ // <![
4280+ case Ch('['):
4281+ if (text[2] == Ch('C') && text[3] == Ch('D') && text[4] == Ch('A') &&
4282+ text[5] == Ch('T') && text[6] == Ch('A') && text[7] == Ch('['))
4283+ {
4284+ // '<![CDATA[' - cdata
4285+ text += 8; // Skip '![CDATA['
4286+ return parse_cdata<Flags>(text);
4287+ }
4288+ break;
4289+
4290+ // <!D
4291+ case Ch('D'):
4292+ if (text[2] == Ch('O') && text[3] == Ch('C') && text[4] == Ch('T') &&
4293+ text[5] == Ch('Y') && text[6] == Ch('P') && text[7] == Ch('E') &&
4294+ whitespace_pred::test(text[8]))
4295+ {
4296+ // '<!DOCTYPE ' - doctype
4297+ text += 9; // skip '!DOCTYPE '
4298+ return parse_doctype<Flags>(text);
4299+ }
4300+
4301+ } // switch
4302+
4303+ // Attempt to skip other, unrecognized node types starting with <!
4304+ ++text; // Skip !
4305+ while (*text != Ch('>'))
4306+ {
4307+ if (*text == 0)
4308+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
4309+ ++text;
4310+ }
4311+ ++text; // Skip '>'
4312+ return 0; // No node recognized
4313+
4314+ }
4315+ }
4316+
4317+ // Parse contents of the node - children, data etc.
4318+ template<int Flags>
4319+ void parse_node_contents(Ch *&text, xml_node<Ch> *node)
4320+ {
4321+ // For all children and text
4322+ while (1)
4323+ {
4324+ // Skip whitespace between > and node contents
4325+ Ch *contents_start = text; // Store start of node contents before whitespace is skipped
4326+ skip<whitespace_pred, Flags>(text);
4327+ Ch next_char = *text;
4328+
4329+ // After data nodes, instead of continuing the loop, control jumps here.
4330+ // This is because zero termination inside parse_and_append_data() function
4331+ // would wreak havoc with the above code.
4332+ // Also, skipping whitespace after data nodes is unnecessary.
4333+ after_data_node:
4334+
4335+ // Determine what comes next: node closing, child node, data node, or 0?
4336+ switch (next_char)
4337+ {
4338+
4339+ // Node closing or child node
4340+ case Ch('<'):
4341+ if (text[1] == Ch('/'))
4342+ {
4343+ // Node closing
4344+ text += 2; // Skip '</'
4345+ if (Flags & parse_validate_closing_tags)
4346+ {
4347+ // Skip and validate closing tag name
4348+ Ch *closing_name = text;
4349+ skip<node_name_pred, Flags>(text);
4350+ if (!internal::compare(node->name(), node->name_size(), closing_name, text - closing_name, true))
4351+ RAPIDXML_PARSE_ERROR("invalid closing tag name", text);
4352+ }
4353+ else
4354+ {
4355+ // No validation, just skip name
4356+ skip<node_name_pred, Flags>(text);
4357+ }
4358+ // Skip remaining whitespace after node name
4359+ skip<whitespace_pred, Flags>(text);
4360+ if (*text != Ch('>'))
4361+ RAPIDXML_PARSE_ERROR("expected >", text);
4362+ ++text; // Skip '>'
4363+ return; // Node closed, finished parsing contents
4364+ }
4365+ else
4366+ {
4367+ // Child node
4368+ ++text; // Skip '<'
4369+ if (xml_node<Ch> *child = parse_node<Flags>(text))
4370+ node->append_node(child);
4371+ }
4372+ break;
4373+
4374+ // End of data - error
4375+ case Ch('\0'):
4376+ RAPIDXML_PARSE_ERROR("unexpected end of data", text);
4377+
4378+ // Data node
4379+ default:
4380+ next_char = parse_and_append_data<Flags>(node, text, contents_start);
4381+ goto after_data_node; // Bypass regular processing after data nodes
4382+
4383+ }
4384+ }
4385+ }
4386+
4387+ // Parse XML attributes of the node
4388+ template<int Flags>
4389+ void parse_node_attributes(Ch *&text, xml_node<Ch> *node)
4390+ {
4391+ // For all attributes
4392+ while (attribute_name_pred::test(*text))
4393+ {
4394+ // Extract attribute name
4395+ Ch *name = text;
4396+ ++text; // Skip first character of attribute name
4397+ skip<attribute_name_pred, Flags>(text);
4398+ if (text == name)
4399+ RAPIDXML_PARSE_ERROR("expected attribute name", name);
4400+
4401+ // Create new attribute
4402+ xml_attribute<Ch> *attribute = this->allocate_attribute();
4403+ attribute->name(name, text - name);
4404+ node->append_attribute(attribute);
4405+
4406+ // Skip whitespace after attribute name
4407+ skip<whitespace_pred, Flags>(text);
4408+
4409+ // Skip =
4410+ if (*text != Ch('='))
4411+ RAPIDXML_PARSE_ERROR("expected =", text);
4412+ ++text;
4413+
4414+ // Add terminating zero after name
4415+ if (!(Flags & parse_no_string_terminators))
4416+ attribute->name()[attribute->name_size()] = 0;
4417+
4418+ // Skip whitespace after =
4419+ skip<whitespace_pred, Flags>(text);
4420+
4421+ // Skip quote and remember if it was ' or "
4422+ Ch quote = *text;
4423+ if (quote != Ch('\'') && quote != Ch('"'))
4424+ RAPIDXML_PARSE_ERROR("expected ' or \"", text);
4425+ ++text;
4426+
4427+ // Extract attribute value and expand char refs in it
4428+ Ch *value = text, *end;
4429+ const int AttFlags = Flags & ~parse_normalize_whitespace; // No whitespace normalization in attributes
4430+ if (quote == Ch('\''))
4431+ end = skip_and_expand_character_refs<attribute_value_pred<Ch('\'')>, attribute_value_pure_pred<Ch('\'')>, AttFlags>(text);
4432+ else
4433+ end = skip_and_expand_character_refs<attribute_value_pred<Ch('"')>, attribute_value_pure_pred<Ch('"')>, AttFlags>(text);
4434+
4435+ // Set attribute value
4436+ attribute->value(value, end - value);
4437+
4438+ // Make sure that end quote is present
4439+ if (*text != quote)
4440+ RAPIDXML_PARSE_ERROR("expected ' or \"", text);
4441+ ++text; // Skip quote
4442+
4443+ // Add terminating zero after value
4444+ if (!(Flags & parse_no_string_terminators))
4445+ attribute->value()[attribute->value_size()] = 0;
4446+
4447+ // Skip whitespace after attribute value
4448+ skip<whitespace_pred, Flags>(text);
4449+ }
4450+ }
4451+
4452+ };
4453+
4454+ //! \cond internal
4455+ namespace internal
4456+ {
4457+
4458+ // Whitespace (space \n \r \t)
4459+ template<int Dummy>
4460+ const unsigned char lookup_tables<Dummy>::lookup_whitespace[256] =
4461+ {
4462+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4463+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, // 0
4464+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
4465+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2
4466+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3
4467+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4
4468+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5
4469+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6
4470+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 7
4471+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8
4472+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9
4473+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A
4474+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B
4475+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // C
4476+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // D
4477+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // E
4478+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // F
4479+ };
4480+
4481+ // Node name (anything but space \n \r \t / > ? \0)
4482+ template<int Dummy>
4483+ const unsigned char lookup_tables<Dummy>::lookup_node_name[256] =
4484+ {
4485+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4486+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
4487+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4488+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2
4489+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, // 3
4490+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4491+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4492+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4493+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4494+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4495+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4496+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4497+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4498+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4499+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4500+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4501+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4502+ };
4503+
4504+ // Text (i.e. PCDATA) (anything but < \0)
4505+ template<int Dummy>
4506+ const unsigned char lookup_tables<Dummy>::lookup_text[256] =
4507+ {
4508+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4509+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
4510+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4511+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
4512+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
4513+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4514+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4515+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4516+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4517+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4518+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4519+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4520+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4521+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4522+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4523+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4524+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4525+ };
4526+
4527+ // Text (i.e. PCDATA) that does not require processing when ws normalization is disabled
4528+ // (anything but < \0 &)
4529+ template<int Dummy>
4530+ const unsigned char lookup_tables<Dummy>::lookup_text_pure_no_ws[256] =
4531+ {
4532+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4533+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
4534+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4535+ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
4536+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
4537+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4538+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4539+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4540+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4541+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4542+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4543+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4544+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4545+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4546+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4547+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4548+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4549+ };
4550+
4551+ // Text (i.e. PCDATA) that does not require processing when ws normalizationis is enabled
4552+ // (anything but < \0 & space \n \r \t)
4553+ template<int Dummy>
4554+ const unsigned char lookup_tables<Dummy>::lookup_text_pure_with_ws[256] =
4555+ {
4556+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4557+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
4558+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4559+ 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
4560+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 3
4561+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4562+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4563+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4564+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4565+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4566+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4567+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4568+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4569+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4570+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4571+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4572+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4573+ };
4574+
4575+ // Attribute name (anything but space \n \r \t / < > = ? ! \0)
4576+ template<int Dummy>
4577+ const unsigned char lookup_tables<Dummy>::lookup_attribute_name[256] =
4578+ {
4579+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4580+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, // 0
4581+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4582+ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 2
4583+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, // 3
4584+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4585+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4586+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4587+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4588+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4589+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4590+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4591+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4592+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4593+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4594+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4595+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4596+ };
4597+
4598+ // Attribute data with single quote (anything but ' \0)
4599+ template<int Dummy>
4600+ const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1[256] =
4601+ {
4602+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4603+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
4604+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4605+ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2
4606+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
4607+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4608+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4609+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4610+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4611+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4612+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4613+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4614+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4615+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4616+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4617+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4618+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4619+ };
4620+
4621+ // Attribute data with single quote that does not require processing (anything but ' \0 &)
4622+ template<int Dummy>
4623+ const unsigned char lookup_tables<Dummy>::lookup_attribute_data_1_pure[256] =
4624+ {
4625+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4626+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
4627+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4628+ 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 2
4629+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
4630+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4631+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4632+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4633+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4634+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4635+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4636+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4637+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4638+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4639+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4640+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4641+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4642+ };
4643+
4644+ // Attribute data with double quote (anything but " \0)
4645+ template<int Dummy>
4646+ const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2[256] =
4647+ {
4648+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4649+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
4650+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4651+ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
4652+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
4653+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4654+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4655+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4656+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4657+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4658+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4659+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4660+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4661+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4662+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4663+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4664+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4665+ };
4666+
4667+ // Attribute data with double quote that does not require processing (anything but " \0 &)
4668+ template<int Dummy>
4669+ const unsigned char lookup_tables<Dummy>::lookup_attribute_data_2_pure[256] =
4670+ {
4671+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4672+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0
4673+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1
4674+ 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
4675+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3
4676+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4
4677+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5
4678+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
4679+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
4680+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8
4681+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9
4682+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A
4683+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B
4684+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // C
4685+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // D
4686+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // E
4687+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F
4688+ };
4689+
4690+ // Digits (dec and hex, 255 denotes end of numeric character reference)
4691+ template<int Dummy>
4692+ const unsigned char lookup_tables<Dummy>::lookup_digits[256] =
4693+ {
4694+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
4695+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 0
4696+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 1
4697+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 2
4698+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,255,255,255,255,255,255, // 3
4699+ 255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255, // 4
4700+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 5
4701+ 255, 10, 11, 12, 13, 14, 15,255,255,255,255,255,255,255,255,255, // 6
4702+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 7
4703+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 8
4704+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 9
4705+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // A
4706+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // B
4707+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // C
4708+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // D
4709+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // E
4710+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 // F
4711+ };
4712+
4713+ // Upper case conversion
4714+ template<int Dummy>
4715+ const unsigned char lookup_tables<Dummy>::lookup_upcase[256] =
4716+ {
4717+ // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A B C D E F
4718+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 0
4719+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, // 1
4720+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, // 2
4721+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, // 3
4722+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, // 4
4723+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, // 5
4724+ 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, // 6
4725+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123,124,125,126,127, // 7
4726+ 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, // 8
4727+ 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, // 9
4728+ 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, // A
4729+ 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, // B
4730+ 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, // C
4731+ 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, // D
4732+ 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, // E
4733+ 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 // F
4734+ };
4735+ }
4736+ //! \endcond
4737+
4738+}
4739+
4740+// Undefine internal macros
4741+#undef RAPIDXML_PARSE_ERROR
4742+
4743+// On MSVC, restore warnings state
4744+#ifdef _MSC_VER
4745+ #pragma warning(pop)
4746+#endif
4747+
4748+#endif
4749
4750=== added file 'CTLParser/rapidxml-1.13/rapidxml_iterators.hpp'
4751--- CTLParser/rapidxml-1.13/rapidxml_iterators.hpp 1970-01-01 00:00:00 +0000
4752+++ CTLParser/rapidxml-1.13/rapidxml_iterators.hpp 2016-03-31 07:42:46 +0000
4753@@ -0,0 +1,174 @@
4754+#ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
4755+#define RAPIDXML_ITERATORS_HPP_INCLUDED
4756+
4757+// Copyright (C) 2006, 2009 Marcin Kalicinski
4758+// Version 1.13
4759+// Revision $DateTime: 2009/05/13 01:46:17 $
4760+//! \file rapidxml_iterators.hpp This file contains rapidxml iterators
4761+
4762+#include "rapidxml.hpp"
4763+
4764+namespace rapidxml
4765+{
4766+
4767+ //! Iterator of child nodes of xml_node
4768+ template<class Ch>
4769+ class node_iterator
4770+ {
4771+
4772+ public:
4773+
4774+ typedef typename xml_node<Ch> value_type;
4775+ typedef typename xml_node<Ch> &reference;
4776+ typedef typename xml_node<Ch> *pointer;
4777+ typedef std::ptrdiff_t difference_type;
4778+ typedef std::bidirectional_iterator_tag iterator_category;
4779+
4780+ node_iterator()
4781+ : m_node(0)
4782+ {
4783+ }
4784+
4785+ node_iterator(xml_node<Ch> *node)
4786+ : m_node(node->first_node())
4787+ {
4788+ }
4789+
4790+ reference operator *() const
4791+ {
4792+ assert(m_node);
4793+ return *m_node;
4794+ }
4795+
4796+ pointer operator->() const
4797+ {
4798+ assert(m_node);
4799+ return m_node;
4800+ }
4801+
4802+ node_iterator& operator++()
4803+ {
4804+ assert(m_node);
4805+ m_node = m_node->next_sibling();
4806+ return *this;
4807+ }
4808+
4809+ node_iterator operator++(int)
4810+ {
4811+ node_iterator tmp = *this;
4812+ ++this;
4813+ return tmp;
4814+ }
4815+
4816+ node_iterator& operator--()
4817+ {
4818+ assert(m_node && m_node->previous_sibling());
4819+ m_node = m_node->previous_sibling();
4820+ return *this;
4821+ }
4822+
4823+ node_iterator operator--(int)
4824+ {
4825+ node_iterator tmp = *this;
4826+ ++this;
4827+ return tmp;
4828+ }
4829+
4830+ bool operator ==(const node_iterator<Ch> &rhs)
4831+ {
4832+ return m_node == rhs.m_node;
4833+ }
4834+
4835+ bool operator !=(const node_iterator<Ch> &rhs)
4836+ {
4837+ return m_node != rhs.m_node;
4838+ }
4839+
4840+ private:
4841+
4842+ xml_node<Ch> *m_node;
4843+
4844+ };
4845+
4846+ //! Iterator of child attributes of xml_node
4847+ template<class Ch>
4848+ class attribute_iterator
4849+ {
4850+
4851+ public:
4852+
4853+ typedef typename xml_attribute<Ch> value_type;
4854+ typedef typename xml_attribute<Ch> &reference;
4855+ typedef typename xml_attribute<Ch> *pointer;
4856+ typedef std::ptrdiff_t difference_type;
4857+ typedef std::bidirectional_iterator_tag iterator_category;
4858+
4859+ attribute_iterator()
4860+ : m_attribute(0)
4861+ {
4862+ }
4863+
4864+ attribute_iterator(xml_node<Ch> *node)
4865+ : m_attribute(node->first_attribute())
4866+ {
4867+ }
4868+
4869+ reference operator *() const
4870+ {
4871+ assert(m_attribute);
4872+ return *m_attribute;
4873+ }
4874+
4875+ pointer operator->() const
4876+ {
4877+ assert(m_attribute);
4878+ return m_attribute;
4879+ }
4880+
4881+ attribute_iterator& operator++()
4882+ {
4883+ assert(m_attribute);
4884+ m_attribute = m_attribute->next_attribute();
4885+ return *this;
4886+ }
4887+
4888+ attribute_iterator operator++(int)
4889+ {
4890+ attribute_iterator tmp = *this;
4891+ ++this;
4892+ return tmp;
4893+ }
4894+
4895+ attribute_iterator& operator--()
4896+ {
4897+ assert(m_attribute && m_attribute->previous_attribute());
4898+ m_attribute = m_attribute->previous_attribute();
4899+ return *this;
4900+ }
4901+
4902+ attribute_iterator operator--(int)
4903+ {
4904+ attribute_iterator tmp = *this;
4905+ ++this;
4906+ return tmp;
4907+ }
4908+
4909+ bool operator ==(const attribute_iterator<Ch> &rhs)
4910+ {
4911+ return m_attribute == rhs.m_attribute;
4912+ }
4913+
4914+ bool operator !=(const attribute_iterator<Ch> &rhs)
4915+ {
4916+ return m_attribute != rhs.m_attribute;
4917+ }
4918+
4919+ private:
4920+
4921+ xml_attribute<Ch> *m_attribute;
4922+
4923+ };
4924+
4925+}
4926+
4927+#endif
4928
4929=== added file 'CTLParser/rapidxml-1.13/rapidxml_print.hpp'
4930--- CTLParser/rapidxml-1.13/rapidxml_print.hpp 1970-01-01 00:00:00 +0000
4931+++ CTLParser/rapidxml-1.13/rapidxml_print.hpp 2016-03-31 07:42:46 +0000
4932@@ -0,0 +1,421 @@
4933+#ifndef RAPIDXML_PRINT_HPP_INCLUDED
4934+#define RAPIDXML_PRINT_HPP_INCLUDED
4935+
4936+// Copyright (C) 2006, 2009 Marcin Kalicinski
4937+// Version 1.13
4938+// Revision $DateTime: 2009/05/13 01:46:17 $
4939+//! \file rapidxml_print.hpp This file contains rapidxml printer implementation
4940+
4941+#include "rapidxml.hpp"
4942+
4943+// Only include streams if not disabled
4944+#ifndef RAPIDXML_NO_STREAMS
4945+ #include <ostream>
4946+ #include <iterator>
4947+#endif
4948+
4949+namespace rapidxml
4950+{
4951+
4952+ ///////////////////////////////////////////////////////////////////////
4953+ // Printing flags
4954+
4955+ const int print_no_indenting = 0x1; //!< Printer flag instructing the printer to suppress indenting of XML. See print() function.
4956+
4957+ ///////////////////////////////////////////////////////////////////////
4958+ // Internal
4959+
4960+ //! \cond internal
4961+ namespace internal
4962+ {
4963+
4964+ ///////////////////////////////////////////////////////////////////////////
4965+ // Internal character operations
4966+
4967+ // Copy characters from given range to given output iterator
4968+ template<class OutIt, class Ch>
4969+ inline OutIt copy_chars(const Ch *begin, const Ch *end, OutIt out)
4970+ {
4971+ while (begin != end)
4972+ *out++ = *begin++;
4973+ return out;
4974+ }
4975+
4976+ // Copy characters from given range to given output iterator and expand
4977+ // characters into references (&lt; &gt; &apos; &quot; &amp;)
4978+ template<class OutIt, class Ch>
4979+ inline OutIt copy_and_expand_chars(const Ch *begin, const Ch *end, Ch noexpand, OutIt out)
4980+ {
4981+ while (begin != end)
4982+ {
4983+ if (*begin == noexpand)
4984+ {
4985+ *out++ = *begin; // No expansion, copy character
4986+ }
4987+ else
4988+ {
4989+ switch (*begin)
4990+ {
4991+ case Ch('<'):
4992+ *out++ = Ch('&'); *out++ = Ch('l'); *out++ = Ch('t'); *out++ = Ch(';');
4993+ break;
4994+ case Ch('>'):
4995+ *out++ = Ch('&'); *out++ = Ch('g'); *out++ = Ch('t'); *out++ = Ch(';');
4996+ break;
4997+ case Ch('\''):
4998+ *out++ = Ch('&'); *out++ = Ch('a'); *out++ = Ch('p'); *out++ = Ch('o'); *out++ = Ch('s'); *out++ = Ch(';');
4999+ break;
5000+ case Ch('"'):
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches