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: 6615 lines (+5858/-150)
40 files modified
.bzrignore (+29/-0)
CTL/CertainZeroFPA.cpp (+144/-0)
CTL/CertainZeroFPA.h (+28/-0)
CTL/DependencyGraph.cpp (+20/-0)
CTL/DependencyGraph.h (+42/-0)
CTL/FixedPointAlgorithm.h (+16/-0)
CTL/LocalFPA.cpp (+106/-0)
CTL/LocalFPA.h (+28/-0)
CTL/OnTheFlyDG.cpp (+385/-0)
CTL/OnTheFlyDG.h (+50/-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 (+426/-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+290600@code.launchpad.net

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

This proposal has been superseded by a proposal from 2016-04-01.

Commit message

Added support for inhibitor arcs in CTL successor generator

Description of the change

Added support for inhibitor arcs in CTL successor generator

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

Subscribers

People subscribed via source and target branches