Directory: | ./ |
---|---|
File: | tmp_project/PhoenixTex2Html/src/PLatexObj/platexobj_order.cpp |
Date: | 2025-03-24 18:12:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 67 | 74 | 90.5% |
Branches: | 55 | 65 | 84.6% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | |||
8 | #include "platexobj_order.h" | ||
9 | |||
10 | ///Erase all the higher level from vecPtrSection | ||
11 | /** @param[out] vecPtrSection : PVecPtrSection to be updated | ||
12 | * @param level : required level | ||
13 | */ | ||
14 | 323 | void platexobj_orderGetSmallerLevel(PVecPtrSection & vecPtrSection, long unsigned int level){ | |
15 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 323 times.
|
323 | if(vecPtrSection.size() == 0lu){return;} |
16 |
6/6✓ Branch 1 taken 682 times.
✓ Branch 2 taken 63 times.
✓ Branch 5 taken 422 times.
✓ Branch 6 taken 260 times.
✓ Branch 7 taken 422 times.
✓ Branch 8 taken 323 times.
|
745 | while(vecPtrSection.size() != 0lu && level <= getSectionLevel(*vecPtrSection.back())){ |
17 | 422 | vecPtrSection.pop_back(); | |
18 | } | ||
19 | } | ||
20 | |||
21 | ///Add a section into the vecPtrSection | ||
22 | /** @param[out] out : output sorted PLatexObj | ||
23 | * @param[out] vecPtrSection : vector of section pointer to be updated | ||
24 | * @param separator : input section | ||
25 | */ | ||
26 | 2 | void addSeparatorInVecPtrSection(PLatexObj & out, PVecPtrSection & vecPtrSection, PLatexObj & separator){ | |
27 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if(vecPtrSection.size() != 0lu){ |
28 | 2 | PLatexObj & parentSec = *vecPtrSection.back(); | |
29 | 2 | long unsigned int currentLevel(getSectionLevel(parentSec)); | |
30 | 2 | long unsigned int secLevel(getSectionLevel(separator)); | |
31 | // std::cout << "addSectionInVecPtrSection : currentLevel = " << currentLevel << ", secLevel = " << secLevel << std::endl; | ||
32 | |||
33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if(currentLevel < secLevel){ |
34 | ✗ | parentSec.getVecContent().push_back(separator); | |
35 | ✗ | vecPtrSection.push_back(&(parentSec.getVecContent().back())); | |
36 | }else{ | ||
37 | 2 | platexobj_orderGetSmallerLevel(vecPtrSection, secLevel); | |
38 | |||
39 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if(vecPtrSection.size() == 0lu){ |
40 | 2 | out.getVecContent().push_back(separator); | |
41 |
1/1✓ Branch 3 taken 2 times.
|
2 | vecPtrSection.push_back(&(out.getVecContent().back())); |
42 | }else{ | ||
43 | ✗ | PLatexObj* lastSec = vecPtrSection.back(); | |
44 | |||
45 | ✗ | lastSec->getVecContent().push_back(separator); | |
46 | ✗ | vecPtrSection.push_back(&(lastSec->getVecContent().back())); | |
47 | } | ||
48 | } | ||
49 | }else{ | ||
50 | ✗ | out.getVecContent().push_back(separator); | |
51 | ✗ | vecPtrSection.push_back(&(out.getVecContent().back())); | |
52 | } | ||
53 | 2 | } | |
54 | |||
55 | ///Add a section into the vecPtrSection | ||
56 | /** @param[out] out : output sorted PLatexObj | ||
57 | * @param[out] vecPtrSection : vector of section pointer to be updated | ||
58 | * @param sec : input section | ||
59 | */ | ||
60 | 462 | void addSectionInVecPtrSection(PLatexObj & out, PVecPtrSection & vecPtrSection, PLatexObj & sec){ | |
61 |
2/2✓ Branch 1 taken 431 times.
✓ Branch 2 taken 31 times.
|
462 | if(vecPtrSection.size() != 0lu){ |
62 | 431 | PLatexObj & parentSec = *vecPtrSection.back(); | |
63 | 431 | long unsigned int currentLevel(getSectionLevel(parentSec)); | |
64 | 431 | long unsigned int secLevel(getSectionLevel(sec)); | |
65 | // std::cout << "addSectionInVecPtrSection : currentLevel = " << currentLevel << ", secLevel = " << secLevel << std::endl; | ||
66 | |||
67 |
2/2✓ Branch 0 taken 110 times.
✓ Branch 1 taken 321 times.
|
431 | if(currentLevel < secLevel){ |
68 | 110 | PLatexMenu & parentSecMenu = sec.getParentSec(); | |
69 | 110 | parentSecMenu.setLink(parentSec.getLink()); | |
70 | 110 | parentSecMenu.setText(parentSec.getName()); | |
71 | |||
72 | 110 | parentSec.getVecContent().push_back(sec); | |
73 |
1/1✓ Branch 3 taken 110 times.
|
110 | vecPtrSection.push_back(&(parentSec.getVecContent().back())); |
74 | }else{ | ||
75 | 321 | platexobj_orderGetSmallerLevel(vecPtrSection, secLevel); | |
76 | |||
77 |
2/2✓ Branch 1 taken 61 times.
✓ Branch 2 taken 260 times.
|
321 | if(vecPtrSection.size() == 0lu){ |
78 | 61 | PLatexMenu & parentSecMenu = sec.getParentSec(); | |
79 | 61 | parentSecMenu.setLink(out.getLink()); | |
80 | 61 | parentSecMenu.setText(out.getName()); | |
81 | |||
82 | 61 | out.getVecContent().push_back(sec); | |
83 |
1/1✓ Branch 3 taken 61 times.
|
61 | vecPtrSection.push_back(&(out.getVecContent().back())); |
84 | }else{ | ||
85 | 260 | PLatexObj* lastSec = vecPtrSection.back(); | |
86 | |||
87 | 260 | PLatexMenu & parentSecMenu = sec.getParentSec(); | |
88 | 260 | parentSecMenu.setLink(lastSec->getLink()); | |
89 | 260 | parentSecMenu.setText(lastSec->getName()); | |
90 | |||
91 | 260 | lastSec->getVecContent().push_back(sec); | |
92 |
1/1✓ Branch 3 taken 260 times.
|
260 | vecPtrSection.push_back(&(lastSec->getVecContent().back())); |
93 | } | ||
94 | } | ||
95 | }else{ | ||
96 | 31 | PLatexMenu & parentSecMenu = sec.getParentSec(); | |
97 | 31 | parentSecMenu.setLink(out.getLink()); | |
98 | 31 | parentSecMenu.setText(out.getName()); | |
99 | |||
100 | 31 | out.getVecContent().push_back(sec); | |
101 |
1/1✓ Branch 3 taken 31 times.
|
31 | vecPtrSection.push_back(&(out.getVecContent().back())); |
102 | } | ||
103 | 462 | } | |
104 | |||
105 | ///Order the PLatexObj in part,chapter,section,subsection,subsubsection | ||
106 | /** @param[out] obj : PLatexObj to be reordered | ||
107 | * @return PLatexObj sorted | ||
108 | */ | ||
109 | 127 | PLatexObj platexobj_order(PLatexObj & obj){ | |
110 |
1/1✓ Branch 1 taken 127 times.
|
127 | PLatexObj out; |
111 |
2/2✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
|
127 | out.setType(obj.getType()); |
112 |
2/2✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
|
127 | out.setLink(obj.getLink()); |
113 |
2/2✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
|
127 | out.setName(obj.getName()); |
114 |
2/2✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
|
127 | out.setAuthor(obj.getAuthor()); |
115 |
2/2✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
|
127 | out.setDate(obj.getDate()); |
116 |
2/2✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
|
127 | out.setSubTitle(obj.getSubTitle()); |
117 |
2/2✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
|
127 | out.setSourceFile(obj.getSourceFile()); |
118 |
2/2✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
|
127 | out.setSourceLine(obj.getSourceLine()); |
119 | |||
120 |
1/1✓ Branch 1 taken 127 times.
|
127 | PVecLatexObj & vecObj = obj.getVecContent(); |
121 | |||
122 | 127 | PVecPtrSection vecPtrSection; | |
123 | |||
124 |
2/2✓ Branch 4 taken 12502 times.
✓ Branch 5 taken 127 times.
|
12629 | for(PVecLatexObj::iterator it(vecObj.begin()); it != vecObj.end(); ++it){ |
125 |
3/3✓ Branch 2 taken 12502 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 12500 times.
|
12502 | if(isSeparator(*it)){ |
126 |
1/1✓ Branch 2 taken 2 times.
|
2 | addSeparatorInVecPtrSection(out, vecPtrSection, *it); |
127 |
3/3✓ Branch 2 taken 12500 times.
✓ Branch 4 taken 462 times.
✓ Branch 5 taken 12038 times.
|
12500 | }else if(isSection(*it)){ |
128 |
1/1✓ Branch 2 taken 462 times.
|
462 | addSectionInVecPtrSection(out, vecPtrSection, *it); |
129 | }else{ | ||
130 |
2/2✓ Branch 1 taken 7119 times.
✓ Branch 2 taken 4919 times.
|
12038 | if(vecPtrSection.size() == 0lu){ |
131 |
2/2✓ Branch 1 taken 7119 times.
✓ Branch 5 taken 7119 times.
|
7119 | out.getVecContent().push_back(*it); |
132 | }else{ | ||
133 |
2/2✓ Branch 2 taken 4919 times.
✓ Branch 6 taken 4919 times.
|
4919 | vecPtrSection.back()->getVecContent().push_back(*it); |
134 | } | ||
135 | } | ||
136 | } | ||
137 | 254 | return out; | |
138 | 127 | } | |
139 | |||
140 | |||
141 |