PhoenixLecture  2.0.0
Set of tools to make lectures
updateLabelRef.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 #include "platexobj_html.h"
8 
9 #include "updateLabelRef.h"
10 #include "redirect_html.h"
11 
13 
16 void updateMapLabel(PMapLabel & mapLabel, const PLatexObj & obj){
17  if(obj.getLabelName() != ""){
18  //TODO : update the text of the reference
19  PString name(obj.getName());
20  if(obj.getVecSecNumber().size() != 0lu){
21  name = vecNumberToString(obj.getVecSecNumber());
22  }
23  mapLabel[obj.getLabelName()] = std::pair<PString,PString>(obj.getLink(), name);
24  }
25  const PVecLatexObj & vecObj = obj.getVecContent();
26  for(PVecLatexObj::const_iterator it(vecObj.begin()); it != vecObj.end(); ++it){
27  updateMapLabel(mapLabel, *it);
28  }
29 }
30 
32 
35 void useMapLabel(PLatexObj & obj, const PMapLabel & mapLabel){
36  if(obj.getType() == PLatexType::REF){
37  PMapLabel::const_iterator it(mapLabel.find(obj.getName()));
38  if(it != mapLabel.end()){
39  const PString & link = it->second.first;
40  obj.setLink(link);
41  obj.setName(it->second.second);
42  }else{
43  std::cerr << "useMapLabel : reference to '"<<obj.getName()<<"' not found" << std::endl;
44  }
45  }else{
46  useMapLabel(obj.getVecContent(), mapLabel);
48  useMapLabel(obj.getComplexTitle(), mapLabel);
49  }
50  }
51 }
52 
54 
57 void useMapLabel(std::vector<PLatexObj> & vecObj, const PMapLabel & mapLabel){
58  for(std::vector<PLatexObj>::iterator it(vecObj.begin()); it != vecObj.end(); ++it){
59  useMapLabel(*it, mapLabel);
60  }
61 }
62 
64 
67  PMapLabel mapLabel;
68  updateMapLabel(mapLabel, obj);
69  useMapLabel(obj, mapLabel);
70 
71  PPath redirectFileName("redirect.html");
72  if(!redirect_html(redirectFileName, mapLabel)){
73  std::cerr << "updateLabelRef : cannot save the file '"<<redirectFileName<<"'" << std::endl;
74  }
75 }
76 
77 
Describe a latex object.
Definition: PLatexObj.h:40
void setLink(const PString &link)
Sets the link of the PLatexObj.
Definition: PLatexObj.cpp:165
const std::vector< PLatexObj > & getVecContent() const
Gets the vecContent of the PLatexObj.
Definition: PLatexObj.cpp:410
const std::vector< PLatexObj > & getComplexTitle() const
Gets the complexTitle of the PLatexObj.
Definition: PLatexObj.cpp:396
const PString & getLabelName() const
Gets the labelName of the PLatexObj.
Definition: PLatexObj.cpp:354
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 std::vector< long unsigned int > & getVecSecNumber() const
Gets the vecSecNumber of the PLatexObj.
Definition: PLatexObj.cpp:438
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16
@ TIMETABLE_WEEK
Definition: PLatexType.h:99
PString vecNumberToString(const std::vector< long unsigned int > &vecNb)
Convert a vector of numbers into a string.
std::vector< PLatexObj > PVecLatexObj
Vector of obj.
bool redirect_html(const PPath &fileName, const PMapLabel &mapLabel)
Create the redirection page to get page with label name as reference.
void updateMapLabel(PMapLabel &mapLabel, const PLatexObj &obj)
Update the map of label.
void updateLabelRef(PLatexObj &obj)
Update the label of the references.
void useMapLabel(PLatexObj &obj, const PMapLabel &mapLabel)
Update the map of label.
std::map< PString, std::pair< PString, PString > > PMapLabel
Map of the label (name, link)