PhoenixLecture  2.0.0
Set of tools to make lectures
platexobj_order.cpp
Go to the documentation of this file.
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 
11 
14 void platexobj_orderGetSmallerLevel(PVecPtrSection & vecPtrSection, long unsigned int level){
15  if(vecPtrSection.size() == 0lu){return;}
16  while(vecPtrSection.size() != 0lu && level <= getSectionLevel(*vecPtrSection.back())){
17  vecPtrSection.pop_back();
18  }
19 }
20 
22 
26 void addSeparatorInVecPtrSection(PLatexObj & out, PVecPtrSection & vecPtrSection, PLatexObj & separator){
27  if(vecPtrSection.size() != 0lu){
28  PLatexObj & parentSec = *vecPtrSection.back();
29  long unsigned int currentLevel(getSectionLevel(parentSec));
30  long unsigned int secLevel(getSectionLevel(separator));
31 // std::cout << "addSectionInVecPtrSection : currentLevel = " << currentLevel << ", secLevel = " << secLevel << std::endl;
32 
33  if(currentLevel < secLevel){
34  parentSec.getVecContent().push_back(separator);
35  vecPtrSection.push_back(&(parentSec.getVecContent().back()));
36  }else{
37  platexobj_orderGetSmallerLevel(vecPtrSection, secLevel);
38 
39  if(vecPtrSection.size() == 0lu){
40  out.getVecContent().push_back(separator);
41  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 }
54 
56 
60 void addSectionInVecPtrSection(PLatexObj & out, PVecPtrSection & vecPtrSection, PLatexObj & sec){
61  if(vecPtrSection.size() != 0lu){
62  PLatexObj & parentSec = *vecPtrSection.back();
63  long unsigned int currentLevel(getSectionLevel(parentSec));
64  long unsigned int secLevel(getSectionLevel(sec));
65 // std::cout << "addSectionInVecPtrSection : currentLevel = " << currentLevel << ", secLevel = " << secLevel << std::endl;
66 
67  if(currentLevel < secLevel){
68  PLatexMenu & parentSecMenu = sec.getParentSec();
69  parentSecMenu.setLink(parentSec.getLink());
70  parentSecMenu.setText(parentSec.getName());
71 
72  parentSec.getVecContent().push_back(sec);
73  vecPtrSection.push_back(&(parentSec.getVecContent().back()));
74  }else{
75  platexobj_orderGetSmallerLevel(vecPtrSection, secLevel);
76 
77  if(vecPtrSection.size() == 0lu){
78  PLatexMenu & parentSecMenu = sec.getParentSec();
79  parentSecMenu.setLink(out.getLink());
80  parentSecMenu.setText(out.getName());
81 
82  out.getVecContent().push_back(sec);
83  vecPtrSection.push_back(&(out.getVecContent().back()));
84  }else{
85  PLatexObj* lastSec = vecPtrSection.back();
86 
87  PLatexMenu & parentSecMenu = sec.getParentSec();
88  parentSecMenu.setLink(lastSec->getLink());
89  parentSecMenu.setText(lastSec->getName());
90 
91  lastSec->getVecContent().push_back(sec);
92  vecPtrSection.push_back(&(lastSec->getVecContent().back()));
93  }
94  }
95  }else{
96  PLatexMenu & parentSecMenu = sec.getParentSec();
97  parentSecMenu.setLink(out.getLink());
98  parentSecMenu.setText(out.getName());
99 
100  out.getVecContent().push_back(sec);
101  vecPtrSection.push_back(&(out.getVecContent().back()));
102  }
103 }
104 
106 
110  PLatexObj out;
111  out.setType(obj.getType());
112  out.setLink(obj.getLink());
113  out.setName(obj.getName());
114  out.setAuthor(obj.getAuthor());
115  out.setDate(obj.getDate());
116  out.setSubTitle(obj.getSubTitle());
117  out.setSourceFile(obj.getSourceFile());
118  out.setSourceLine(obj.getSourceLine());
119 
120  PVecLatexObj & vecObj = obj.getVecContent();
121 
122  PVecPtrSection vecPtrSection;
123 
124  for(PVecLatexObj::iterator it(vecObj.begin()); it != vecObj.end(); ++it){
125  if(isSeparator(*it)){
126  addSeparatorInVecPtrSection(out, vecPtrSection, *it);
127  }else if(isSection(*it)){
128  addSectionInVecPtrSection(out, vecPtrSection, *it);
129  }else{
130  if(vecPtrSection.size() == 0lu){
131  out.getVecContent().push_back(*it);
132  }else{
133  vecPtrSection.back()->getVecContent().push_back(*it);
134  }
135  }
136  }
137  return out;
138 }
139 
140 
Describe a menu entry.
Definition: PLatexObj.h:17
void setText(const PString &text)
Sets the text of the PLatexMenu.
Definition: PLatexObj.cpp:48
void setLink(const PString &link)
Sets the link of the PLatexMenu.
Definition: PLatexObj.cpp:41
Describe a latex object.
Definition: PLatexObj.h:40
void setLink(const PString &link)
Sets the link of the PLatexObj.
Definition: PLatexObj.cpp:165
void setSourceFile(const PString &sourceFile)
Sets the sourceFile of the PLatexObj.
Definition: PLatexObj.cpp:249
const std::vector< PLatexObj > & getVecContent() const
Gets the vecContent of the PLatexObj.
Definition: PLatexObj.cpp:410
const PString & getSubTitle() const
Gets the subTitle of the PLatexObj.
Definition: PLatexObj.cpp:340
const PLatexType::PLatexType & getType() const
Gets the type of the PLatexObj.
Definition: PLatexObj.cpp:298
const PString & getName() const
Gets the name of the PLatexObj.
Definition: PLatexObj.cpp:326
void setName(const PString &name)
Sets the name of the PLatexObj.
Definition: PLatexObj.cpp:144
const PString & getLink() const
Gets the link of the PLatexObj.
Definition: PLatexObj.cpp:368
const PLatexMenu & getParentSec() const
Gets the parentSec of the PLatexObj.
Definition: PLatexObj.cpp:494
void setType(const PLatexType::PLatexType &type)
Sets the type of the PLatexObj.
Definition: PLatexObj.cpp:130
void setDate(const PString &date)
Sets the date of the PLatexObj.
Definition: PLatexObj.cpp:242
const PString & getAuthor() const
Gets the author of the PLatexObj.
Definition: PLatexObj.cpp:508
const PString & getSourceFile() const
Gets the sourceFile of the PLatexObj.
Definition: PLatexObj.cpp:536
size_t getSourceLine() const
Gets the sourceLine of the PLatexObj.
Definition: PLatexObj.cpp:550
void setAuthor(const PString &author)
Sets the author of the PLatexObj.
Definition: PLatexObj.cpp:235
void setSourceLine(size_t sourceLine)
Sets the sourceLine of the PLatexObj.
Definition: PLatexObj.cpp:256
const PString & getDate() const
Gets the date of the PLatexObj.
Definition: PLatexObj.cpp:522
void setSubTitle(const PString &subTitle)
Sets the subTitle of the PLatexObj.
Definition: PLatexObj.cpp:151
void platexobj_orderGetSmallerLevel(PVecPtrSection &vecPtrSection, long unsigned int level)
Erase all the higher level from vecPtrSection.
void addSectionInVecPtrSection(PLatexObj &out, PVecPtrSection &vecPtrSection, PLatexObj &sec)
Add a section into the vecPtrSection.
PLatexObj platexobj_order(PLatexObj &obj)
Order the PLatexObj in part,chapter,section,subsection,subsubsection.
void addSeparatorInVecPtrSection(PLatexObj &out, PVecPtrSection &vecPtrSection, PLatexObj &separator)
Add a section into the vecPtrSection.
bool isSection(const PLatexObj &obj)
Say if the PLatexObj is a part, charpter, section, subsection or subsubsection.
bool isSeparator(const PLatexObj &obj)
Say if the PLatexObj is a book separator.
long unsigned int getSectionLevel(const PLatexObj &obj)
Return the section level.
std::vector< PLatexObj > PVecLatexObj
Vector of obj.
std::vector< PLatexObj * > PVecPtrSection
Vector of section pointer.